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

buildRustPackage: fix cross-compilation to aarch64-unknown-linux-musl #66617

Merged
merged 1 commit into from Sep 19, 2019
Merged

buildRustPackage: fix cross-compilation to aarch64-unknown-linux-musl #66617

merged 1 commit into from Sep 19, 2019

Conversation

lukateras
Copy link
Member

@lukateras lukateras commented Aug 14, 2019

Motivation for this change

See: rust-lang/rust#46651

musl libc for aarch64 doesn't have __addtf3, __subtf3, __multf3 symbols that Rust expects. This change allows to use statically linked in GCC for these symbols, allowing to build statically linked Rust binaries using Nixpkgs (Rust assumes that musl targets always want static linking).

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 nix-review --run "nix-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)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @Ericson2314 @matthewbauer @Mic92

@@ -86,6 +86,10 @@ in stdenv.mkDerivation (args // {
${stdenv.lib.optionalString (stdenv.buildPlatform.config != stdenv.hostPlatform.config) ''
[target."${stdenv.hostPlatform.config}"]
"linker" = "${ccForHost}"
${stdenv.lib.optionalString (stdenv.hostPlatform.config == "aarch64-unknown-linux-musl") ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it have those symbols on any musl platform?
Otherwise we could set stdenv.hostPlatform.isMusl.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does have these symbols on x86_64 musl platform.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? I cannot find it:

$ nm -gC $(nix-build --no-out-link '<nixpkgs>' -A musl)/lib/libc.so | grep __addtf3

I ask since I also cannot find a definition in the musl source repository.

Copy link
Member Author

@lukateras lukateras Aug 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that's the case, but at the very least I'm absolutely sure that cross-compiled x86_64-unknown-linux-musl executables work without this change. It seems that these symbols are used by LLVM for floating point arithmetic on AArch64 only.

@matthewbauer matthewbauer added the 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on label Aug 28, 2019
@lukateras
Copy link
Member Author

lukateras commented Sep 6, 2019

Would like to merge as-is on September 12 unless anyone minds otherwise (cc @matthewbauer @Mic92), verified this introduces no regressions while allowing cross to aarch64-unknown-linux-musl. I also verified this is not required for x86_64-unknown-linux-musl.

Copy link
Member

@Mic92 Mic92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it turns out these flags are useful for other targets, we can extend this.

@lheckemann lheckemann added this to the 20.03 milestone Sep 12, 2019
@lukateras lukateras merged commit 17a6ae0 into NixOS:master Sep 19, 2019
@Ericson2314
Copy link
Member

Sorry I didn't see the fixes and merge earlier!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: cross-compilation Building packages on a different sort platform than than they will be run on 6.topic: rust 10.rebuild-darwin: 0 10.rebuild-linux: 0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants