cctools: support LTO on Darwin

LTO is disabled during bootstrap to keep the bootstrap tools small and
avoid unnecessary LLVM rebuilds, but is enabled in the final stdenv
stage and should be usable by normal packages.
This commit is contained in:
Dan Peebles 2018-09-15 16:49:44 -04:00
parent b91ad0e54f
commit 110c252870
6 changed files with 15 additions and 10 deletions

View file

@ -119,12 +119,14 @@ in stdenv.mkDerivation (rec {
+ stdenv.lib.optionalString enableSharedLibraries ''
moveToOutput "lib/libLLVM-*" "$lib"
moveToOutput "lib/libLLVM${stdenv.hostPlatform.extensions.sharedLibrary}" "$lib"
moveToOutput "lib/libLTO${stdenv.hostPlatform.extensions.sharedLibrary}" "$lib"
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM-" "$lib/lib/libLLVM-"
''
+ stdenv.lib.optionalString (stdenv.isDarwin && enableSharedLibraries) ''
substituteInPlace "$out/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib"
--replace "\''${_IMPORT_PREFIX}/lib/libLLVM.dylib" "$lib/lib/libLLVM.dylib" \
--replace "\''${_IMPORT_PREFIX}/lib/libLTO.dylib" "$lib/lib/libLTO.dylib"
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib
ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib
'';

View file

@ -1,8 +1,6 @@
{ cctools, appleDerivation }:
{ appleDerivation }:
appleDerivation {
nativeBuildInputs = [ cctools ];
patches = [ ./clang-5.patch ];
postPatch = ''

View file

@ -215,7 +215,7 @@ let
# Splicing is currently broken in Nixpkgs
# cctools need to be specified manually here to handle this
ICU = applePackage "ICU" "osx-10.10.5" "1qihlp42n5g4dl0sn0f9pc0bkxy1452dxzf0vr6y5gqpshlzy03p" { inherit (buildPackages.darwin) cctools; };
ICU = applePackage "ICU" "osx-10.10.5" "1qihlp42n5g4dl0sn0f9pc0bkxy1452dxzf0vr6y5gqpshlzy03p" {};
IOKit = applePackage "IOKit" "osx-10.11.6" "0kcbrlyxcyirvg5p95hjd9k8a01k161zg0bsfgfhkb90kh2s8x00" { inherit IOKitSrcs; };
launchd = applePackage "launchd" "osx-10.9.5" "0w30hvwqq8j5n90s3qyp0fccxflvrmmjnicjri4i1vd2g196jdgj" {};

View file

@ -1,5 +1,5 @@
{ stdenv, fetchFromGitHub, autoconf, automake, libtool_2, autoreconfHook
, libcxxabi, libuuid
, libcxxabi, libuuid, llvm
, libobjc ? null, maloader ? null
, enableDumpNormalizedLibArgs ? false
}:
@ -56,7 +56,7 @@ let
autoreconfHook
];
buildInputs = [ libuuid ] ++
stdenv.lib.optionals stdenv.isDarwin [ libcxxabi libobjc ];
stdenv.lib.optionals stdenv.isDarwin [ llvm libcxxabi libobjc ];
patches = [
./ld-rpath-nonfinal.patch ./ld-ignore-rpath-link.patch

View file

@ -201,6 +201,7 @@ in rec {
python2 = self.python;
ninja = super.ninja.override { buildDocs = false; };
darwin = super.darwin // { cctools = super.darwin.cctools.override { llvm = null; }; };
};
in with prevStage; stageFun 1 prevStage {
extraPreHook = "export NIX_CFLAGS_COMPILE+=\" -F${bootstrapTools}/Library/Frameworks\"";

View file

@ -12,6 +12,10 @@ in rec {
singleBinary = false;
});
# We want a version of cctools without LLVM, because the LTO support ends up making
# the bootstrap tools huge and isn't really necessary for bootstrap
cctools_ = darwin.cctools.override { llvm = null; };
# Avoid debugging larger changes for now.
bzip2_ = bzip2.override (args: { linkStatic = true; });
@ -95,7 +99,7 @@ in rec {
# Copy binutils.
for i in as ld ar ranlib nm strip otool install_name_tool dsymutil lipo; do
cp ${darwin.cctools}/bin/$i $out/bin
cp ${cctools_}/bin/$i $out/bin
done
cp -rd ${pkgs.darwin.CF}/Library $out
@ -105,9 +109,9 @@ in rec {
nuke-refs $out/bin/*
rpathify() {
local libs=$(${darwin.cctools}/bin/otool -L "$1" | tail -n +2 | grep -o "$NIX_STORE.*-\S*") || true
local libs=$(${cctools_}/bin/otool -L "$1" | tail -n +2 | grep -o "$NIX_STORE.*-\S*") || true
for lib in $libs; do
${darwin.cctools}/bin/install_name_tool -change $lib "@rpath/$(basename $lib)" "$1"
${cctools_}/bin/install_name_tool -change $lib "@rpath/$(basename $lib)" "$1"
done
}