Skip to content

Commit

Permalink
darwin/stdenv: tapi stub based bootstrap
Browse files Browse the repository at this point in the history
Fixes bootstrapping on macOS Big Sur.
  • Loading branch information
thefloweringash authored and o1lo01ol1o committed Oct 21, 2021
1 parent 2e7a665 commit 923f606
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 100 deletions.

This file was deleted.

12 changes: 5 additions & 7 deletions pkgs/os-specific/darwin/darwin-stubs/default.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
{ stdenv, fetchFromGitHub }:
{ stdenv, fetchurl }:

stdenv.mkDerivation {
pname = "darwin-stubs";
version = "10.12";

src = fetchFromGitHub {
owner = "NixOS";
repo = "darwin-stubs";
rev = "80b3d4a57d3454c975eefd984c804dbd76f04ef2";
sha256 = "0sslg4rmskms8ixixv1gvnrvvvmn723vbfjj6mcn24fj2ncg38y7";
src = fetchurl {
url = "https://github.com/NixOS/darwin-stubs/releases/download/v20201216/10.12.tar.gz";
sha256 = "1fyd3xig7brkzlzp0ql7vyfj5sp8iy56kgp548mvicqdyw92adgm";
};

dontBuild = true;

installPhase = ''
mkdir $out
cp -vr stubs/$version/* $out
mv * $out
'';
}
70 changes: 56 additions & 14 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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";
Expand All @@ -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 {
Expand Down Expand Up @@ -259,6 +300,7 @@ in rec {

darwin = super.darwin // {
binutils = darwin.binutils.override {
coreutils = self.coreutils;
libc = self.darwin.Libsystem;
};
};
Expand All @@ -271,8 +313,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;
};
Expand Down Expand Up @@ -321,8 +363,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 ]);

Expand Down Expand Up @@ -373,8 +415,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 ]);

Expand Down
3 changes: 0 additions & 3 deletions pkgs/stdenv/darwin/make-bootstrap-tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 0 additions & 35 deletions pkgs/stdenv/darwin/unpack-bootstrap-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 923f606

Please sign in to comment.