-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
Enable cross-compilation between both Darwin platforms #256590
Conversation
af2c4e7
to
dec9a32
Compare
dec9a32
to
94b24ce
Compare
The LLVM 11 build failed in compiler-rt on aarch64-darwin. I could have reverted back to #123524, but it would be really nice to have parity between both architectures. Fortunately, I was able to fix it by backporting some of the changes from the compiler-rt 16 derivation. It’s building again, and hopefully it should finish by this evening. |
…es (#56959) We want to get newer stuff in the devshell, but keep a stabler pin for the static binaries (until darwin stdenv stabilizes, most notably the big brain work over at NixOS/nixpkgs#256590) ## Test plan N/A nix stuff :clueless:
The clang 11 builds completed successfully after I added the fix for compiler-rt. Setting this to ready to review. |
94b24ce
to
1a2d7cd
Compare
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.
Mostly have minor remarks and questions due to unfamiliarity.
Awesome work once again! ❤️
1a2d7cd
to
a8d8c76
Compare
@toonn I believe I’ve addressed all the feedback. I tested static and dynamic cross builds to both x86_64-darwin and aarch64-darwin. I also confirmed Wine builds with the clang 16 stdenv (it does not build with the clang 11 one currently). |
darwin-cross is at commit a8d8c7640fa324fca6c24ebd0ea7660957a2e556
pkgsCross.aarch64-darwin.llvm.log
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
I finally got a chance to dig into the LLVM issue. I’ve been testing on my clang 16 branch, so I had to rebuild this branch for clang 11 to test and confirm, and that took a little bit. This is the issue. nixpkgs/pkgs/development/compilers/llvm/11/llvm/default.nix Lines 267 to 271 in a68655c
LLVM needs a native compiler when doing a cross build. That is set up correctly, but the native compiler also needs certain dependencies propagated to it (such as the path to However, I do have a patch, but I want to make sure it applies and works across all of the LLVM versions. I’ll submit the PR (probably tomorrow morning EDT) for it once those finish building (for both aarch64-darwin and x86_64-darwin cross). |
I opened #260543 for the LLVM cross-compilation fix. |
* Always use `stdenvNoCC` to build Libsystem. This is needed to prevent an infinite recursion when cross-building Libsystem; * Drop ncurses from Libsystem. While upstream does ship ncurses headers, everything in nixpkgs should be using ncurses from nixpkgs and not using upstream’s headers. This fixes an infinite recursion because ncurses still needs to be build to produce an ncurses^dev output; * Allow the stubs to be conditionally included in Libsystem. This is needed to build a bootstrap stdenv for building libresolv and Csu; * Symlink libresolv instead of copying it into Libsystem’s output. It’s not clear why this is necessary anymore, and using a stdenv with `install_name_tool` causes an infinite recursion when cross-building.
* Break an infinite recursion by determining the target prefix from the platform config. Referencing `stdenv.cc.bintools.targetPrefix` causes an infinite recursion because xnu is a dependency of Libsystem; * Add the host compiler as a dependency for the headers-only build, which needs to build tools it will use at build time; and * Add `migcc`, which provides a target compiler for use with `mig`, which needs to invoke clang for the target system during the build.
Break an infinite recursion with CF due to its depending on libc++ and compiler-rt.
With the infinite recursion broken when including darwin.CF in the stdenv, both regular cross and static builds can use the same `extraBuildInputs` override.
This ensures it is properly dropped when cross-compiling.
abseil-cpp will try to build for both architectures on Darwin. Not sure why this works with clang 16, but clang 18 fails when x86_64 flags are used when building for aarch64-darwin.
b2 tries to invoke the linker without a prefix, which fails.
The http-parser `Makefile` excepts the variable to be `PLATFORM`. Otherwise, it runs `uname -s` and detects the wrong target platform when cross-compiling to Linux from Darwin.
libpsl needs to link against gettext, which requires it be included as a build input even if gettext is already propagated as a native build input.
Actual static builds using `-static` are not supported, but Darwin can still do mostly static.
Taken from NixOS/nixpkgs#256590
Sorry about not updating, but this PR will be replaced by the Darwin refactor. I have a replacement for the SDKs that makes using them much easier in Darwin. I am developing it with cross-compilation in mind, so it should just work. This work is targeted for 24.11. |
Thanks for your hard work on that. I think we can close this then, for now. |
Is there a link to somewhere (pr, or message board thread, or anything) to follow along with this? Just curious to see what's going on |
Discussions have been happening on Matrix and in other PRs. I discuss it some in #242666 (comment). To help explain further and provide some background, I created a thread on Discourse: https://discourse.nixos.org/t/on-the-future-of-darwin-sdks-or-how-you-can-stop-worrying-and-put-the-sdk-in-build-inputs/50574 |
Description of changes
While cross-compilation from x86_64-darwin to aarch64-darwin already works, going the other way runs into issues with the source-based SDK. This PR resolves those issues and enables cross-compilation to x86_64-darwin. It should now be possible to build any of the following scenarios from a Darwin host:
I have tried to keep the changes required small and limited. While working on this PR, I found a few derivations that did not build correctly when cross-compiling. Fixing those was outside the scope of this PR unless they were required by the bootstrap or are part of the cross-stdenv.
Known breakage: brotli (references a dylib from the build environment), Wine (has a
buildInput
in one of its phase scripts), DarwinTools (needs modifications for cross-compilation). MoltenVK is probably also broken.Regarding Linux: I briefly looked at whether this would work on Linux. There’s work needing to be done to make certain required tools like bootstrap_cmds work on Linux. Expanding cross-compilation to Linux is outside the scope of this PR.
Note: My tests were done using my clang 16 branch. I have successfully evaluated the clang 11 branch used for this PR, but it will take overnight to build. I wanted to open this PR to get it out there for review, so I am opening it as a draft. If all goes well, I’ll flip this to ready tomorrow (Friday, 2023-09-22).
Resolved Issues
This PR should close the following issues:
Prerequisite PRs
Related PRs
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)