13 # libtapi is only supported building against Apple’s LLVM fork pinned to a specific revision.
14 # It can’t be built against upstream LLVM because it uses APIs that are specific to Apple’s fork.
15 # See: https://github.com/apple-oss-distributions/tapi/blob/main/Readme.md
17 # Apple’s LLVM fork uses its own versioning scheme.
18 # See: https://en.wikipedia.org/wiki/Xcode#Toolchain_versions
19 # Note: Can’t use a sparse checkout because the Darwin stdenv bootstrap can’t depend on fetchgit.
21 version = "15.0.0"; # As reported by upstream’s `tapi --version`.
22 rev = "2b5ff47e44b059c03de5779479d01a133ab4d581"; # Per the TAPI repo.
23 hash = "sha256-X37zBbpSEWmqtdTXsd1t++gp+0ggA8YtB73fGKNaiR0=";
26 stdenv.mkDerivation (finalAttrs: {
28 version = "1500.0.12.3";
39 owner = "apple-oss-distributions";
41 rev = "tapi-${finalAttrs.version}";
42 hash = "sha256-YeaA2OeSY1fXYJHPJJ0TrVC1brspSvutBtPMPGX6Y1o=";
44 # libtapi can’t avoid pulling the whole repo even though it needs only a couple of folders because
45 # `fetchgit` can’t be used in the Darwin bootstrap.
47 name = "apple-llvm-src";
49 repo = "llvm-project";
50 inherit (appleLlvm) rev hash;
55 # Older versions of ld64 may not support `-no_exported_symbols`, so use it only
56 # when the linker supports it.
57 # Note: This can be dropped once the bootstrap tools are updated after the ld64 update.
58 ./0001-Check-for-no_exported_symbols-linker-support.patch
59 # The recommended upstream revision of Apple’s LLVM fork needs this patch, or
60 # `tapi stubify` will crash when generating stubs.
62 url = "https://github.com/apple/llvm-project/commit/455bf3d1ccd6a52df5e38103532c1b8f49924edc.patch";
63 hash = "sha256-ujZcfdAls20JPIvjvO2Xv8st8cNTY/XTEQusICKBKSA";
65 # Updates `JSONReaderWriter` to work with the API change in the above patch.
66 ./0002-Pass-fileType-to-writeToStream.patch
67 # Fix build on Linux. GCC is more picky than clang about the field order.
68 ./0003-Match-designator-order-with-declaration-order.patch
73 # Enable building on non-Darwin platforms
74 substituteInPlace tapi/CMakeLists.txt \
75 --replace-fail 'message(FATAL_ERROR "Unsupported configuration.")' ""
77 # Remove the client limitation on linking to libtapi.dylib.
78 substituteInPlace tapi/tools/libtapi/CMakeLists.txt \
79 --replace-fail '-allowable_client ld' ""
80 # Replace hard-coded installation paths with standard ones.
81 declare -A installdirs=(
86 [local/share/man]=MANDIR
89 for dir in "''${!installdirs[@]}"; do
90 cmakevar=CMAKE_INSTALL_''${installdirs[$dir]}
91 for cmakelist in $(grep -rl "DESTINATION $dir" tapi); do
92 substituteInPlace "$cmakelist" \
93 --replace-fail "DESTINATION $dir" "DESTINATION \''${$cmakevar}"
96 # Doesn’t seem to exist publically.
97 substituteInPlace tapi/test/CMakeLists.txt \
98 --replace-fail tapi-configs ""
100 + lib.optionalString stdenv.hostPlatform.isLinux ''
101 # Remove Darwin-specific versioning flags.
102 substituteInPlace tapi/tools/libtapi/CMakeLists.txt \
103 --replace-fail '-current_version ''${DYLIB_VERSION} -compatibility_version 1' ""
110 sourceRoot = "source";
113 chmod -R u+w apple-llvm-src tapi-src
114 mv apple-llvm-src/{clang,cmake,llvm,utils} source
115 mv tapi-src source/tapi
120 buildInputs = [ zlib ]; # Upstream links against zlib in their distribution.
122 nativeBuildInputs = [
128 cmakeDir = "../llvm";
131 (lib.cmakeFeature "LLVM_ENABLE_PROJECTS" "clang;tapi")
132 (lib.cmakeFeature "LLVM_EXTERNAL_PROJECTS" "tapi")
133 (lib.cmakeBool "TAPI_INCLUDE_DOCS" true)
134 # Matches the version string format reported by upstream `tapi`.
135 (lib.cmakeFeature "TAPI_REPOSITORY_STRING" "tapi-${finalAttrs.version}")
136 (lib.cmakeFeature "TAPI_FULL_VERSION" appleLlvm.version)
137 # Match the versioning used by Apple’s LLVM fork (primarily used for .so versioning).
138 (lib.cmakeFeature "LLVM_VERSION_MAJOR" (lib.versions.major appleLlvm.version))
139 (lib.cmakeFeature "LLVM_VERSION_MINOR" (lib.versions.minor appleLlvm.version))
140 (lib.cmakeFeature "LLVM_VERSION_PATCH" (lib.versions.patch appleLlvm.version))
141 (lib.cmakeFeature "LLVM_VERSION_SUFFIX" "")
142 # Upstream `tapi` does not link against ncurses. Disable it explicitly to make sure
143 # it is not detected incorrectly from the bootstrap tools tarball.
144 (lib.cmakeBool "LLVM_ENABLE_TERMINFO" false)
145 # Disabling the benchmarks avoids a failure during the configure phase because
146 # the sparse checkout does not include the benchmarks.
147 (lib.cmakeBool "LLVM_INCLUDE_BENCHMARKS" false)
148 # tapi’s tests expect to target macOS 13.0 and build both x86_64 and universal
149 # binaries regardless of the host platform.
150 (lib.cmakeBool "LLVM_INCLUDE_TESTS" false)
151 (lib.cmakeBool "TAPI_INCLUDE_TESTS" false)
163 "install-tapi-headers"
169 # The man page is installed for these, but they’re not included in the source release.
170 rm $bin/share/man/man1/tapi-analyze.1 $bin/share/man/man1/tapi-api-verify.1
174 description = "Replaces the Mach-O Dynamic Library Stub files in Apple's SDKs to reduce the size";
175 homepage = "https://github.com/apple-oss-distributions/tapi/";
176 license = lib.licenses.ncsa;
177 mainProgram = "tapi";
178 maintainers = with lib.maintainers; [
182 platforms = lib.platforms.unix;