darwin/stdenv: tapi stub based bootstrap

Fixes bootstrapping on macOS Big Sur.
This commit is contained in:
Andrew Childs
2020-12-22 11:43:54 +09:00
parent 55868ac425
commit 34c8fae439
5 changed files with 61 additions and 100 deletions
+56 -14
View File
@@ -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 ]);
@@ -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.
@@ -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"