Skip to content

Instantly share code, notes, and snippets.

@peacememories
Created August 17, 2023 15:37
Show Gist options
  • Save peacememories/b9f3efd586b4bfdb2ae22fd9aab4fa58 to your computer and use it in GitHub Desktop.
Save peacememories/b9f3efd586b4bfdb2ae22fd9aab4fa58 to your computer and use it in GitHub Desktop.

I could not get cross compiling to work on macOS. See this issue

Attempts

With cargo2nix

{pkgs ? import <nixpkgs> {}}: let
  cargo2nix = builtins.getFlake "github:cargo2nix/cargo2nix/release-0.11.0";
  pkgsCross = import pkgs.path {
    crossSystem = {
      config = "x86_64-unknown-linux-musl";
    };
    overlays = [
      cargo2nix.overlays.default
    ];
  };
  rustPkgs = pkgsCross.rustBuilder.makePackageSet {
    rustVersion = "latest";
    packageFun = import ./Cargo.nix;
  };
in
  rustPkgs.workspace.cargo-cross-test {}

This works well without dependencies, but crashes on missing iconv library in memchr when trying to build ld50-highscore

With buildRustPackage

{pkgs ? import <nixpkgs> {}}: let
  pkgsCross = pkgs.pkgsCross.musl64;
in
  pkgsCross.rustPlatform.buildRustPackage {
    pname = "test";
    name = "test";
    src = ./.;
    cargoLock = {lockFile = ./Cargo.lock;};
  }

This fails with a missing libc.a in libSystem With pkgs.pkgsCross.gnu64 it instead fails with unknown option: --version-script

Fails with ld: unknown option: --as-needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment