Compiling project from x86_64-unknown-linux-gnu
to x86_64-apple-darwin
#882
-
Good morning. As per the title, I'm trying to compile a Rust project from my Linux machine to Since there are no specific instructions in the documentation, I tried to adapt the "cross-windows" example, coming up with something like this: { meta, crane, fenix, nixpkgs }: {
libcrossquil = let
pkgs = import nixpkgs {
localSystem = "x86_64-linux";
crossSystem = "x86_64-darwin";
};
fenixPkgs = fenix.packages."x86_64-linux";
toolchain = (with fenixPkgs;
(combine [
stable.cargo
stable.rustc
targets."x86_64-apple-darwin".stable.rust-std
]));
craneLib = (crane.mkLib pkgs).overrideToolchain (_: toolchain);
libcrossquilInfo = {
pname = "libcrossquil";
version = meta.version;
src = craneLib.cleanCargoSource (craneLib.path ../.);
doCheck = false;
strictDeps = true;
CARGO_BUILD_TARGET = "x86_64-apple-darwin";
};
in rec {
cargoArtifacts = craneLib.buildDepsOnly libcrossquilInfo;
target = craneLib.buildPackage (libcrossquilInfo // {
inherit cargoArtifacts;
});
};
} But as the build process immediately fails with this error, I think that I'm missing something:
I therefore wanted to ask: what is the correct approach to build on Linux a crate for MacOS? Sorry if this has been asked before, but I couldn't find anything relevant in the Issues and Discussions. Thank you very much in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @Occhioverde! Cross compilation can be fraught with peril as sometimes dependency packages don't always work 😅 I've never actually tried cross compiling from Linux for Darwin so I'm not entirely sure whether that's currently possible/supported in nixpkgs. Based on the error my suspicion is that there is no build of You can always try to allow the unsupported system flag as hinted above and see how far you get, but I suspect its there for a reason and might not work. If anyone else has managed to make Linux -> Darwin cross compilation work with nixpkgs you could try adapting what they've done! But otherwise I'm not too sure what else to suggest besides give up on cross compilation and use a real Darwin runner if you care about Darwin builds |
Beta Was this translation helpful? Give feedback.
Hi @Occhioverde! Cross compilation can be fraught with peril as sometimes dependency packages don't always work 😅
I've never actually tried cross compiling from Linux for Darwin so I'm not entirely sure whether that's currently possible/supported in nixpkgs. Based on the error my suspicion is that there is no build of
darwin-cctools
that can be built for Linux (but otherwise outputs instructions for Darwin) so we can't even start cross compiling dependencies before thecrane
derivations even have a chance to run.You can always try to allow the unsupported system flag as hinted above and see how far you get, but I suspect its there for a reason and might not work. If anyone else has manag…