-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
Cross compiling to x86_64-darwin from aarch64-darwin seems broken #180771
Comments
Confirm that other packages have this problem as well.
It looks like LibsystemCross is missing and LibsystemCross only finded in apple-sdk-11.0. Is there any way to switch apple-sdk to apple-sdk-11.0? Edit 1: |
That would be a full stdenv rebuild and also break Nix on old macOS versions. I would support it regardless though. Testing whether this would work would be a hefty compilation session, I expect. I'll have a light try at it today and see if I can get it any further. I don't think I have time to follow through with a full patch set as we ended up solving the problem this caused at work by not using Nix for the relevant project. |
I have a bootstrapping 11.0 stdenv on x86_64-darwin that is waiting on #181550 before I can open a PR (since it needs an updated bootstrap-tools). It is currently targeted at selectively using the 11.0 SDK when the 10.12 SDK won’t work. As far as I am aware, the plan for nixpkgs in general is still to work towards bumping the source-based SDK rather than switch to the Apple SDK. |
@lf- Is possible to override the SDK version in cross compiling environment of aarch64-darwin host shell? Could this be a workaround to the problem? |
Unfortunately, I haven’t had the bandwidth to get back to #180931. I can take a look at splitting some of the packages fixes into separate PRs, but the bootstrap-tools/stdenv stuff definitely won’t happen for 22.11.
Do you need actually cross-built tools or just access to the x86_64-darwin versions? If the latter, you can use |
Im not entirely clued into the distinction here, so Ill give a quick tldr of what Im trying to do. Current unrefined (and definitely not functional yet) flake: flake.nix{
description = "sample text";
outputs = { self, nixpkgs }: {
packages.aarch64-darwin.default =
let
pkgs = nixpkgs.legacyPackages.aarch64-darwin.pkgsCross.x86_64-darwin;
in
pkgs.clangStdenv.mkDerivation rec {
name = "p4-fusion";
version = "v1.12";
srcs = [
(pkgs.fetchFromGitHub {
inherit name;
owner = "salesforce";
repo = "p4-fusion";
rev = "3ee482466464c18e6a635ff4f09cd75a2e1bfe0f";
sha256 = "sha256-rUXuBoXuOUanWxutd7dNgjn2vLFvHQ0IgCIn9vG5dgs=";
})
(pkgs.fetchzip {
name = "helix-core-api";
url = "https://cdist2.perforce.com/perforce/r21.1/bin.macosx1015x86_64/p4api.tgz";
})
];
sourceRoot = name;
preBuild = ''
mkdir -p ./vendor/helix-core-api/mac
cp -R ../helix-core-api ./vendor/helix-core-api/mac
'';
nativeBuildInputs = with pkgs; [
openssl
cmake
libiconv
pkg-config
pcre
libssh2
zlib
gss
openssh_gssapi
p4
];
buildInputs = with pkgs; [
openssl
libiconv
pcre
libssh2
zlib
gss
openssh_gssapi
p4
];
};
};
} |
Thanks for the explanation. The difference is
There are a couple of ways you can achieve what you are trying to do without using You can also assign the x86_64-darwin package to the aarch64-darwin, which is what I did in the modified flake below. Note that I had to make a few changes to get it to build.
The LibreSSL thing is a terrible hack, but I wanted to avoid linking against OpenSSL 1.0.2 if I could because it’s marked as insecure in nixpkgs and unsupported upstream. flake.nix
|
There's an SDK packaged along Darling, a Darwin/macOS emulation layer for Linux. The author of the PR that packages Maybe someone could add a Cc: @zhaofengli |
#180931 is pretty much dead. I need to pull the fix commits out into separate PRs that are still applicable, but I don’t think I’ll be going forward with that approach. My current focus is on bumping LLVM in #234710 and making that process more sustainable. After that, I have other things I need to look at (e.g., updating DXVK, landing some Wine changes, looking at Mesa on Darwin) first, then I might be able to pull out those PRs, but that won’t help with this issue. My recommendation on aarch64-darwin is to use |
I'm running into this issue when trying to use static builds on |
- I found out that Cargo workspaces can have a "root crate", which here is `ghcid-ng`. This lets us move all the `ghcid-ng` sources out of the `ghcid-ng` directory and into a top-level `src` directory, which is very nice. - The inevitable `nix/` directory has been created - Moved a few helper scripts to `nix/` and packaged them - The versioning and release process has been moved into Nix as well. - At least on Linux. Cross-compilation on macOS with Nix doesn't work: NixOS/nixpkgs#180771
- I found out that Cargo workspaces can have a "root crate", which here is `ghcid-ng`. This lets us move all the `ghcid-ng` sources out of the `ghcid-ng` directory and into a top-level `src` directory, which is very nice. - The inevitable `nix/` directory has been created - Moved a few helper scripts to `nix/` and packaged them - The versioning and release process has been moved into Nix as well. - At least on Linux. Cross-compilation on macOS with Nix doesn't work: NixOS/nixpkgs#180771
- I found out that Cargo workspaces can have a "root crate", which here is `ghcid-ng`. This lets us move all the `ghcid-ng` sources out of the `ghcid-ng` directory and into a top-level `src` directory, which is very nice. - The inevitable `nix/` directory has been created - Moved a few helper scripts to `nix/` and packaged them - The versioning and release process has been moved into Nix as well. - At least on Linux. Cross-compilation on macOS with Nix doesn't work: NixOS/nixpkgs#180771
Static builds are implemented as a cross build to a system with The problem with x86_64-darwin static builds is the same as regular cross builds. The source-based SDK needs some work done to make cross builds work. Once that’s done, I expect static builds for x86_64-darwin should also just work. |
So do you know why making |
I think I figured out the source of the loop. The
which (I believe?) in turn depends on Libsystem , while the apple-sdk-11.0 version of Libsystem uses stdenvNoCC :
which prevents this recursion. I haven't figured out why cc depends strictly on it though, instead of just being lazily recursive, only in attributes, which would be fine, since we only need some attributes, not the full derivation.
Edit: Hmm, commenting out those dependencies on |
The SDK structure is different between the 10.12 and 11.0 SDKs. The 11.0 SDK mostly just vendors stuff from the SDK while the 10.12 SDK actually builds stuff from the source releases. The stdenv has to jump through a few hoops to build stuff on the source-based SDK that’s a non-issue with the 11.0 SDK.
Not really. Debugging infinite recursions sucks. I put off fixing the pkgStatic issue with the clang 16 stdenv for about a month because I didn’t want to deal with it (working on fixing other packages isntead). Edit: If you’re using the new CLI, you can pass |
The reasoning in the comment seems suspect to me. Do we really need to match glibc, especially since aarch64-darwin doesn’t even use libresolv from nixpkgs (though it could)? I wonder if it would be good enough to include libresolv as a |
That’s because the Darwin stdenv uses assertions to make sure packages have the correct provenance (from the bootstrap tools, build by them, build by the final compiler, etc). On x86_64-darwin, it assumes that Libsystem is built with a regular stdenv. Changing it to build with stdenvNoCC means those assertions need updating. After I made that change, it hits an infinite recursion in ncurses. That’s because Libsystem exports the headers from ncurses. If I drop ncurses from Libsystem, it starts building stuff until it fails in xnu. I’m looking at that now. If I can get past xnu, it seems like the rest should be relatively smooth sailing. |
Replacing the target prefix with the following (copied from cctools but used elsewhere) fixes the xnu build failure and infinite recursion. I also cleaned up the derivation a bit. I’m going to take a break then let this build overnight.
|
I should add that I’m also building this stuff with clang 16 because I want to make sure that the clang 16 update is not blocked by any more cross-related changes. I assume clang 11 will work and will test it once I have a PR ready to submit. |
I was wrong. I had to use pkgsBuildBuild.darwin.bootstrap_cmds not buildPackages.darwin.bootstrap_cmds. Either way, the poc seems to have succeeded. CF doesn’t (yet) support static builds, but that can be fixed. Unfortunately, dynamic Darwin cross doesn’t work yet. There’s another infinite recursion I’ll look at once I have the bootstrap stdenv stuff in place. $ nix build .#pkgsStatic.curl --system x86_64-darwin
$ ./result-bin/bin/curl --version
curl 8.2.1 (x86_64-apple-darwin) libcurl/8.2.1 OpenSSL/3.0.10 zlib/1.2.13 zstd/1.5.5 libidn2/2.3.4 libssh2/1.11.0 nghttp2/1.54.0
Release-Date: 2023-07-26
Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HSTS HTTP2 HTTPS-proxy IDN Largefile libz NTLM NTLM_WB SSL threadsafe TLS-SRP UnixSockets zstd
$ otool -L ./result-bin/bin/curl
./result-bin/bin/curl:
@rpath/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1454.90.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.60.2)
$ file ./result-bin/bin/curl
./result-bin/bin/curl: Mach-O 64-bit executable x86_64 |
The release process was broken when we moved to a Cargo workspace. This fixes it. - I found out that Cargo workspaces can have a "root crate", which here is `ghcid-ng`. This lets us move all the `ghcid-ng` sources out of the `ghcid-ng` directory and into a top-level `src` directory, which is very nice. - The inevitable `nix/` directory has been created. - Moved a few helper scripts to `nix/` and packaged them. - The versioning and release process has been moved into Nix as well. This makes everything much slower but at least we know what versions of the tools we're using? - At least on Linux. Cross-compilation on macOS with Nix doesn't work: NixOS/nixpkgs#180771
As posted on Matrix just now:
That’s cross-compiled from aarch64-darwin to x86_64-darwin (i.e., native compilers not Rosetta 2). The curl is statically linked against everything except for Once that’s done (fixing some of the hacks to use a reduced Libsystem instead), I want to look at Linux to Darwin if it’s not too bad. The last time I tried it (to aarch64-darwin), it was failing to link cctools. |
I opened #256590 as draft but plan to set it to ready tomorrow once the build with clang 11 is complete. |
Just ran into this problem while trying to port Rust program builds for macOS to Nix: deltachat/deltachat-core-rust#5326 |
Cross compiling from aarch64-darwin to other targets like the esp32 also seems to be broken due to this (same infinite recursion error). EDIT: For others looking for a quick and dirty workaround in the meantime, I get successful builds pinning nixpkgs to 23.05. |
#346043 contains the new Darwin SDK work that includes cross-compilation support from Darwin to Darwin (either architecture). |
Closed by #346043 |
The build does not fail with infinite recursion anymore, but now I get an error "building for macOS-arm64 but attempting to link with file built for unknown-x86_64" from |
I've seen that bug but I don't remember the cause of it. I think it was related to using the wrong linker or an old LTO bug? Maybe it made it into the lix bug tracker, maybe not. |
I will try to comment out all the changes to release build, like enabling LTO, and see if it helps. EDIT: did not help. |
It’s a Rust issue. Cross-compilation doesn’t seem to work right currently. That should be opened as a new issue. |
Does it also affect nixpkgs? If you know more, could you open an issue? I am not sure if it is affecting all rust or just my usage of naersk and fenix. |
Sorry, it’s a Rust in nixpkgs implementation issue. For some reason, it’s trying to link object files from different architectures when it shouldn’t be doing that. |
I get the same issue (or very similar) trying a simple(?) crossbuild of
The errors are something like:
followed by many variants of the second line, and then a long list of I wasn't able to find an existing issue, but I easily could've missed it; if no-one knows of one, I'll open one. |
Describe the bug
It's currently seemingly impossible to cross compile for x86_64-darwin from aarch64-darwin, since the darwin SDK for x86_64 is old. #176661 provides some way to hack the stdenv to use the correct toolchain, but I have no idea how to integrate it with Rust.
I am testing against master, which should have that patch.
Specifically, I'm trying to build a Rust hello world for x86_64, which is trivial with
cargo build --target x86_64-apple-darwin
but I can't figure out how to get nixpkgs to generate that invocation with the cargoBuildHook. I've triedpkgsCross.myPackage
, but that's maybe the wrong approach?Steps To Reproduce
Steps to reproduce the behavior:
Expected behavior
Can build rust programs for x86_64-darwin
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
Notify maintainers
@reckenrode
@thefloweringash
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.The text was updated successfully, but these errors were encountered: