Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

freshBootstrapTools.bootstrapTools: update for new SDK pattern #348000

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions pkgs/stdenv/darwin/stdenv-bootstrap-tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@
gnused,
gnutar,
gzip,
jq,
ld64,
libffi,
libiconv,
libtapi,
libxml2,
libyaml,
llvmPackages,
ncurses,
nukeReferences,
oniguruma,
openssl,
patch,
pbzx,
runCommand,
writeText,
xar,
xarMinimal,
xz,
zlib,
}:
Expand Down Expand Up @@ -113,21 +115,11 @@ stdenv.mkDerivation (finalAttrs: {

in
''
mkdir -p $out/bin $out/lib $out/lib/darwin
mkdir -p $out/bin $out/include $out/lib $out/lib/darwin

${lib.optionalString stdenv.targetPlatform.isx86_64 ''
# Copy libSystem's .o files for various low-level boot stuff.
cp -d ${getLib darwin.Libsystem}/lib/*.o $out/lib

# Resolv is actually a link to another package, so let's copy it properly
cp -L ${getLib darwin.Libsystem}/lib/libresolv.9.dylib $out/lib
''}

cp -rL ${getDev darwin.Libsystem}/include $out
chmod -R u+w $out/include
cp -rL ${getDev libiconv}/include/* $out/include
cp -rL ${getDev gnugrep.pcre2}/include/* $out/include
mv $out/include $out/include-Libsystem

# Copy binutils.
for i in as ld ar ranlib nm strip otool install_name_tool lipo codesign_allocate; do
Expand Down Expand Up @@ -163,7 +155,7 @@ stdenv.mkDerivation (finalAttrs: {
cp ${getBin xz}/bin/xz $out/bin
cp -d ${getLib bzip2}/lib/libbz2*.dylib $out/lib
cp -d ${getLib gmpxx}/lib/libgmp*.dylib $out/lib
cp -d ${getLib xar}/lib/libxar*.dylib $out/lib
cp -d ${getLib xarMinimal}/lib/libxar*.dylib $out/lib
cp -d ${getLib xz}/lib/liblzma*.dylib $out/lib
cp -d ${getLib zlib}/lib/libz*.dylib $out/lib

Expand All @@ -185,18 +177,19 @@ stdenv.mkDerivation (finalAttrs: {
cp -d ${getLib llvmPackages.llvm}/lib/libLLVM.dylib $out/lib
cp -d ${getLib libffi}/lib/libffi*.dylib $out/lib

mkdir $out/include
cp -rd ${getDev llvmPackages.libcxx}/include/c++ $out/include

# copy .tbd assembly utils
cp ${getBin darwin.rewrite-tbd}/bin/rewrite-tbd $out/bin
cp -d ${getLib libyaml}/lib/libyaml*.dylib $out/lib
# Copy tools needed to build the SDK
cp -d ${getBin jq}/bin/* $out/bin
cp -d ${getBin libtapi}/bin/* $out/bin

cp -d ${getLib jq}/lib/lib*.dylib $out/lib
cp -d ${getLib oniguruma}/lib/lib*.dylib $out/lib
cp -d ${getLib libtapi}/lib/libtapi*.dylib $out/lib

# copy sigtool
cp -d ${getBin darwin.sigtool}/bin/{codesign,sigtool} $out/bin

cp -d ${getLib darwin.libtapi}/lib/libtapi*.dylib $out/lib

# tools needed to unpack bootstrap archive
mkdir -p unpack/bin unpack/lib
cp -d ${getBin bash}/bin/{bash,sh} unpack/bin
Expand Down
36 changes: 9 additions & 27 deletions pkgs/stdenv/darwin/test-bootstrap-tools.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
lib,
stdenv,
apple-sdk,
bootstrapTools,
hello,
}:
Expand Down Expand Up @@ -30,7 +31,7 @@ builtins.derivation {
mkdir -p $out/bin

for exe in $tools/bin/*; do
[[ $exe =~ bunzip2|codesign.*|false|install_name_tool|ld|lipo|pbzx|ranlib|rewrite-tbd|sigtool ]] && continue
[[ $exe =~ bunzip2|codesign.*|false|install_name_tool|ld|lipo|pbzx|ranlib|sigtool ]] && continue
$exe --version > /dev/null || { echo $exe failed >&2; exit 1; }
done

Expand All @@ -44,59 +45,40 @@ builtins.derivation {
lipo -info true
pbzx -v
# ranlib gets tested bulding hello
rewrite-tbd </dev/null
sigtool -h
rm true

# The grep will return a nonzero exit code if there is no match, and we want to assert that we have
# an SSL-capable curl
curl --version | grep SSL

# This approximates a bootstrap version of libSystem can that be
# assembled via fetchurl. Adapted from main libSystem expression.
mkdir libSystem-boot
cp -vr \
${stdenv.cc.libc_dev}/lib/libSystem.B.tbd \
${stdenv.cc.libc_dev}/lib/system \
libSystem-boot
# The stdenv bootstrap builds the SDK in the bootstrap. Use an existing SDK to test the tools.
export SDKROOT='${apple-sdk.sdkroot}'

sed -i "s|/usr/lib/system/|$PWD/libSystem-boot/system/|g" libSystem-boot/libSystem.B.tbd
ln -s libSystem.B.tbd libSystem-boot/libSystem.tbd
# End of bootstrap libSystem

export flags="-idirafter $tools/include-Libsystem --sysroot=$tools -L$tools/lib -L$PWD/libSystem-boot"
export flags="-idirafter $SDKROOT/usr/include --sysroot=$SDKROOT -L$SDKROOT/usr/lib -L$tools/lib -DTARGET_OS_IPHONE=0"

export CPP="clang -E $flags"
export CC="clang $flags"
export CXX="clang++ $flags --stdlib=libc++ -isystem$tools/include/c++/v1"

# NOTE: These tests do a separate 'install' step (using cp), because
# having clang write directly to the final location apparently will make
# running the executable fail signature verification. (SIGKILL'd)
#
# Suspect this is creating a corrupt entry in the kernel cache, but it is
# unique to cctools ld. (The problem goes away with `-fuse-ld=lld`.)

echo '#include <stdio.h>' >> hello1.c
echo '#include <float.h>' >> hello1.c
echo '#include <limits.h>' >> hello1.c
echo 'int main() { printf("Hello World\n"); return 0; }' >> hello1.c
$CC -o hello1 hello1.c
cp hello1 $out/bin/
$CC -o $out/bin/hello1 hello1.c
$out/bin/hello1

echo '#include <iostream>' >> hello3.cc
echo 'int main() { std::cout << "Hello World\n"; }' >> hello3.cc
$CXX -v -o hello3 hello3.cc
cp hello3 $out/bin/
$CXX -v -o $out/bin/hello3 hello3.cc
$out/bin/hello3

# test that libc++.dylib rpaths are correct so it can reference libc++abi.dylib when linked.
# using -Wl,-flat_namespace is required to generate an error
mkdir libtest/
ln -s $tools/lib/libc++.dylib libtest/
clang++ -Wl,-flat_namespace -idirafter $tools/include-Libsystem -isystem$tools/include/c++/v1 \
--sysroot=$tools -L./libtest -L$PWD/libSystem-boot hello3.cc
clang++ -Wl,-flat_namespace -idirafter $SDKROOT/usr/include -isystem$tools/include/c++/v1 \
--sysroot=$SDKROOT -L$SDKROOT/usr/lib -L./libtest -L$PWD/libSystem-boot hello3.cc

tar xvf ${hello.src}
cd hello-*
Expand Down