-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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
glibc: fix darwin -> linux cross compilation #103517
Conversation
A recent-ish glibc update removed some sunrpc code, causing a patch against it to fail to apply. Since it's removed, fixing it is now unnecessary, so we just remove that part of the patch.
When cross-compiling glibc from darwin to Linux, if NIX_COREFOUNDATION_RPATH is set, the resulting ld.so ends up with an RPATH of [], instead of no RPATH at all; this causes ld.so to fail with an assertion. I'm not sure if this is the best place to fix this, but it gets cross-compilation working for now.
@@ -206,6 +206,8 @@ stdenv.mkDerivation ({ | |||
|
|||
|
|||
'' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' | |||
unset NIX_COREFOUNDATION_RPATH |
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 is going to cause problems in multiple places, we should not set this at all if the target platform is linux. This might also be wrong for darwin->darwin cross.
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.
Yeah, that's fair. It looks like it's getting set here:
nixpkgs/pkgs/stdenv/darwin/default.nix
Lines 464 to 467 in dbedb52
preHook = commonPreHook + '' | |
export NIX_COREFOUNDATION_RPATH=${pkgs.darwin.CF}/Library/Frameworks | |
export PATH_LOCALE=${pkgs.darwin.locale}/share/locale | |
''; |
But that gets deep enough into the weeds of stdenv and cross infrastructure that I'm not sure how best to fix it. If possible, it would probably be better to do the target check in nix (as opposed to in bash) so we don't cause rebuilds for non-cross packages.
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.
The way that's currently added isn't great and was also done before most of the cross work. Most things, including the counterpart that overrides this when frameworks are included, use addEnvHooks
which I think would improve the situation.
Ideally this would also just be another setup-hook, just for the pure CF. The reason I added it here was to ensure that the hooks from frameworks run last. There's probably a better way to do that.
For testing it might be possible to use an if (stdenv.hostPlatform != stdenv.buildPlatform) then addEnvHook else export
in the preHook but that might be too late. Either way the proper thing should probably go to staging.
I was able to cross-compile from darwin to gnu64 using this PR.
|
I marked this as stale due to inactivity. → More info |
Still important. |
and still stale. Maybe just open a new PR if you want it to be shipped. |
I marked this as stale due to inactivity. → More info |
Closing because author did not react in almost 2 years. |
This seems important to better support Darwin. How can someone help? |
Motivation for this change
darwin -> linux cross-compilation of glibc was broken for two reasons. This fixes both of them:
NIX_COREFOUNDATION_RPATH
is set, we create a ld.so binary with an RPATH of [], but ld.so expects not to have an RPATH set at all. I fix this by unsetting the variable in theglibc
derivation, as suggested by @parthy, but I'm not sure this is the best solution (in particular, I'm not convinced we should be setting NIX_COREFOUNDATION_RPATH at all when host != darwin). However, this does get cross-compilation working for now.Tested by doing
nix-build . --arg crossSystem '(import ./. {}).lib.systems.examples.gnu64' -A hello
on Darwin, copying the resulting closure onto a Linux box, and runninghello
.This should only change code on the cross-compilation path, so it shouldn't cause any mass rebuilds.
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)