-
-
Save thefloweringash/7459f96d78ada56708db335d1b6af6c9 to your computer and use it in GitHub Desktop.
nixpkgs and tapi exploration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
# Something that can be built | |
src = pkgs.writeText "hello.c" '' | |
// No headers setup, just inline the definition | |
int puts( const char *str ); | |
int main() { puts("hello with tapi linkage!"); return 0; } | |
''; | |
# Impure, but copy to isolated path in the nix store to prove there's nothing | |
# up my sleeve | |
appleLibSystem = | |
let appleLibs = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib; | |
in builtins.path { | |
path = appleLibs; | |
filter = path: type: | |
path == "${toString appleLibs}/libSystem.tbd" || | |
path == "${toString appleLibs}/libSystem.B.tbd" ; | |
name = "apple-libSystem"; | |
}; | |
# Link using cctools | |
# | |
# Expected result: SUCCESS | |
# | |
# cctools must be compiled with tapi support | |
test_cctools = { runCommandNoCC, cctools, clang, tree }: runCommandNoCC "trivial-link-cctools" { | |
nativeBuildInputs = [ cctools clang.cc tree ]; | |
inherit src appleLibSystem; | |
} '' | |
set -x | |
clang -c $src -o main.o | |
echo "Contents of apple libsystem" | |
tree -s $appleLibSystem | |
# using ld64 from cctools-port, flags: | |
# -t logs loaded files | |
# -Z disables the default search paths | |
ld \ | |
-t \ | |
-Z \ | |
-o main \ | |
-L$appleLibSystem -lSystem \ | |
main.o | |
./main | |
mkdir $out | |
cp main $out | |
set +x | |
''; | |
# Link using llvm | |
# | |
# Expected result: FAILURE | |
# | |
# It looks like support for tapi is being upstreamed, but might not be here | |
# yet. | |
test_llvm = { runCommandNoCC, lld, clang, tree }: runCommandNoCC "trivial-link-llvm" { | |
nativeBuildInputs = [ lld clang.cc tree ]; | |
inherit src appleLibSystem; | |
} '' | |
set -x | |
clang -c $src -o main.o | |
echo "Contents of apple libsystem" | |
tree -s $appleLibSystem | |
# using ld64 from llvm, flags: | |
# -t logs loaded files | |
# -Z disables the default search paths | |
ld64.lld \ | |
-t \ | |
-Z \ | |
-o main \ | |
-L$appleLibSystem -lSystem \ | |
main.o | |
./main | |
mkdir $out | |
cp main $out | |
set +x | |
''; | |
pkgs = import ./. { | |
overlays = [ | |
(self: super: { | |
# Spurious test failure getting in the way :( | |
libuv = super.libuv.overrideAttrs (_: { doCheck = false; }); | |
}) | |
]; | |
}; | |
in | |
{ | |
test_cctools = pkgs.callPackage test_cctools { | |
cctools = pkgs.darwin.cctools.override { enableTapiSupport = true; }; | |
}; | |
test_llvm = pkgs.callPackage test_llvm { | |
clang = pkgs.clang_10; | |
lld = pkgs.llvmPackages_10.lld; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment