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

misc pkgs: Darwin -> Linux cross compilation #46534

Merged
merged 3 commits into from Oct 24, 2018

Conversation

Ericson2314
Copy link
Member

@Ericson2314 Ericson2314 commented Sep 11, 2018

Motivation for this change

Carefully changed to not be a mass rebuild, I'll clean up after (or @oxij can call me out :)). Glibc patches delayed temporarily, but musl works fine.

Fixes #27934

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.

CC @3noch @periklis

@GrahamcOfBorg GrahamcOfBorg added 6.topic: darwin Running or building packages on Darwin 6.topic: stdenv Standard environment labels Sep 11, 2018
@@ -9513,6 +9513,12 @@ with pkgs;
installLocales = config.glibc.locales or false;
};

# Provided by libc on Operating Systems that use the Extensible Linker Format.
elf-header =
Copy link
Member

Choose a reason for hiding this comment

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

Have you seen if libelf above would work? Not sure how that works currently but it might be a little bit more generic of the name. elf-header IMO is a little two awkward. No package will ever list a dependency on "elf-header" but may for libelf.

Copy link
Member Author

Choose a reason for hiding this comment

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

libelf is something else. I bet paxctl could be rewritten against it, but it's not a drop-in replacement. (libelf also looks more like the darwin DTrace header.)

Copy link
Member

Choose a reason for hiding this comment

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

Hmm... I guess it's okay then. It's just semantically kind of ugly to me.

(hostPlatform.isLinux && !buildPlatform.isLinux)
[ buildPackages.patchelf buildPackages.paxctl ]
++ lib.optional
(let f = p: !p.isx86 || p.libc == "musl"; in f hostPlatform && !(f buildPlatform))
Copy link
Member

Choose a reason for hiding this comment

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

