-
-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to cross-compile with buildRustPackage from macOS fails. #249679
Comments
@NixOS/Rust |
This doesn't work because |
I would honestly prefer being able to just use Cargo2nix works on a project without dependencies, but when trying to build the project I was originally trying to build, it fails on building crane fails with here are my current notes on this. They're a bit sparse, I know 😅 |
Update - I tried Full default.nix{pkgs ? import <nixpkgs> {}}: let
fenix = builtins.getFlake "github:nix-community/fenix/monthly";
naersk = builtins.getFlake "github:nix-community/naersk";
target = "x86_64-unknown-linux-musl";
toolchain = with fenix.packages.${builtins.currentSystem};
combine [
minimal.cargo
minimal.rustc
targets.${target}.latest.rust-std
];
in
(naersk.lib.${builtins.currentSystem}.override {
cargo = toolchain;
rustc = toolchain;
})
.buildPackage {
src = ./.;
buildInputs = [
pkgs.pkgsCross.musl64.sqlite
];
CARGO_BUILD_TARGET = target;
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = let
inherit (pkgs.pkgsCross.musl64.stdenv) cc;
in "${cc}/bin/${cc.targetPrefix}cc";
} Of course I'd love to get |
I've since simplified my problems with
These are the same errors that I get while trying to build my rust package |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/cross-compile-rust-from-m1/27879/27 |
I think I will close this issue in favor of two issues describing the specific build failures I am experiencing with |
@peacememories Can you link up those issues? I'm also still interested in tracking this (though I've given up myself). |
Describe the bug
When trying to build a rust package on macOS with Apple Silicon for other platforms, the rust compiler fails to build.
Steps To Reproduce
Steps to reproduce the behavior:
Create a blank rust project with
cargo init
Add the following
default.nix
fileTry to run
nix-build
Observe the error log
Expected behavior
A cross compiled binary should be created
Additional context
Since this section mentions that the rust compiler does not actually have to be built for cross compiling, I tried a different approach:
Using this method the build is successful, but it results in a macOS binary rather than a cross compiled binary. This is because cargo is still run with
--target aarch64-apple-darwin
Notify maintainers
@figsoda (extracted from the blame of
buildRustPackage
, I don't know how to find the maintainer of a function)Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.The text was updated successfully, but these errors were encountered: