Merge pull request #243367 from tjni/build2

build2: use lld from llvm 16 to link on darwin
This commit is contained in:
Ryan Burns 2023-07-14 15:59:42 -07:00 committed by GitHub
commit 22032910e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View file

@ -1,6 +1,7 @@
{ lib, stdenv
, fetchurl
, pkgs
, buildPackages
, fixDarwinDylibNames
}:
stdenv.mkDerivation rec {
@ -25,6 +26,10 @@ stdenv.mkDerivation rec {
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_16.lld)
];
doCheck = true;
@ -40,5 +45,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;
}

View file

@ -4,6 +4,7 @@
, fixDarwinDylibNames
, libbutl
, libpkgconf
, buildPackages
, enableShared ? !stdenv.hostPlatform.isStatic
, enableStatic ? !enableShared
}:
@ -57,6 +58,10 @@ 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_16.lld)
];
postPatch = ''
@ -73,6 +78,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;

View file

@ -19,6 +19,12 @@ build2ConfigurePhase() {
$build2ConfigureFlags "${build2ConfigureFlagsArray[@]}"
)
if [ -n "@isTargetDarwin@" ]; then
flagsArray+=("config.bin.ld=ld64-lld")
flagsArray+=("config.cc.loptions+=-fuse-ld=lld")
flagsArray+=("config.cc.loptions+=-headerpad_max_install_names")
fi
echo 'configure flags' "${flagsArray[@]}"
b configure "${flagsArray[@]}"