This seems a little bit too much. I think I would prefer the more verbose: (!hostPlatform.isx86 || hostPlatform.libc == "musl" && !(!buildPlatform.isx86 || buildPlatform.libc == "musl"). Would it hurt to just do this everywhere? It's just a hook so maybe it's smart enough to avoid the conditional completely?

Copy link
Member Author

Choose a reason for hiding this comment

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

I do want to do this everywhere, but unfortunately I don't see a good way to deduplicate it between stdenv/linux and stdenv/cross since stdenv/generic doesn't get passed whole package sets.

Or...we could just use one of the builtin fetchers to get the new scripts so we don't even need most of nixpkgs 😈.

@matthewbauer
Copy link
Member

matthewbauer commented Sep 11, 2018

Great work!!! When I looked at this in June I got stuck on the case insensitive glibc. Nice that there is a patch for that. It would be good to report this to glibc. I suspect they already know about it but just maybe giving them the patch would make it a priority (most likely they will not apply it immediately though).

This is my old branch:

https://github.com/matthewbauer/nixpkgs/commits/cross

Everything is hopefully upstreamed.

@@ -96,7 +94,8 @@ callPackage ./common.nix { inherit stdenv; } {
mv $bin/bin/getconf_ $bin/bin/getconf
'';

separateDebugInfo = true;
# Hack to get around eval issue.
separateDebugInfo = !stdenv.isDarwin;
Copy link
Member

Choose a reason for hiding this comment

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

This might be useful to do in mk-derivation. I don't think separateDebugInfo has ever worked in macOS.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah if we remove the assert in mkDerivation and instead make it part of meta.broken or something, that would give us the required laziness.

makeFlags = [
"SHELL=bash"
# Avoid use of runtime build->host compilers for checks
"cc-version:=9999"
Copy link
Member

Choose a reason for hiding this comment

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

ugh... Another thing to report upstream, but it is probably fine for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well... it's arguably not a bug. I checked and this version is just used to work around bugs in old GCCs; I assume/hope newer GCCs are given better testing so hopefully it won't a happen again. But we could generate the actual version number thing just as a precaution.

Then again, upstream could provide the right hook in the configure script so faking this number wouldn't be downstream's burden.

@periklis
Copy link
Contributor

Really great kudos from my side. I could only skim it very fast. However, i will try it tommorow on couple of our docker base images which are using dockerTools and are built with lnl7/nix-docker. This will enhance our build chain a lot at Holidaycheck.

@matthewbauer
Copy link
Member

How much were you able to cross compile? I would think some things could still go wrong when cross compiling a NixOS image.

@Ericson2314
Copy link
Member Author

@matthewbauer Yeah I just did stdenv and random easy stuff like hello and ed. The infrastructure works, but I make no claim that arbitrary things will build on case-insensitive filesystems :D.

@Ericson2314
Copy link
Member Author

https://sourceware.org/bugzilla/show_bug.cgi?id=72 Uhoh, upstream so far hasn't been interested.

@matthewbauer
Copy link
Member

matthewbauer commented Sep 11, 2018

Someone sent an article recently that might be useful:

https://worthdoingbadly.com/casesensitive-iossim/

Basically you can do taskpolicy -X to enable case sensitivity in macOS. taskpolicy is part of system_cmds but not currently built by us. We can probably fix that easily though.

EDIT: Just now realized it requires root privileges & a PID. Might be something worth doing in Nix though (which should know the PID).

@Ericson2314 Ericson2314 added 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on 6.topic: portability General portability concerns, not specific to cross-compilation or a specific platform labels Sep 11, 2018
@copumpkin
Copy link
Member

Holy shit @matthewbauer I had no idea that was a thing. Can you file that as a ticket somewhere so we don't forget it with all the stuff going on? I'd love to get that integrated into Nix

@LnL7
Copy link
Member

LnL7 commented Sep 11, 2018

Oh right! I remember seeing that somewhere now.

@edolstra
Copy link
Member

This PR illustrates my concerns with cross-compilation support: it adds dozens of patches, special casing, extra build flags, pseudo-packages like elf-header etc., all to support a relatively obscure use case (namely macOS -> Linux cross-compilation). I mean, don't most macOS users just use VMs to build Linux stuff?

@periklis
Copy link
Contributor

@edolstra I understand the constrains and the extra maintenance burden for our derivation, however i have to admit that building docker images on macOS is one of my daily jobs in developer land. Our developers at holidaycheck have to run a remote builder e.g. lnl7/nix-docker to use dockerTools daily. Latter has limited resources on macOS with Docker4Mac. I would like to ditch DockerForMac if we could get binary cached cross compiled glibc and gcc packages. Thus dockerTools will be closer to nix and lesser dependent on docker4mac. Developers writing jvm/nodejs/haskell services at our place really have more concerns than maintaining docker4mac's glitches just to build images. I admit most of the time those images are built through a linux-baked pipeline, but people writing dockerTools-Expression need to test them upfront.

@Ericson2314
Copy link
Member Author

@edolstra

I mean, don't most macOS users just use VMs to build Linux stuff?

In case it isn't clear already, this is far and a way the most popular thing my work enables.

@Ericson2314
Copy link
Member Author

#46574 Contains some non-mass-rebuild portions of this

LnL7 and others added 2 commits October 23, 2018 23:20
Carefully fake cc-version and cc-fullversion to avoid needing a compiler
for the kernel itself to build the headers.

For some reason, doing `make install_headers` twice, first without
INSTALL_HDR_PATH=$out then with, is neccessary to get this to work.
@Ericson2314 Ericson2314 merged commit 7d96d15 into NixOS:master Oct 24, 2018
@Ericson2314 Ericson2314 deleted the darwin-to-linux-cross branch October 24, 2018 14:36
@dtzWill
Copy link
Member

dtzWill commented Oct 24, 2018 via email

@Ericson2314
Copy link
Member Author

Linux bootstrap? Weird and bummer. I'll open the clean up PR tomorrow so we have something to investigate.

@dtzWill
Copy link
Member

dtzWill commented Oct 25, 2018 via email

@periklis
Copy link
Contributor

@Ericson2314 Is the following error a glibc issue or related to the builder:

[Run cross-compilation jobset] builder for '/nix/store/8fcx14mfnlzm03704dwy03ldnsjgy490-glibc-2.27-x86_64-linux-gnu.drv' failed with exit code 1; last 10 log lines:
[Run cross-compilation jobset]   rm -f /private/var/folders/lg/gsg812dx2llcqvrxfchsngn80000gp/T/nix-build-glibc-2.27-x86_64-linux-gnu.drv-0/build/localedata/stamp.os; > /private/var/folders/lg/gsg812dx2llcqvrxfchsngn80000gp/T/nix-build-glibc-2.27-x86_64-linux-gnu.drv-0/build/localedata/stamp.os
[Run cross-compilation jobset]   make[2]: Leaving directory '/private/var/folders/lg/gsg812dx2llcqvrxfchsngn80000gp/T/nix-build-glibc-2.27-x86_64-linux-gnu.drv-0/glibc-2.27/localedata'
[Run cross-compilation jobset]   make  subdir=iconvdata -C iconvdata ..=../ subdir_lib
[Run cross-compilation jobset]   make[2]: Entering directory '/private/var/folders/lg/gsg812dx2llcqvrxfchsngn80000gp/T/nix-build-glibc-2.27-x86_64-linux-gnu.drv-0/glibc-2.27/iconvdata'
[Run cross-compilation jobset]   extra-module.mk:11: *** Too many open files.  Stop.
[Run cross-compilation jobset]   make[2]: Leaving directory '/private/var/folders/lg/gsg812dx2llcqvrxfchsngn80000gp/T/nix-build-glibc-2.27-x86_64-linux-gnu.drv-0/glibc-2.27/iconvdata'
[Run cross-compilation jobset]   make[1]: *** [Makefile:215: iconvdata/subdir_lib] Error 2
[Run cross-compilation jobset]   make[1]: Leaving directory '/private/var/folders/lg/gsg812dx2llcqvrxfchsngn80000gp/T/nix-build-glibc-2.27-x86_64-linux-gnu.drv-0/glibc-2.27'
[Run cross-compilation jobset]   make: *** [Makefile:9: all] Error 2
[Run cross-compilation jobset]   builder for '/nix/store/8fcx14mfnlzm03704dwy03ldnsjgy490-glibc-2.27-x86_64-linux-gnu.drv' failed with exit code 2

i was trying to build openjdk with cross-compilation after the PR merge.

@Ericson2314
Copy link
Member Author

Yeah that's a glibc faillure. Try a crossSystem of { config = "x86_64-unknown-linux-musl"; }.

@dtzWill
Copy link
Member

dtzWill commented Oct 25, 2018 via email

@Ericson2314
Copy link
Member Author

#49129 is the staging cleanup with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: work-in-progress 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on 6.topic: darwin Running or building packages on Darwin 6.topic: portability General portability concerns, not specific to cross-compilation or a specific platform 10.rebuild-darwin: 0 10.rebuild-linux: 0
Projects
No open projects
Cross compilation
Planned for 18.09
Development

Successfully merging this pull request may close these issues.

None yet

9 participants