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
Rust build-support: enabling cross-compilation of Rust code #47976
Conversation
Looks okay to me! I had this commit that might be helpful: Feel free to cherry-pick it if it's helpful. I don't have enough familiarity with rust to do much. |
Done, thanks for the input! I started working on this a while ago, which is why I didn't get a chance to see your commit (nothing worked for an embarrassingly long time). |
Wait, actually, your commit is about the cargo-based compilation system, which explains better why I hadn't seen it. This PR is about the other system (the Carnix-based one). The Carnix-based system uses Nix instead of Cargo to do the dependency management. This is really useful, since all the crates are independent derivations, and you don't need to recompile the world every time you change the final crate. As an example, I spent way less time working on Carnix in total than waiting for the server of https://nest.pijul.com to finish compiling. The only downside is that the Carnix-based system sometimes lags behind compared to Cargo, since the configuration files of Cargo might change, and no one is currently tracking these changes too closely. Also, this PR means that the Carnix-based system is now more advanced than the Cargo-based one (and I know it shouldn't make me happy). |
rustPlatform = | ||
with stdenv.hostPlatform.parsed; | ||
let cpu_ = if cpu.name == "armv7a" then "armv7" | ||
else cpu.name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have a fixed and known-to-work name mapping instead of such hardcoded special cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too!
If you know of any such naming, great. Rustc doesn't seem to respect GNU conventions, NixOS does. I don't want to sound scary, but most, if not all, of rustBuildCrate
was built by trial and error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asking in #rustc they pointed me to https://github.com/rust-lang/rust/tree/master/src/librustc_target/spec where this stuff is apparently declared, soo if somebody feels inclined to do a mapping for them there you go :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They also said they match llvm targets, and those are defined in each file as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can get list of supported targets and their names by running rustc --print target-list
.
Merged into #40587. |
Motivation for this change
The Rust build-support in Nixpkgs was lacking cross-compilation support, mostly because 'rustc' was not using the proper linker. Another issue is the difference in platform names (for instance ARMv7) between Gnu and Rust.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)