From 34c8fae43997917ee43522f4ab5aedf4855d5349 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Wed, 16 Dec 2020 13:59:18 +0900 Subject: darwin/stdenv: tapi stub based bootstrap Fixes bootstrapping on macOS Big Sur. --- pkgs/stdenv/darwin/default.nix | 70 ++++++++++++++++++++++------ pkgs/stdenv/darwin/make-bootstrap-tools.nix | 3 -- pkgs/stdenv/darwin/unpack-bootstrap-tools.sh | 35 -------------- 3 files changed, 56 insertions(+), 52 deletions(-) (limited to 'pkgs/stdenv') diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index f07b1ee73b87..ecec2903b5f7 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -54,8 +54,6 @@ in rec { args = [ ./unpack-bootstrap-tools.sh ]; inherit (bootstrapFiles) mkdir bzip2 cpio tarball; - reexportedLibrariesFile = - ../../os-specific/darwin/apple-source-releases/Libsystem/reexported_libraries; __impureHostDeps = commonImpureHostDeps; }; @@ -167,19 +165,57 @@ in rec { stage0 = stageFun 0 null { overrides = self: super: with stage0; { - coreutils = { name = "bootstrap-stage0-coreutils"; outPath = bootstrapTools; }; - gnugrep = { name = "bootstrap-stage0-gnugrep"; outPath = bootstrapTools; }; + coreutils = stdenv.mkDerivation { + name = "bootstrap-stage0-coreutils"; + buildCommand = '' + mkdir -p $out + ln -s ${bootstrapTools}/bin $out/bin + ''; + }; + + gnugrep = stdenv.mkDerivation { + name = "bootstrap-stage0-gnugrep"; + buildCommand = '' + mkdir -p $out + ln -s ${bootstrapTools}/bin $out/bin + ''; + }; darwin = super.darwin // { Libsystem = stdenv.mkDerivation { name = "bootstrap-stage0-Libsystem"; buildCommand = '' mkdir -p $out - ln -s ${bootstrapTools}/lib $out/lib + + cp -r ${self.darwin.darwin-stubs}/usr/lib $out/lib + chmod -R +w $out/lib + substituteInPlace $out/lib/libSystem.B.tbd --replace /usr/lib/system $out/lib/system + + ln -s libSystem.B.tbd $out/lib/libSystem.tbd + + for name in c dbm dl info m mx poll proc pthread rpcsvc util gcc_s.10.4 gcc_s.10.5; do + ln -s libSystem.tbd $out/lib/lib$name.tbd + done + + ln -s ${bootstrapTools}/lib/*.o $out/lib + + ln -s ${bootstrapTools}/lib/libresolv.9.dylib $out/lib + ln -s libresolv.9.dylib $out/lib/libresolv.dylib + ln -s ${bootstrapTools}/include-Libsystem $out/include ''; }; - dyld = bootstrapTools; + + darwin-stubs = super.darwin.darwin-stubs.override { inherit (self) stdenv fetchurl; }; + + dyld = { + name = "bootstrap-stage0-dyld"; + buildCommand = '' + mkdir -p $out + ln -s ${bootstrapTools}/lib $out/lib + ln -s ${bootstrapTools}/include $out/include + ''; + }; binutils = lib.makeOverridable (import ../../build-support/bintools-wrapper) { shell = "${bootstrapTools}/bin/bash"; @@ -194,10 +230,15 @@ in rec { }; llvmPackages_7 = { - clang-unwrapped = { + clang-unwrapped = stdenv.mkDerivation { name = "bootstrap-stage0-clang"; - outPath = bootstrapTools; version = bootstrapClangVersion; + buildCommand = '' + mkdir -p $out/lib + ln -s ${bootstrapTools}/bin $out/bin + ln -s ${bootstrapTools}/lib/clang $out/lib/clang + ln -s ${bootstrapTools}/include $out/include + ''; }; libcxx = stdenv.mkDerivation { @@ -256,6 +297,7 @@ in rec { darwin = super.darwin // { binutils = darwin.binutils.override { + coreutils = self.coreutils; libc = self.darwin.Libsystem; }; }; @@ -268,8 +310,8 @@ in rec { allowedRequisites = [ bootstrapTools ] ++ - (with pkgs; [ libcxx libcxxabi llvmPackages_7.compiler-rt ]) ++ - (with pkgs.darwin; [ Libsystem ]); + (with pkgs; [ coreutils gnugrep libcxx libcxxabi llvmPackages_7.clang-unwrapped llvmPackages_7.compiler-rt ]) ++ + (with pkgs.darwin; [ darwin-stubs Libsystem ]); overrides = persistent; }; @@ -318,8 +360,8 @@ in rec { [ bootstrapTools ] ++ (with pkgs; [ xz.bin xz.out libcxx libcxxabi llvmPackages_7.compiler-rt - zlib libxml2.out curl.out openssl.out libssh2.out - nghttp2.lib libkrb5 coreutils gnugrep pcre.out gmp libiconv + llvmPackages_7.clang-unwrapped zlib libxml2.out curl.out openssl.out + libssh2.out nghttp2.lib libkrb5 coreutils gnugrep pcre.out gmp libiconv ]) ++ (with pkgs.darwin; [ dyld Libsystem CF ICU locale ]); @@ -370,8 +412,8 @@ in rec { [ bootstrapTools ] ++ (with pkgs; [ xz.bin xz.out bash libcxx libcxxabi llvmPackages_7.compiler-rt - zlib libxml2.out curl.out openssl.out libssh2.out - nghttp2.lib libkrb5 coreutils gnugrep pcre.out gmp libiconv + llvmPackages_7.clang-unwrapped zlib libxml2.out curl.out openssl.out + libssh2.out nghttp2.lib libkrb5 coreutils gnugrep pcre.out gmp libiconv ]) ++ (with pkgs.darwin; [ dyld ICU Libsystem locale ]); diff --git a/pkgs/stdenv/darwin/make-bootstrap-tools.nix b/pkgs/stdenv/darwin/make-bootstrap-tools.nix index 1243b96e5051..9824d57dff86 100644 --- a/pkgs/stdenv/darwin/make-bootstrap-tools.nix +++ b/pkgs/stdenv/darwin/make-bootstrap-tools.nix @@ -180,9 +180,6 @@ in rec { unpack = stdenv.mkDerivation (bootstrapFiles // { name = "unpack"; - reexportedLibrariesFile = - ../../os-specific/darwin/apple-source-releases/Libsystem/reexported_libraries; - # This is by necessity a near-duplicate of unpack-bootstrap-tools.sh. If we refer to it directly, # we can't make any changes to it due to our testing stdenv depending on it. Think of this as the # unpack-bootstrap-tools.sh for the next round of bootstrap tools. diff --git a/pkgs/stdenv/darwin/unpack-bootstrap-tools.sh b/pkgs/stdenv/darwin/unpack-bootstrap-tools.sh index 0da80ec5ce56..37beeaf28f94 100644 --- a/pkgs/stdenv/darwin/unpack-bootstrap-tools.sh +++ b/pkgs/stdenv/darwin/unpack-bootstrap-tools.sh @@ -17,41 +17,6 @@ for i in $out/bin/*; do fi done -install_name_tool \ - -id $out/lib/system/libsystem_c.dylib \ - $out/lib/system/libsystem_c.dylib - -install_name_tool \ - -id $out/lib/system/libsystem_kernel.dylib \ - $out/lib/system/libsystem_kernel.dylib - -# TODO: this logic basically duplicates similar logic in the Libsystem expression. Deduplicate them! -libs=$(cat $reexportedLibrariesFile | grep -v '^#') - -for i in $libs; do - if [ "$i" != "/usr/lib/system/libsystem_kernel.dylib" ] && [ "$i" != "/usr/lib/system/libsystem_c.dylib" ]; then - args="$args -reexport_library $i" - fi -done - -ld -macosx_version_min 10.7 \ - -arch x86_64 \ - -dylib \ - -o $out/lib/libSystem.B.dylib \ - -compatibility_version 1.0 \ - -current_version 1226.10.1 \ - -reexport_library $out/lib/system/libsystem_c.dylib \ - -reexport_library $out/lib/system/libsystem_kernel.dylib \ - $args - -ln -s libSystem.B.dylib $out/lib/libSystem.dylib - -for name in c dbm dl info m mx poll proc pthread rpcsvc util gcc_s.10.4 gcc_s.10.5; do - ln -s libSystem.dylib $out/lib/lib$name.dylib -done - -ln -s libresolv.9.dylib $out/lib/libresolv.dylib - for i in $out/lib/*.dylib $out/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation; do if test ! -L "$i" -a "$i" != "$out/lib/libSystem*.dylib"; then echo "Patching $i" -- cgit 1.4.1