Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Rust build-support: enabling cross-compilation of Rust code #47976

wants to merge 3 commits into from

Conversation

P-E-Meunier
Copy link
Contributor

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
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@matthewbauer
Copy link
Member

Looks okay to me! I had this commit that might be helpful:

c66e3de

Feel free to cherry-pick it if it's helpful. I don't have enough familiarity with rust to do much.

@P-E-Meunier
Copy link
Contributor Author

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).

@P-E-Meunier
Copy link
Contributor Author

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;
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Contributor

@nagisa nagisa Oct 14, 2018

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.

@P-E-Meunier P-E-Meunier mentioned this pull request Oct 21, 2018
8 tasks
@P-E-Meunier
Copy link
Contributor Author

Merged into #40587.

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

Successfully merging this pull request may close these issues.

None yet

5 participants