-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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 Cross Compilation (1.32.0) #56540
Conversation
not sure why, maybe @matthewbauer might know, but I get these errors on a lot of rust packages:
it seems like but the UPDATE: fixed with a weird hack bd45c09 dunno what 2 do about that |
I have not looked yet at the |
@Mic92 yes, (see list above) cross-compiled the right architecture lib seems to get compiled, but there's something wrong with them. :/ EDIT: Specificity
The same from the cross-compiled rustc:
The only thing I can guess is that the |
Can you upload? |
|
||
cargoBuildFlags = [ "--all" ]; | ||
|
||
PKG_CONFIG_ALLOW_CROSS = 1; |
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.
Is this something we should set by default in buildRustPackage
?
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.
possibly, it's for pkg-config
so ostensibly it would need to be set anywhere pkg-config
is used during cross-compilation. Don't know how to handle all those cases though.
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.
Actually it is a pkgconfig-rs thing i think
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.
Maybe some hook in buildRustPackage that checks if pkg-config is available and sets PKG_CONFIG_ALLOW_CROSS
in that case?
@Mic92 so this happens when you build |
Looks actually sane on the first glance: $ 7z x libstd-e27907af0047d202.zip
$ ar x libstd-e27907af0047d202.rlib
$ file *.o
alloc.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
backtrace.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
dwarf.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
elf.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
fileline.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
posix.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
read.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
sort.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
state.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
std-e27907af0047d202.std.3x3nkc5s-cgu.0.rcgu.o: ELF 64-bit LSB relocatable, no machine, version 1 (SYSV), not stripped
std-e27907af0047d202.std.3x3nkc5s-cgu.1.rcgu.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
std-e27907af0047d202.std.3x3nkc5s-cgu.2.rcgu.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
std-e27907af0047d202.std.3x3nkc5s-cgu.3.rcgu.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
std-e27907af0047d202.std.3x3nkc5s-cgu.4.rcgu.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
std-e27907af0047d202.std.3x3nkc5s-cgu.5.rcgu.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
std-e27907af0047d202.std.3x3nkc5s-cgu.6.rcgu.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
std-e27907af0047d202.std.3x3nkc5s-cgu.7.rcgu.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
std-e27907af0047d202.std.3x3nkc5s-cgu.8.rcgu.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped
std-e27907af0047d202.std.3x3nkc5s-cgu.9.rcgu.o: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), with debug_info, not stripped |
@Mic92 yea, could setting the Machine correctly really be all that's needed? |
@illegalprime could be. I have not figured out yet, how I can run gdb on the build compiler otherwise I would set a breakpoint in the right location. The hack is ok right now, also annoying because it forces cross-compilers to build a rustc they probably never need. Maybe this can be reported upstream though. I wonder how they build those stdlibs. |
pkgs/build-support/rust/default.nix
Outdated
|
||
rm -rf $out/lib/rustlib/${stdenv.hostPlatform.config} | ||
cp -a \ | ||
${pkgsCross."${host}".rustc}/lib/rustlib/${stdenv.hostPlatform.config}/. \ |
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.
This should be targetpackages - pkgsCross should not be referenced internally.
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.
if i try to use targetPackages.rustc
I get:
error: attribute 'rustc' missing,
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.
Shouldn't it be buildPackages
? Or maybe just pkgs
? I'm a bit confused on what the intention is.
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.
this rustc
is supposed to be the rustc
whose host & target is aarch64
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 think pkgs.rustc
is where just the target is aarch64 and build & host are x86
|
||
cargoBuildFlags = [ "--all" ]; | ||
|
||
PKG_CONFIG_ALLOW_CROSS = 1; |
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.
Actually it is a pkgconfig-rs thing i think
ccForBuild = "${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc"; | ||
cxxForBuild = "${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}c++"; | ||
ccForTarget = "${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc"; | ||
cxxForTarget = "${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}c++"; |
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.
This looks wrong. /cc @Ericson2314
turns out it was the stripping in the fixupPhase that was creating the bad rlibs, not rust's bootstrapping process, :( |
Good news. Anything left to do then? |
@Mic92 i have an interest in cross compiling for 32-bit arm (armv7), doing:
breaks because Rust doesn't recognize the triple
if you think no. 2 is preferable, how do I do that? the entire layout of EDIT: less of a mystery, after knowing it's in diff --git a/lib/systems/parse.nix b/lib/systems/parse.nix
index 6947d41419e..c029d6a1914 100644
--- a/lib/systems/parse.nix
+++ b/lib/systems/parse.nix
@@ -76,6 +76,7 @@ rec {
armv7r = { bits = 32; significantByte = littleEndian; family = "arm"; version = "7"; };
armv7m = { bits = 32; significantByte = littleEndian; family = "arm"; version = "7"; };
armv7l = { bits = 32; significantByte = littleEndian; family = "arm"; version = "7"; };
+ armv7 = { bits = 32; significantByte = littleEndian; family = "arm"; version = "7"; };
armv8a = { bits = 32; significantByte = littleEndian; family = "arm"; version = "8"; }; |
another thing since we're here, how do people feel about https://www.hadean.com/blog/managing-rust-dependencies-with-nix-part-ii (i'm not the author, or know the author)? It seems more nix-ish than the current setup, but it didn't seem very popular in #11144. my other main goal is to be able to support rust builds where some crates are in directories that are siblings to the project directory, without setting the entire parent folder as my |
I rebased @Mic92's old PR and changed some things in the past. I'll work to get that rebased so I can combine with this. |
https://github.com/NixOS/nixpkgs/pull/57611/files is something that would make this easier. |
https://github.com/Ericson2314/nixpkgs/branche/rust-cross here my old modification, rebased to have the same branch as this, but not yet tested). However, if #57611 is merged, we should rebase both onto that before combining. |
After some hacking, ignore my previous 2 comments, I'm all good on this PR I think it's ready to merge! 🎉 |
] ++ optional (!withBundledLLVM) [ | ||
"--enable-llvm-link-shared" | ||
"${setBuild}.llvm-config=${buildLlvmShared}/bin/llvm-config" | ||
"${setHost}.llvm-config=${buildLlvmShared}/bin/llvm-config" |
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.
this might be wrong, need to test
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.
so when building under ARMv7 rust tries to call llvm-config
to get the libs to link against. buildLlvmShared
has an llvm-config
that can run on the build system but the wrong shared libraries, while llvm-config
is the opposite (wrong binary, right libs). Not sure why this problem doesn't show up on AArch64.
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.
Maybe a shim llvm-config
script should be introduced, this is similar to meta-amd's: https://git.yoctoproject.org/cgit/cgit.cgi/meta-amd/tree/common/recipes-core/llvm/files/0001-llvm-config-allow-overriding-libdir-through-cmdline.patch?h=sumo
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.
Since there should be no arch-specific one could wrap around the llvm-config
and then just do sed -e "s!${buildPackages.llvm}!${llvm}!"
on the output?
@Mic92 NP, do you have documented somewhere the philosophy and plan for nixpkgs cross-comp? things like |
I assume you meant me? :). So https://nixos.org/nixpkgs/manual/#ssec-stdenv-dependencies is the main section describing the dependencies and how they fit together, but in that PR I extended the corresponding section the cross compilation section. Hopefully https://hydra.nixos.org/build/91228503# has it in a moment. edit master post PR built: |
OK now that that #57611 is merged:
The first thing to note is @Mic92 did take my changes (all-packages.nix changes were moved to an I guess orphaned The second things is @illegalprime your PR is harder to review because some commits "undo" other commits (revert or moral revert). Could you After that's done I'll be able to better wrap my head around everything, and also set about incorporating the new Thanks in advance! |
2d6d180
to
6d06924
Compare
thanks for the links to the docs @Mic92 , i rebased it, we'll see how the tests go |
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.
Thanks again @illegalprime and @Mic92! I pruned the remaining silly states from the history, and incorporated the new pkgsBuild*
, so this is ready to go!
https://github.com/Ericson2314/nixpkgs/commits/rust-cross-2 has the beginnings of a |
NixOS/ofborg looked good enough to me, haha. |
Motivation for this change
This is the same as #50866 but re-based and updated for Rust 1.32.0. It also does some other extra stuff like moving all output dirs to
target/{release, debug}
and being able to specify the build mode (release
ordebug
).the following derivations build:
pkgs.pkgsCross.aarch64-multiplatform.rustc
pkgs.pkgsCross.aarch64-multiplatform.cargo
pkgs.pkgsCross.aarch64-multiplatform.fd
pkgs.pkgsCross.aarch64-multiplatform.synapse-bt
pkgs.pkgsCross.aarch64-multiplatform.webmetro
pkgs.pkgsCross.aarch64-multiplatform.miniserve
pkgs.pkgsCross.aarch64-multiplatform.ripgrep
pkgs.pkgsCross.aarch64-multiplatform.ethabi
pkgs.pkgsCross.aarch64-multiplatform.zola
pkgs.pkgsCross.aarch64-multiplatform.todiff
pkgs.pkgsCross.aarch64-multiplatform.gitAndTools.git-ignore
pkgs.pkgsCross.aarch64-multiplatform.gitAndTools.git-codeowners
pkgs.pkgsCross.aarch64-multiplatform.gitAndTools.git-absorb
pkgs.rustc
I will attempt to updated this as soon as I figure out how to build more derivations. There are a lot more rust packages in nixpkgs, but these are likely a good starting point.
Any edits to or help with these derivations is appreciated.
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)