build2: use lld from llvm 16 to link on darwin#243367
build2: use lld from llvm 16 to link on darwin#243367r-burns merged 1 commit intoNixOS:staging-nextfrom tjni:build2
Conversation
|
Thanks for the ping. It’s failing due to two things:
I’m digging into this to see if there is a different fix. |
|
The following patch uses lld to link instead of ld64. I was able to build build2, bdep, bpkg, and libodb (albeit with clang 16 instead of clang 11). It’s not exactly pretty, but it appears things don’t necessarily use diff --git a/pkgs/development/tools/build-managers/build2/bootstrap.nix b/pkgs/development/tools/build-managers/build2/bootstrap.nix
index 4f9879840b2..0fadb42c8a4 100644
--- a/pkgs/development/tools/build-managers/build2/bootstrap.nix
+++ b/pkgs/development/tools/build-managers/build2/bootstrap.nix
@@ -1,6 +1,7 @@
{ lib, stdenv
, fetchurl
, pkgs
+, buildPackages
, fixDarwinDylibNames
}:
stdenv.mkDerivation rec {
@@ -25,6 +26,7 @@ stdenv.mkDerivation rec {
propagatedBuildInputs = lib.optionals stdenv.targetPlatform.isDarwin [
fixDarwinDylibNames
+ (lib.getBin buildPackages.llvmPackages.lld)
];
doCheck = true;
@@ -40,5 +42,10 @@ stdenv.mkDerivation rec {
runHook postInstall
'';
+ postFixup = ''
+ substituteInPlace $out/nix-support/setup-hook \
+ --subst-var-by isTargetDarwin '${toString stdenv.targetPlatform.isDarwin}'
+ '';
+
inherit (pkgs.build2) passthru;
}
diff --git a/pkgs/development/tools/build-managers/build2/default.nix b/pkgs/development/tools/build-managers/build2/default.nix
index 562d3aa0c47..6f636150ba3 100644
--- a/pkgs/development/tools/build-managers/build2/default.nix
+++ b/pkgs/development/tools/build-managers/build2/default.nix
@@ -4,6 +4,7 @@
, fixDarwinDylibNames
, libbutl
, libpkgconf
+, buildPackages
, enableShared ? !stdenv.hostPlatform.isStatic
, enableStatic ? !enableShared
}:
@@ -57,6 +58,9 @@ stdenv.mkDerivation rec {
# LC_LOAD_DYLIB entries containing @rpath, requiring manual fixup
propagatedBuildInputs = lib.optionals stdenv.targetPlatform.isDarwin [
fixDarwinDylibNames
+ # Build2 needs to use lld on Darwin because it creates thin archives when it detects `llvm-ar`,
+ # which ld64 does not support.
+ (lib.getBin buildPackages.llvmPackages.lld)
];
postPatch = ''
@@ -73,6 +77,11 @@ stdenv.mkDerivation rec {
install_name_tool -add_rpath "''${!outputLib}/lib" "''${!outputBin}/bin/b"
'';
+ postFixup = ''
+ substituteInPlace $dev/nix-support/setup-hook \
+ --subst-var-by isTargetDarwin '${toString stdenv.targetPlatform.isDarwin}'
+ '';
+
passthru = {
bootstrap = build2;
inherit configSharedStatic;
diff --git a/pkgs/development/tools/build-managers/build2/setup-hook.sh b/pkgs/development/tools/build-managers/build2/setup-hook.sh
index 16b592d3c10..1d19091ac98 100644
--- a/pkgs/development/tools/build-managers/build2/setup-hook.sh
+++ b/pkgs/development/tools/build-managers/build2/setup-hook.sh
@@ -19,6 +19,12 @@ build2ConfigurePhase() {
$build2ConfigureFlags "${build2ConfigureFlagsArray[@]}"
)
+ if [ -n "@isTargetDarwin@" ]; then
+ flagsArray+=("config.bin.ld=ld64-lld")
+ flagsArray+=("config.cc.coptions+=-fuse-ld=lld")
+ flagsArray+=("config.cc.loptions+=-headerpad_max_install_names")
+ fi
+
echo 'configure flags' "${flagsArray[@]}"
b configure "${flagsArray[@]}" |
|
Aha, I see. Where does Please let me know if you'd like me to apply these changes, or if you'd like to create a separate PR. |
It’s substituted in the
It’s up to you. This PR already has the context of the issue, so that might be easier, but I can also open a separate one. |
|
Give me a few minutes to try to do this and test it. |
|
Builds
I currently do see these warnings when building |
The bootstrap derivation only has one output while the actual build also has a
I thought I tried that, but I might have done something wrong. I agree with this change.
|
|
Something is going wrong when building libbutl (in between build2's bootstrap and build2 proper): regardless of which clang version I use, even if I add CoreFoundation to |
|
It appears lld 11 doesn’t have very good Mach-O support. It didn’t even get arm64 support until lld 13. Instead of using |
|
Result of 22 packages built:
|
|
Using |
r-burns
left a comment
There was a problem hiding this comment.
Tested on x86_64-darwin. Nice work, thanks for the fix!
Description of changes
This seems to fix the build of
build2after the darwin stdenv rework in #240433. For some reason, thearfrom cctools-llvm produces an artifact that breaks linking in this package with the following error:Also wouldn't mind a better solution than this.
Broken right now in staging-next so targeting it: #241951
/cc @reckenrode
Things done
sandbox = trueset 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/)