From 7f1a82d4761ecced506035ee175160c2f3b5fe39 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Thu, 15 Oct 2020 23:42:09 +0200 Subject: [PATCH 01/18] stdenv/darwin: bump bootstrap tools This new version has tapi support, which is needed to build the new stubs based libSystem, etc. and Big Sur support. You can verify the provenance of these yourself by checking Hydra here: https://hydra.nixos.org/build/128192471 --- pkgs/stdenv/darwin/default.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 58da8b71b65..5540216b0d8 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -7,15 +7,15 @@ # Allow passing in bootstrap files directly so we can test the stdenv bootstrap process when changing the bootstrap tools , bootstrapFiles ? let fetch = { file, sha256, executable ? true }: import { - url = "http://tarballs.nixos.org/stdenv-darwin/x86_64/d5bdfcbfe6346761a332918a267e82799ec954d2/${file}"; + url = "http://tarballs.nixos.org/stdenv-darwin/x86_64/5ab5783e4f46c373c6de84deac9ad59b608bb2e6/${file}"; inherit (localSystem) system; inherit sha256 executable; }; in { - sh = fetch { file = "sh"; sha256 = "07wm33f1yzfpcd3rh42f8g096k4cvv7g65p968j28agzmm2s7s8m"; }; - bzip2 = fetch { file = "bzip2"; sha256 = "0y9ri2aprkrp2dkzm6229l0mw4rxr2jy7vvh3d8mxv2698v2kdbm"; }; - mkdir = fetch { file = "mkdir"; sha256 = "0sb07xpy66ws6f2jfnpjibyimzb71al8n8c6y4nr8h50al3g90nr"; }; - cpio = fetch { file = "cpio"; sha256 = "0r5c54hg678w7zydx27bzl9p3v9fs25y5ix6vdfi1ilqim7xh65n"; }; - tarball = fetch { file = "bootstrap-tools.cpio.bz2"; sha256 = "18hp5w6klr8g307ap4368r255qpzg9r0vwg9vqvj8f2zy1xilcjf"; executable = false; }; + sh = fetch { file = "sh"; sha256 = "sha256-nbb4XEk3go7ttiWrQyKQMLzPr+qUnwnHkWMtVCZsMCs="; }; + bzip2 = fetch { file = "bzip2"; sha256 = "sha256-ybnA+JWrKhXSfn20+GVKXkHFTp2Zt79hat8hAVmsUOc="; }; + mkdir = fetch { file = "mkdir"; sha256 = "sha256-nmvMxmfcY41/60Z/E8L9u0vgePW5l30Dqw1z+Nr02Hk="; }; + cpio = fetch { file = "cpio"; sha256 = "sha256-cB36rN3NLj19Tk37Kc5bodMFMO+mCpEQkKKo0AEMkaU="; }; + tarball = fetch { file = "bootstrap-tools.cpio.bz2"; sha256 = "sha256-kh2vKmjCr/HvR06czZbxUxV5KDRxSF27M6nN3cyofRI="; executable = false; }; } }: From 86ee107a15ac7197380d5b44697cd2b3af00bf2f Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 31 Jul 2020 23:03:51 +0900 Subject: [PATCH 02/18] darwin/stdenv: assemble full clang toolchain Adapted from main expression for clang 7. --- pkgs/stdenv/darwin/default.nix | 48 +++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 5540216b0d8..5386213f2ad 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -24,6 +24,8 @@ assert crossSystem == localSystem; let inherit (localSystem) system platform; + bootstrapClangVersion = "7.1.0"; + commonImpureHostDeps = [ "/bin/sh" "/usr/lib/libSystem.B.dylib" @@ -90,7 +92,18 @@ in rec { inherit shell; inherit (last) stdenvNoCC; - extraPackages = []; + extraPackages = [ + # last.pkgs.llvmPackages_7.libcxxabi # TODO: is this required? if not, why not? + last.pkgs.llvmPackages_7.compiler-rt + ]; + + extraBuildCommands = '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${bootstrapTools}/lib/clang/${bootstrapClangVersion}/include" "$rsrc" + ln -s "${last.pkgs.llvmPackages_7.compiler-rt.out}/lib" "$rsrc/lib" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; nativeTools = false; nativeLibc = false; @@ -180,6 +193,15 @@ in rec { ln -s ${bootstrapTools}/lib/libc++abi.dylib $out/lib/libc++abi.dylib ''; }; + + compiler-rt = stdenv.mkDerivation { + name = "bootstrap-stage0-compiler-rt"; + buildCommand = '' + mkdir -p $out/lib + ln -s ${bootstrapTools}/lib/libclang_rt* $out/lib + ln -s ${bootstrapTools}/lib/darwin $out/lib/darwin + ''; + }; }; }; @@ -195,6 +217,12 @@ in rec { python3 = super.python3Minimal; ninja = super.ninja.override { buildDocs = false; }; + + llvmPackages_7 = super.llvmPackages_7 // (let + libraries = super.llvmPackages_7.libraries.extend (_: _: { + inherit (llvmPackages_7) compiler-rt; + }); + in { inherit libraries; } // libraries); }; in with prevStage; stageFun 1 prevStage { extraPreHook = "export NIX_CFLAGS_COMPILE+=\" -F${bootstrapTools}/Library/Frameworks\""; @@ -203,7 +231,9 @@ in rec { libcxx = pkgs.libcxx; allowedRequisites = - [ bootstrapTools ] ++ (with pkgs; [ libcxx libcxxabi ]) ++ [ pkgs.darwin.Libsystem ]; + [ bootstrapTools ] ++ + (with pkgs; [ libcxx libcxxabi llvmPackages_7.compiler-rt ]) ++ + (with pkgs.darwin; [ Libsystem ]); overrides = persistent; }; @@ -217,6 +247,12 @@ in rec { findfreetype libssh curl cmake autoconf automake libtool ed cpio coreutils libssh2 nghttp2 libkrb5 ninja; + llvmPackages_7 = super.llvmPackages_7 // (let + libraries = super.llvmPackages_7.libraries.extend (_: _: { + inherit (llvmPackages_7) compiler-rt; + }); + in { inherit libraries; } // libraries); + darwin = super.darwin // { inherit (darwin) dyld Libsystem xnu configd ICU libdispatch libclosure launchd CF; @@ -234,8 +270,8 @@ in rec { allowedRequisites = [ bootstrapTools ] ++ (with pkgs; [ - xz.bin xz.out libcxx libcxxabi zlib libxml2.out curl.out openssl.out libssh2.out - nghttp2.lib libkrb5 + xz.bin xz.out libcxx libcxxabi llvmPackages_7.compiler-rt zlib + libxml2.out curl.out openssl.out libssh2.out nghttp2.lib libkrb5 ]) ++ (with pkgs.darwin; [ dyld Libsystem CF ICU locale ]); @@ -284,8 +320,8 @@ in rec { allowedRequisites = [ bootstrapTools ] ++ (with pkgs; [ - xz.bin xz.out bash libcxx libcxxabi zlib libxml2.out curl.out openssl.out libssh2.out - nghttp2.lib libkrb5 + xz.bin xz.out bash libcxx libcxxabi llvmPackages_7.compiler-rt zlib + libxml2.out curl.out openssl.out libssh2.out nghttp2.lib libkrb5 ]) ++ (with pkgs.darwin; [ dyld ICU Libsystem locale ]); From fece3eb2e981b3bd9ea73b34f302ff3aa3d9f81c Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 31 Jul 2020 23:03:51 +0900 Subject: [PATCH 03/18] darwin/stdenv: refactoring Build the llvm support libraries (libcxx, libcxxabi) from scratch without using the existing llvm libraries. This is the same spirit and similar implementation as the "useLLVM" bootstrap in llvm package sets. Critically it avoids having libcxxabi provided by the cc-wrapper when building libcxx, which otherwise results in two libcxxabi instances. $ otool -L /nix/store/vd4vvgs9xngqbjzpg3qc41wl6jh42s9i-libc++-7.1.0/lib/libc++.dylib /nix/store/vd4vvgs9xngqbjzpg3qc41wl6jh42s9i-libc++-7.1.0/lib/libc++.dylib: /nix/store/vd4vvgs9xngqbjzpg3qc41wl6jh42s9i-libc++-7.1.0/lib/libc++.1.0.dylib (compatibility version 1.0.0, current version 1.0.0) /nix/store/gmpwk5fyp3iasppqrrdpswxvid6kcp8r-libc++abi-7.1.0/lib/libc++abi.dylib (compatibility version 1.0.0, current version 1.0.0) /nix/store/3hn7azynqgp2pm5gpdg45gpq0ia72skg-libc++abi-7.1.0/lib/libc++abi.dylib (compatibility version 1.0.0, current version 1.0.0) /nix/store/1nq94scbxs6bk7pimqhvz76q6cfmbv97-Libsystem-osx-10.12.6/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1) Additionally move some utilities (clang, binutils, coreutils, gnugrep) to the stage layers so they can be replaced before the final stdenv. This should cause most of stage4 to be built from the toolchain assembled as of stage3 instead of the bootstrap toolchain. --- .../compilers/llvm/7/libc++abi.nix | 5 +- pkgs/stdenv/darwin/default.nix | 132 ++++++++++++------ 2 files changed, 94 insertions(+), 43 deletions(-) diff --git a/pkgs/development/compilers/llvm/7/libc++abi.nix b/pkgs/development/compilers/llvm/7/libc++abi.nix index 97141a0bd40..7f2ec528f3c 100644 --- a/pkgs/development/compilers/llvm/7/libc++abi.nix +++ b/pkgs/development/compilers/llvm/7/libc++abi.nix @@ -1,4 +1,5 @@ { stdenv, cmake, fetch, libcxx, llvm, version +, standalone ? false # on musl the shared objects don't build , enableShared ? ! stdenv.hostPlatform.isMusl }: @@ -20,7 +21,9 @@ stdenv.mkDerivation { patch -p1 -d $(ls -d libcxx-*) -i ${../libcxx-0001-musl-hacks.patch} ''; - cmakeFlags = stdenv.lib.optional (!enableShared) "-DLIBCXXABI_ENABLE_SHARED=OFF"; + cmakeFlags = + stdenv.lib.optional standalone "-DLLVM_ENABLE_LIBCXX=ON" ++ + stdenv.lib.optional (!enableShared) "-DLIBCXXABI_ENABLE_SHARED=OFF"; installPhase = if stdenv.isDarwin then '' diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 5386213f2ad..fbd5f1cf3f0 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -74,44 +74,48 @@ in rec { inherit (last) stdenv; }; - coreutils = { name = "${name}-coreutils"; outPath = bootstrapTools; }; - gnugrep = { name = "${name}-gnugrep"; outPath = bootstrapTools; }; + mkExtraBuildCommands = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc}/lib/clang/${cc.version}/include" "$rsrc" + ln -s "${last.pkgs.llvmPackages_7.compiler-rt.out}/lib" "$rsrc/lib" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; - bintools = import ../../build-support/bintools-wrapper { - inherit shell; - inherit (last) stdenvNoCC; + mkCC = overrides: import ../../build-support/cc-wrapper ( + let args = { + inherit shell; + inherit (last) stdenvNoCC; - nativeTools = false; - nativeLibc = false; - inherit buildPackages coreutils gnugrep; - libc = last.pkgs.darwin.Libsystem; - bintools = { name = "${name}-binutils"; outPath = bootstrapTools; }; - }; - - cc = if last == null then "/dev/null" else import ../../build-support/cc-wrapper { - inherit shell; - inherit (last) stdenvNoCC; + nativeTools = false; + nativeLibc = false; + inherit buildPackages libcxx; + inherit (last.pkgs) coreutils gnugrep; + bintools = last.pkgs.darwin.binutils; + libc = last.pkgs.darwin.Libsystem; + isClang = true; + cc = last.pkgs.llvmPackages_7.clang-unwrapped; + }; in args // (overrides args)); + cc = if last == null then "/dev/null" else mkCC ({ cc, ... }: { extraPackages = [ - # last.pkgs.llvmPackages_7.libcxxabi # TODO: is this required? if not, why not? + last.pkgs.llvmPackages_7.libcxxabi last.pkgs.llvmPackages_7.compiler-rt ]; + extraBuildCommands = mkExtraBuildCommands cc; + }); + ccNoLibcxx = if last == null then "/dev/null" else mkCC ({ cc, ... }: { + libcxx = null; + extraPackages = [ + last.pkgs.llvmPackages_7.compiler-rt + ]; extraBuildCommands = '' - rsrc="$out/resource-root" - mkdir "$rsrc" - ln -s "${bootstrapTools}/lib/clang/${bootstrapClangVersion}/include" "$rsrc" - ln -s "${last.pkgs.llvmPackages_7.compiler-rt.out}/lib" "$rsrc/lib" - echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags - ''; - - nativeTools = false; - nativeLibc = false; - inherit buildPackages coreutils gnugrep bintools libcxx; - libc = last.pkgs.darwin.Libsystem; - isClang = true; - cc = { name = "${name}-clang"; outPath = bootstrapTools; }; - }; + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${last.pkgs.llvmPackages_7.compiler-rt}/lib" >> $out/nix-support/cc-cflags + echo "-nostdlib++" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }); thisStdenv = import ../generic { name = "${name}-stdenv-darwin"; @@ -150,7 +154,10 @@ in rec { extraAttrs = { inherit macosVersionMin appleSdkVersion platform; }; - overrides = self: super: (overrides self super) // { fetchurl = thisStdenv.fetchurlBoot; }; + overrides = self: super: (overrides self super) // { + inherit ccNoLibcxx; + fetchurl = thisStdenv.fetchurlBoot; + }; }; in { @@ -160,6 +167,9 @@ 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; }; + darwin = super.darwin // { Libsystem = stdenv.mkDerivation { name = "bootstrap-stage0-Libsystem"; @@ -170,9 +180,26 @@ in rec { ''; }; dyld = bootstrapTools; + + binutils = lib.makeOverridable (import ../../build-support/bintools-wrapper) { + shell = "${bootstrapTools}/bin/bash"; + inherit (self) stdenvNoCC; + + nativeTools = false; + nativeLibc = false; + inherit (self) buildPackages coreutils gnugrep; + libc = self.pkgs.darwin.Libsystem; + bintools = { name = "bootstrap-stage0-binutils"; outPath = bootstrapTools; }; + }; }; llvmPackages_7 = { + clang-unwrapped = { + name = "bootstrap-stage0-clang"; + outPath = bootstrapTools; + version = bootstrapClangVersion; + }; + libcxx = stdenv.mkDerivation { name = "bootstrap-stage0-libcxx"; phases = [ "installPhase" "fixupPhase" ]; @@ -219,10 +246,19 @@ in rec { ninja = super.ninja.override { buildDocs = false; }; llvmPackages_7 = super.llvmPackages_7 // (let - libraries = super.llvmPackages_7.libraries.extend (_: _: { - inherit (llvmPackages_7) compiler-rt; + tools = super.llvmPackages_7.tools.extend (_: _: { + inherit (llvmPackages_7) clang-unwrapped; }); - in { inherit libraries; } // libraries); + libraries = super.llvmPackages_7.libraries.extend (_: _: { + inherit (llvmPackages_7) compiler-rt libcxx libcxxabi; + }); + in { inherit tools libraries; } // tools // libraries); + + darwin = super.darwin // { + binutils = darwin.binutils.override { + libc = self.darwin.Libsystem; + }; + }; }; in with prevStage; stageFun 1 prevStage { extraPreHook = "export NIX_CFLAGS_COMPILE+=\" -F${bootstrapTools}/Library/Frameworks\""; @@ -248,14 +284,24 @@ in rec { libssh2 nghttp2 libkrb5 ninja; llvmPackages_7 = super.llvmPackages_7 // (let - libraries = super.llvmPackages_7.libraries.extend (_: _: { - inherit (llvmPackages_7) compiler-rt; + tools = super.llvmPackages_7.tools.extend (_: _: { + inherit (llvmPackages_7) clang-unwrapped; }); - in { inherit libraries; } // libraries); + libraries = super.llvmPackages_7.libraries.extend (_: libSuper: { + inherit (llvmPackages_7) compiler-rt; + libcxx = libSuper.libcxx.override { + stdenv = overrideCC self.stdenv self.ccNoLibcxx; + }; + libcxxabi = libSuper.libcxxabi.override { + stdenv = overrideCC self.stdenv self.ccNoLibcxx; + standalone = true; + }; + }); + in { inherit tools libraries; } // tools // libraries); darwin = super.darwin // { inherit (darwin) - dyld Libsystem xnu configd ICU libdispatch libclosure launchd CF; + binutils dyld Libsystem xnu configd ICU libdispatch libclosure launchd CF; }; }; in with prevStage; stageFun 2 prevStage { @@ -270,8 +316,9 @@ in rec { allowedRequisites = [ 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 + 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 ]) ++ (with pkgs.darwin; [ dyld Libsystem CF ICU locale ]); @@ -320,8 +367,9 @@ in rec { allowedRequisites = [ 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 + 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 ]) ++ (with pkgs.darwin; [ dyld ICU Libsystem locale ]); From ddd17201abbec8bf04e55164b995eb148ae94b48 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 30 Jul 2020 00:32:34 +0900 Subject: [PATCH 04/18] compiler-rt: prevent platform sniffing on Darwin Exposed by the tbd stubs which contains fat libraries. The previously used proxy libraries were x86_64 only. --- pkgs/development/compilers/llvm/10/compiler-rt.nix | 5 +++++ pkgs/development/compilers/llvm/5/compiler-rt.nix | 5 +++++ pkgs/development/compilers/llvm/6/compiler-rt.nix | 5 +++++ pkgs/development/compilers/llvm/7/compiler-rt.nix | 5 +++++ pkgs/development/compilers/llvm/8/compiler-rt.nix | 5 +++++ pkgs/development/compilers/llvm/9/compiler-rt.nix | 5 +++++ 6 files changed, 30 insertions(+) diff --git a/pkgs/development/compilers/llvm/10/compiler-rt.nix b/pkgs/development/compilers/llvm/10/compiler-rt.nix index 47bbe808ac2..e6882cbabb8 100644 --- a/pkgs/development/compilers/llvm/10/compiler-rt.nix +++ b/pkgs/development/compilers/llvm/10/compiler-rt.nix @@ -41,6 +41,11 @@ stdenv.mkDerivation rec { "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" ] ++ stdenv.lib.optionals (bareMetal) [ "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ stdenv.lib.optionals (stdenv.hostPlatform.isDarwin) [ + # The compiler-rt build infrastructure sniffs supported platforms on Darwin + # and finds i386;x86_64;x86_64h. We only build for x86_64, so linking fails + # when it tries to use libc++ and libc++api for i386. + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.parsed.cpu.name}" ]; outputs = [ "out" "dev" ]; diff --git a/pkgs/development/compilers/llvm/5/compiler-rt.nix b/pkgs/development/compilers/llvm/5/compiler-rt.nix index 32d6dd3d479..41f2b24b057 100644 --- a/pkgs/development/compilers/llvm/5/compiler-rt.nix +++ b/pkgs/development/compilers/llvm/5/compiler-rt.nix @@ -41,6 +41,11 @@ stdenv.mkDerivation { "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" ] ++ stdenv.lib.optionals (bareMetal) [ "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ stdenv.lib.optionals (stdenv.hostPlatform.isDarwin) [ + # The compiler-rt build infrastructure sniffs supported platforms on Darwin + # and finds i386;x86_64;x86_64h. We only build for x86_64, so linking fails + # when it tries to use libc++ and libc++api for i386. + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.parsed.cpu.name}" ]; outputs = [ "out" "dev" ]; diff --git a/pkgs/development/compilers/llvm/6/compiler-rt.nix b/pkgs/development/compilers/llvm/6/compiler-rt.nix index 89f25cad2c5..8bd61f5d7f7 100644 --- a/pkgs/development/compilers/llvm/6/compiler-rt.nix +++ b/pkgs/development/compilers/llvm/6/compiler-rt.nix @@ -41,6 +41,11 @@ stdenv.mkDerivation { "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" ] ++ stdenv.lib.optionals (bareMetal) [ "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ stdenv.lib.optionals (stdenv.hostPlatform.isDarwin) [ + # The compiler-rt build infrastructure sniffs supported platforms on Darwin + # and finds i386;x86_64;x86_64h. We only build for x86_64, so linking fails + # when it tries to use libc++ and libc++api for i386. + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.parsed.cpu.name}" ]; outputs = [ "out" "dev" ]; diff --git a/pkgs/development/compilers/llvm/7/compiler-rt.nix b/pkgs/development/compilers/llvm/7/compiler-rt.nix index 97a5d73f304..ec9b7e6e6ad 100644 --- a/pkgs/development/compilers/llvm/7/compiler-rt.nix +++ b/pkgs/development/compilers/llvm/7/compiler-rt.nix @@ -41,6 +41,11 @@ stdenv.mkDerivation { "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" ] ++ stdenv.lib.optionals (bareMetal) [ "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ stdenv.lib.optionals (stdenv.hostPlatform.isDarwin) [ + # The compiler-rt build infrastructure sniffs supported platforms on Darwin + # and finds i386;x86_64;x86_64h. We only build for x86_64, so linking fails + # when it tries to use libc++ and libc++api for i386. + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.parsed.cpu.name}" ]; outputs = [ "out" "dev" ]; diff --git a/pkgs/development/compilers/llvm/8/compiler-rt.nix b/pkgs/development/compilers/llvm/8/compiler-rt.nix index a907d408655..3c6265c4fca 100644 --- a/pkgs/development/compilers/llvm/8/compiler-rt.nix +++ b/pkgs/development/compilers/llvm/8/compiler-rt.nix @@ -41,6 +41,11 @@ stdenv.mkDerivation { "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" ] ++ stdenv.lib.optionals (bareMetal) [ "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ stdenv.lib.optionals (stdenv.hostPlatform.isDarwin) [ + # The compiler-rt build infrastructure sniffs supported platforms on Darwin + # and finds i386;x86_64;x86_64h. We only build for x86_64, so linking fails + # when it tries to use libc++ and libc++api for i386. + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.parsed.cpu.name}" ]; outputs = [ "out" "dev" ]; diff --git a/pkgs/development/compilers/llvm/9/compiler-rt.nix b/pkgs/development/compilers/llvm/9/compiler-rt.nix index 394f66ff7f1..13b0b522771 100644 --- a/pkgs/development/compilers/llvm/9/compiler-rt.nix +++ b/pkgs/development/compilers/llvm/9/compiler-rt.nix @@ -41,6 +41,11 @@ stdenv.mkDerivation rec { "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" ] ++ stdenv.lib.optionals (bareMetal) [ "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ stdenv.lib.optionals (stdenv.hostPlatform.isDarwin) [ + # The compiler-rt build infrastructure sniffs supported platforms on Darwin + # and finds i386;x86_64;x86_64h. We only build for x86_64, so linking fails + # when it tries to use libc++ and libc++api for i386. + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.parsed.cpu.name}" ]; outputs = [ "out" "dev" ]; From 8946ff8d71313fbe9634e242149f1e3fb6aa824b Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 10 Sep 2020 19:06:20 +0900 Subject: [PATCH 05/18] darwin/darwin-stubs: init --- .../darwin/darwin-stubs/default.nix | 20 +++++++++++++++++++ pkgs/stdenv/darwin/default.nix | 10 ++++++---- pkgs/top-level/darwin-packages.nix | 2 ++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 pkgs/os-specific/darwin/darwin-stubs/default.nix diff --git a/pkgs/os-specific/darwin/darwin-stubs/default.nix b/pkgs/os-specific/darwin/darwin-stubs/default.nix new file mode 100644 index 00000000000..f7f083e32f4 --- /dev/null +++ b/pkgs/os-specific/darwin/darwin-stubs/default.nix @@ -0,0 +1,20 @@ +{ stdenv, fetchFromGitHub }: + +stdenv.mkDerivation { + pname = "darwin-stubs"; + version = "10.12"; + + src = fetchFromGitHub { + owner = "NixOS"; + repo = "darwin-stubs"; + rev = "80b3d4a57d3454c975eefd984c804dbd76f04ef2"; + sha256 = "0sslg4rmskms8ixixv1gvnrvvvmn723vbfjj6mcn24fj2ncg38y7"; + }; + + dontBuild = true; + + installPhase = '' + mkdir $out + cp -vr stubs/$version/* $out + ''; +} diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index fbd5f1cf3f0..f07b1ee73b8 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -301,7 +301,8 @@ in rec { darwin = super.darwin // { inherit (darwin) - binutils dyld Libsystem xnu configd ICU libdispatch libclosure launchd CF; + binutils dyld Libsystem xnu configd ICU libdispatch libclosure + launchd CF darwin-stubs; }; }; in with prevStage; stageFun 2 prevStage { @@ -345,7 +346,8 @@ in rec { darwin = super.darwin // { inherit (darwin) - dyld Libsystem xnu configd libdispatch libclosure launchd libiconv locale; + dyld Libsystem xnu configd libdispatch libclosure launchd libiconv + locale darwin-stubs; }; }; in with prevStage; stageFun 3 prevStage { @@ -403,7 +405,7 @@ in rec { in { inherit tools libraries; } // tools // libraries); darwin = super.darwin // rec { - inherit (darwin) dyld Libsystem libiconv locale; + inherit (darwin) dyld Libsystem libiconv locale darwin-stubs; CF = super.darwin.CF.override { inherit libxml2; @@ -502,7 +504,7 @@ in rec { inherit cc; darwin = super.darwin // { - inherit (prevStage.darwin) CF; + inherit (prevStage.darwin) CF darwin-stubs; xnu = super.darwin.xnu.override { inherit (prevStage) python3; }; }; }); diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index affb4ae92c1..91f694b40bb 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -41,6 +41,8 @@ in DarwinTools = callPackage ../os-specific/darwin/DarwinTools { }; + darwin-stubs = callPackage ../os-specific/darwin/darwin-stubs { }; + maloader = callPackage ../os-specific/darwin/maloader { inherit (darwin) opencflite; }; From fd33052999bd2bb30ed8751a38d4bade17d07d01 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 18 Sep 2020 17:10:03 +0900 Subject: [PATCH 06/18] darwin/print-reexports: nixpkgs-specific utility to inspect .tbd files Used during bootstrap to check that re-exported libraries are not dangling. --- .../apple-sdk/print-reexports/default.nix | 17 +++ .../darwin/apple-sdk/print-reexports/main.c | 129 ++++++++++++++++++ pkgs/top-level/darwin-packages.nix | 2 + 3 files changed, 148 insertions(+) create mode 100644 pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix create mode 100644 pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c diff --git a/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix b/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix new file mode 100644 index 00000000000..85e11096f06 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk/print-reexports/default.nix @@ -0,0 +1,17 @@ +{ stdenv, libyaml }: + +stdenv.mkDerivation { + name = "print-reexports"; + src = stdenv.lib.sourceFilesBySuffices ./. [".c"]; + + buildInputs = [ libyaml ]; + + buildPhase = '' + $CC -lyaml -o $name main.c + ''; + + installPhase = '' + mkdir -p $out/bin + mv $name $out/bin + ''; +} diff --git a/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c b/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c new file mode 100644 index 00000000000..7ad793eb425 --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c @@ -0,0 +1,129 @@ +#include +#include +#include + +static yaml_node_t *get_mapping_entry(yaml_document_t *document, yaml_node_t *mapping, const char *name) { + if (!mapping) { + fprintf(stderr, "get_mapping_entry: mapping is null\n"); + return NULL; + } + + for ( + yaml_node_pair_t *pair = mapping->data.mapping.pairs.start; + pair < mapping->data.mapping.pairs.top; + ++pair + ) { + yaml_node_t *key = yaml_document_get_node(document, pair->key); + + if (!key) { + fprintf(stderr, "get_mapping_entry: key (%i) is null\n", pair->key); + return NULL; + } + + if (key->type != YAML_SCALAR_NODE) { + fprintf(stderr, "get_mapping_entry: key is not a scalar\n"); + return NULL; + } + + if (strncmp((const char *)key->data.scalar.value, name, key->data.scalar.length) != 0) { + continue; + } + + return yaml_document_get_node(document, pair->value); + } + + return NULL; +} + +static int emit_reexports(yaml_document_t *document) { + yaml_node_t *root = yaml_document_get_root_node(document); + + yaml_node_t *exports = get_mapping_entry(document, root, "exports"); + + if (!exports) { + fprintf(stderr, "emit_reexports: no exports found\n"); + return 0; + } + + if (exports->type != YAML_SEQUENCE_NODE) { + fprintf(stderr, "emit_reexports, value is not a sequence\n"); + return 0; + } + + for ( + yaml_node_item_t *export = exports->data.sequence.items.start; + export < exports->data.sequence.items.top; + ++export + ) { + yaml_node_t *export_node = yaml_document_get_node(document, *export); + + yaml_node_t *reexports = get_mapping_entry(document, export_node, "re-exports"); + + if (!reexports) { + continue; + } + + for ( + yaml_node_item_t *reexport = reexports->data.sequence.items.start; + reexport < reexports->data.sequence.items.top; + ++reexport + ) { + yaml_node_t *val = yaml_document_get_node(document, *reexport); + + if (val->type != YAML_SCALAR_NODE) { + fprintf(stderr, "item is not a scalar\n"); + return 0; + } + + fwrite(val->data.scalar.value, val->data.scalar.length, 1, stdout); + putchar('\n'); + } + } + + return 1; +} + +int main(int argc, char **argv) { + int result = 0; + + if (argc != 2) { + fprintf(stderr, "Invalid usage\n"); + result = 2; + goto done; + } + + FILE *f = fopen(argv[1], "r"); + if (!f) { + perror("opening input file"); + result = errno; + goto done; + } + + yaml_parser_t yaml_parser; + if (!yaml_parser_initialize(&yaml_parser)) { + fprintf(stderr, "Failed to initialize yaml parser\n"); + result = 1; + goto err_file; + } + + yaml_parser_set_input_file(&yaml_parser, f); + + yaml_document_t yaml_document; + + if(!yaml_parser_load(&yaml_parser, &yaml_document)) { + fprintf(stderr, "Failed to load yaml file\n"); + result = 1; + goto err_yaml; + } + + emit_reexports(&yaml_document); + +err_yaml: + yaml_parser_delete(&yaml_parser); + +err_file: + fclose(f); + +done: + return result; +} diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index 91f694b40bb..ff94d8126e0 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -43,6 +43,8 @@ in darwin-stubs = callPackage ../os-specific/darwin/darwin-stubs { }; + print-reexports = callPackage ../os-specific/darwin/apple-sdk/print-reexports { }; + maloader = callPackage ../os-specific/darwin/maloader { inherit (darwin) opencflite; }; From b176ad95463252e9699ed1d397c3eebf787554c6 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 18 Sep 2020 17:10:47 +0900 Subject: [PATCH 07/18] darwin/Libsystem: use darwin-stubs --- .../Libsystem/default.nix | 56 ++++--------------- 1 file changed, 11 insertions(+), 45 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix index 99d67002803..24526f05f06 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix @@ -1,7 +1,7 @@ { stdenv, appleDerivation, cpio, xnu, Libc, Libm, libdispatch, cctools, Libinfo , dyld, Csu, architecture, libclosure, CarbonHeaders, ncurses, CommonCrypto , copyfile, removefile, libresolv, Libnotify, libplatform, libpthread -, mDNSResponder, launchd, libutil, hfs, darling }: +, mDNSResponder, launchd, libutil, hfs, darling, darwin-stubs }: appleDerivation { dontBuild = true; @@ -88,52 +88,18 @@ appleDerivation { # The startup object files cp ${Csu}/lib/* $out/lib - # We can't re-exported libsystem_c and libsystem_kernel directly, - # so we link against the central library here. - mkdir -p $out/lib/system - ld -macosx_version_min 10.7 -arch x86_64 -dylib \ - -o $out/lib/system/libsystem_c.dylib \ - /usr/lib/libSystem.dylib \ - -reexported_symbols_list ${./system_c_symbols} + cp -vr \ + ${darwin-stubs}/usr/lib/libSystem.B.tbd \ + ${darwin-stubs}/usr/lib/system \ + $out/lib - ld -macosx_version_min 10.7 -arch x86_64 -dylib \ - -o $out/lib/system/libsystem_kernel.dylib \ - /usr/lib/libSystem.dylib \ - -reexported_symbols_list ${./system_kernel_symbols} - - # The umbrella libSystem also exports some symbols, - # but we don't want to pull in everything from the other libraries. - ld -macosx_version_min 10.7 -arch x86_64 -dylib \ - -o $out/lib/libSystem_internal.dylib \ - /usr/lib/libSystem.dylib \ - -reexported_symbols_list ${./system_symbols} - - # We used to determine these impurely based on the host system, but then when we got some 10.12 Hydra boxes, - # one of them accidentally built this derivation, referenced libsystem_symptoms.dylib, which doesn't exist on - # 10.11, and then broke all subsequent builds on 10.11. By picking a 10.11 compatible subset of the libraries, - # we avoid scary impurity issues like that. - libs=$(cat ${./reexported_libraries} | 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 \ - -reexport_library $out/lib/libSystem_internal.dylib \ - $args - - ln -s libSystem.B.dylib $out/lib/libSystem.dylib + substituteInPlace $out/lib/libSystem.B.tbd \ + --replace "/usr/lib/system/" "$out/lib/system/" + ln -s libSystem.B.tbd $out/lib/libSystem.tbd # Set up links to pretend we work like a conventional unix (Apple's design, not mine!) 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 + ln -s libSystem.tbd $out/lib/lib$name.tbd done # This probably doesn't belong here, but we want to stay similar to glibc, which includes resolv internally... @@ -144,13 +110,13 @@ appleDerivation { chmod +w $out/lib/libresolv.9.dylib install_name_tool \ -id $out/lib/libresolv.9.dylib \ - -change "$resolv_libSystem" $out/lib/libSystem.dylib \ + -change "$resolv_libSystem" /usr/lib/libSystem.dylib \ $out/lib/libresolv.9.dylib ln -s libresolv.9.dylib $out/lib/libresolv.dylib ''; meta = with stdenv.lib; { - description = "The Mac OS libc/libSystem (impure symlinks to binaries with pure headers)"; + description = "The Mac OS libc/libSystem (tapi library with pure headers)"; maintainers = with maintainers; [ copumpkin gridaphobe ]; platforms = platforms.darwin; license = licenses.apsl20; From 03988a5fec4b9fc09e7e868a06116f3d9215b393 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 18 Sep 2020 17:11:11 +0900 Subject: [PATCH 08/18] darwin/Security: use darwin-stubs --- .../apple-source-releases/Security/boot.nix | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix b/pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix index e04142b8b11..b819057f0c1 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/Security/boot.nix @@ -1,4 +1,4 @@ -{ appleDerivation }: +{ appleDerivation, darwin-stubs }: appleDerivation { phases = [ "unpackPhase" "installPhase" ]; @@ -12,14 +12,15 @@ appleDerivation { ]; installPhase = '' - ###### IMPURITIES mkdir -p $out/Library/Frameworks/Security.framework - pushd $out/Library/Frameworks/Security.framework - ln -s /System/Library/Frameworks/Security.framework/Security - ln -s /System/Library/Frameworks/Security.framework/Resources - ln -s /System/Library/Frameworks/Security.framework/PlugIns - ln -s /System/Library/Frameworks/Security.framework/XPCServices - popd + + ###### IMPURITIES + ln -s /System/Library/Frameworks/Security.framework/{Resources,Plugins,XPCServices} \ + $out/Library/Frameworks/Security.framework + + ###### STUBS + cp ${darwin-stubs}/System/Library/Frameworks/Security.framework/Versions/A/Security.tbd \ + $out/Library/Frameworks/Security.framework ###### HEADERS From 193c91233c048fcea30f8630daa1a65582c19cb4 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 18 Sep 2020 17:11:21 +0900 Subject: [PATCH 09/18] darwin/IOKit: use darwin-stubs --- .../apple-source-releases/IOKit/default.nix | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/IOKit/default.nix b/pkgs/os-specific/darwin/apple-source-releases/IOKit/default.nix index 4b82209f176..a945409ed7a 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/IOKit/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/IOKit/default.nix @@ -1,4 +1,4 @@ -{ stdenv, appleDerivation, IOKitSrcs, xnu }: +{ stdenv, appleDerivation, IOKitSrcs, xnu, darwin-stubs }: # Someday it'll make sense to split these out into their own packages, but today is not that day. appleDerivation { @@ -14,12 +14,15 @@ appleDerivation { ]; installPhase = '' - ###### IMPURITIES mkdir -p $out/Library/Frameworks/IOKit.framework - pushd $out/Library/Frameworks/IOKit.framework - ln -s /System/Library/Frameworks/IOKit.framework/IOKit - ln -s /System/Library/Frameworks/IOKit.framework/Resources - popd + + ###### IMPURITIES + ln -s /System/Library/Frameworks/IOKit.framework/Resources \ + $out/Library/Frameworks/IOKit.framework + + ###### STUBS + cp ${darwin-stubs}/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit.tbd \ + $out/Library/Frameworks/IOKit.framework ###### HEADERS From 8e6d830423aa6bb70fadd9ee46505ff7e5d52ae7 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 18 Sep 2020 17:12:07 +0900 Subject: [PATCH 10/18] darwin/objc4: use darwin-stubs --- .../darwin/apple-source-releases/objc4/default.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix b/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix index a7cedaaea11..2fc4afa77d9 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/objc4/default.nix @@ -1,4 +1,4 @@ -{ appleDerivation }: +{ appleDerivation, darwin-stubs }: appleDerivation { phases = [ "unpackPhase" "installPhase" ]; @@ -14,7 +14,8 @@ appleDerivation { installPhase = '' mkdir -p $out/include/objc $out/lib - ln -s /usr/lib/libobjc.dylib $out/lib/libobjc.dylib + cp ${darwin-stubs}/usr/lib/libobjc.A.tbd $out/lib/libobjc.A.tbd + ln -s libobjc.A.tbd $out/lib/libobjc.tbd cp runtime/OldClasses.subproj/List.h $out/include/objc/List.h cp runtime/NSObjCRuntime.h $out/include/objc/NSObjCRuntime.h cp runtime/NSObject.h $out/include/objc/NSObject.h From 3456ef6f300d3882890d09f1fd91d39baaf986c4 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Fri, 18 Sep 2020 17:12:43 +0900 Subject: [PATCH 11/18] darwin/apple-sdk: use darwin stubs --- .../darwin/apple-sdk/cf-setup-hook.sh | 2 +- pkgs/os-specific/darwin/apple-sdk/default.nix | 108 +++++++-- .../darwin/apple-sdk/frameworks.nix | 228 +++++++++--------- pkgs/top-level/darwin-packages.nix | 4 +- 4 files changed, 211 insertions(+), 131 deletions(-) diff --git a/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh b/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh index 86c241cd0f5..bbf9625e655 100644 --- a/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh +++ b/pkgs/os-specific/darwin/apple-sdk/cf-setup-hook.sh @@ -3,7 +3,7 @@ linkSystemCoreFoundationFramework() { # gross! many symbols (such as _OBJC_CLASS_$_NSArray) are defined in system CF, but not # in the opensource release # if the package needs private headers, we assume they also want to link with system CF - NIX_LDFLAGS+=" /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" + NIX_LDFLAGS+=" @out@/Library/Frameworks/CoreFoundation.framework/CoreFoundation" } preConfigureHooks+=(linkSystemCoreFoundationFramework) diff --git a/pkgs/os-specific/darwin/apple-sdk/default.nix b/pkgs/os-specific/darwin/apple-sdk/default.nix index 89c13d0b92d..dbfd3b05fa5 100644 --- a/pkgs/os-specific/darwin/apple-sdk/default.nix +++ b/pkgs/os-specific/darwin/apple-sdk/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchurl, xar, cpio, pkgs, python3, pbzx, lib }: +{ stdenv, fetchurl, xar, cpio, pkgs, python3, pbzx, lib, darwin-stubs, print-reexports }: let version = "10.12"; in @@ -42,7 +42,12 @@ let rmdir System pushd lib - ln -s -L /usr/lib/libcups*.dylib . + cp ${darwin-stubs}/usr/lib/libcups*.tbd . + ln -s libcups.2.tbd libcups.tbd + ln -s libcupscgi.1.tbd libcupscgi.tbd + ln -s libcupsimage.2.tbd libcupsimage.tbd + ln -s libcupsmime.1.tbd libcupsmime.tbd + ln -s libcupsppdc.1.tbd libcupsppdc.tbd popd ''; @@ -53,6 +58,12 @@ let }; }; + mkFrameworkSubs = name: deps: + let + deps' = deps // { "${name}" = placeholder "out"; }; + substArgs = lib.concatMap (x: [ "--subst-var-by" x deps'."${x}" ]) (lib.attrNames deps'); + in lib.escapeShellArgs substArgs; + framework = name: deps: stdenv.mkDerivation { name = "apple-framework-${name}"; @@ -63,11 +74,14 @@ let disallowedRequisites = [ sdk ]; + nativeBuildInputs = [ print-reexports ]; + + extraTBDFiles = []; + installPhase = '' linkFramework() { local path="$1" local nested_path="$1" - local dest="$out/Library/Frameworks/$path" if [ "$path" == "JavaNativeFoundation.framework" ]; then local nested_path="JavaVM.framework/Versions/A/Frameworks/JavaNativeFoundation.framework" fi @@ -80,21 +94,28 @@ let current=A fi - mkdir -p "$dest" - pushd "$dest" >/dev/null + local dest="$out/Library/Frameworks/$path" - # Keep track of if this is a child or a child rescue as with - # ApplicationServices in the 10.9 SDK - local isChild=0 + mkdir -p "$dest/Versions/$current" + pushd "$dest/Versions/$current" >/dev/null if [ -d "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" ]; then - isChild=1 cp -R "${sdk.out}/Library/Frameworks/$nested_path/Versions/$current/Headers" . elif [ -d "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" ]; then current="$(readlink "/System/Library/Frameworks/$name.framework/Versions/Current")" cp -R "${sdk.out}/Library/Frameworks/$name.framework/Versions/$current/Headers" . fi - ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/$name" + + local tbd_source=${darwin-stubs}/System/Library/Frameworks/$nested_path/Versions/$current + if [ "${name}" != "Kernel" ]; then + cp -v $tbd_source/*.tbd . + fi + + if [ -d "$tbd_source/Libraries" ]; then + mkdir Libraries + cp -v $tbd_source/Libraries/*.tbd Libraries/ + fi + ln -s -L "/System/Library/Frameworks/$nested_path/Versions/$current/Resources" if [ -f "/System/Library/Frameworks/$nested_path/module.map" ]; then @@ -110,17 +131,45 @@ let linkFramework "$childpath" done - if [ -d "$dest/Versions/$current" ]; then - mv $dest/Versions/$current/* . - fi + pushd ../.. >/dev/null + ln -s "$current" Versions/Current + ln -s Versions/Current/* . + popd >/dev/null popd >/dev/null } linkFramework "${name}.framework" + + # linkFramework is recursive, the rest of the processing is not. + + local tbd_source=${darwin-stubs}/System/Library/Frameworks/${name}.framework + for tbd in $extraTBDFiles; do + local tbd_dest_dir=$out/Library/Frameworks/${name}.framework/$(dirname "$tbd") + mkdir -p "$tbd_dest_dir" + cp -v "$tbd_source/$tbd" "$tbd_dest_dir" + done + + # Fix and check tbd re-export references + find $out -name '*.tbd' | while read tbd; do + echo "Fixing re-exports in $tbd" + substituteInPlace "$tbd" ${mkFrameworkSubs name deps} + + echo "Checking re-exports in $tbd" + print-reexports "$tbd" | while read target; do + local expected="''${target%.dylib}.tbd" + if ! [ -e "$expected" ]; then + echo -e "Re-export missing:\n\t$target\n\t(expected $expected)" + echo -e "While processing\n\t$tbd" + exit 1 + else + echo "Re-exported target $target ok" + fi + done + done ''; - propagatedBuildInputs = deps; + propagatedBuildInputs = builtins.attrValues deps; # don't use pure CF for dylibs that depend on frameworks setupHook = ./framework-setup-hook.sh; @@ -139,6 +188,17 @@ let platforms = platforms.darwin; }; }; + + tbdOnlyFramework = name: { private ? true }: stdenv.mkDerivation { + name = "apple-framework-${name}"; + dontUnpack = true; + installPhase = '' + mkdir -p $out/Library/Frameworks/ + cp -r ${darwin-stubs}/System/Library/${lib.optionalString private "Private"}Frameworks/${name}.framework \ + $out/Library/Frameworks + # NOTE there's no re-export checking here, this is probably wrong + ''; + }; in rec { libs = { xpc = stdenv.mkDerivation { @@ -168,7 +228,8 @@ in rec { installPhase = '' mkdir -p $out/include $out/lib ln -s "${lib.getDev sdk}/include/Xplugin.h" $out/include/Xplugin.h - ln -s "/usr/lib/libXplugin.1.dylib" $out/lib/libXplugin.dylib + cp ${darwin-stubs}/usr/lib/libXplugin.1.tbd $out/lib + ln -s libXplugin.1.tbd $out/lib/libXplugin.tbd ''; }; @@ -193,6 +254,10 @@ in rec { ]; }); + Carbon = stdenv.lib.overrideDerivation super.Carbon (drv: { + extraTBDFiles = [ "Versions/A/Frameworks/HTMLRendering.framework/Versions/A/HTMLRendering.tbd" ]; + }); + CoreFoundation = stdenv.lib.overrideDerivation super.CoreFoundation (drv: { setupHook = ./cf-setup-hook.sh; }); @@ -210,6 +275,10 @@ in rec { setupHook = ./private-frameworks-setup-hook.sh; }); + IMServicePlugIn = stdenv.lib.overrideDerivation super.IMServicePlugIn (drv: { + extraTBDFiles = [ "Versions/A/Frameworks/IMServicePlugInSupport.framework/Versions/A/IMServicePlugInSupport.tbd" ]; + }); + Security = stdenv.lib.overrideDerivation super.Security (drv: { setupHook = ./security-setup-hook.sh; }); @@ -228,7 +297,14 @@ in rec { cp ${lib.getDev sdk}/include/simd/*.h $out/include/simd/ ''; }); - }; + + WebKit = stdenv.lib.overrideDerivation super.WebKit (drv: { + extraTBDFiles = [ + "Versions/A/Frameworks/WebCore.framework/Versions/A/WebCore.tbd" + "Versions/A/Frameworks/WebKitLegacy.framework/Versions/A/WebKitLegacy.tbd" + ]; + }); + } // lib.genAttrs [ "ContactsPersistence" "UIFoundation" "GameCenter" ] (x: tbdOnlyFramework x {}); bareFrameworks = stdenv.lib.mapAttrs framework (import ./frameworks.nix { inherit frameworks libs; diff --git a/pkgs/os-specific/darwin/apple-sdk/frameworks.nix b/pkgs/os-specific/darwin/apple-sdk/frameworks.nix index 02e2421f347..bf0b134773d 100644 --- a/pkgs/os-specific/darwin/apple-sdk/frameworks.nix +++ b/pkgs/os-specific/darwin/apple-sdk/frameworks.nix @@ -5,123 +5,125 @@ { frameworks, libs, libobjc, }: with frameworks; with libs; { - AGL = [ Carbon OpenGL ]; - AVFoundation = [ ApplicationServices CoreGraphics ]; - AVKit = []; - Accounts = []; - AddressBook = [ Carbon ]; - AppKit = [ AudioToolbox AudioUnit Foundation QuartzCore ]; - AppKitScripting = []; - AppleScriptKit = []; - AppleScriptObjC = []; - AudioToolbox = [ CoreAudio CoreMIDI ]; - AudioUnit = [ AudioToolbox Carbon CoreAudio ]; - AudioVideoBridging = [ Foundation ]; - Automator = []; - CFNetwork = []; - CalendarStore = []; - Cocoa = [ AppKit ]; - Collaboration = []; + AGL = { inherit Carbon OpenGL; }; + AVFoundation = { inherit ApplicationServices CoreGraphics; }; + AVKit = {}; + Accounts = {}; + AddressBook = { inherit libobjc Carbon ContactsPersistence; }; + AppKit = { inherit ApplicationServices AudioToolbox AudioUnit Foundation QuartzCore UIFoundation; }; + AppKitScripting = {}; + AppleScriptKit = {}; + AppleScriptObjC = {}; + AudioToolbox = { inherit CoreAudio CoreMIDI; }; + AudioUnit = { inherit AudioToolbox Carbon CoreAudio; }; + AudioVideoBridging = { inherit Foundation; }; + Automator = {}; + CFNetwork = {}; + CalendarStore = {}; + Cocoa = { inherit AppKit CoreData; }; + Collaboration = {}; # Impure version of CoreFoundation, this should not be used unless another # framework includes headers that are not available in the pure version. - CoreFoundation = []; - CoreAudio = [ IOKit ]; - CoreAudioKit = [ AudioUnit ]; - CoreData = []; - CoreGraphics = [ Accelerate IOKit IOSurface SystemConfiguration ]; - CoreImage = []; - CoreLocation = []; - CoreMIDI = []; - CoreMIDIServer = []; - CoreMedia = [ ApplicationServices AudioToolbox AudioUnit CoreAudio CoreGraphics CoreVideo ]; - CoreMediaIO = [ CoreMedia ]; - CoreText = [ CoreGraphics ]; - CoreVideo = [ ApplicationServices CoreGraphics IOSurface OpenGL ]; - CoreWLAN = [ SecurityFoundation ]; - DVDPlayback = []; - DirectoryService = []; - DiscRecording = [ CoreServices IOKit ]; - DiscRecordingUI = []; - DiskArbitration = [ IOKit ]; - EventKit = []; - ExceptionHandling = []; - FWAUserLib = []; - ForceFeedback = [ IOKit ]; - Foundation = [ libobjc CoreFoundation Security ApplicationServices SystemConfiguration ]; - GLKit = []; - GLUT = [ OpenGL ]; - GSS = []; - GameController = []; - GameKit = [ Foundation ]; - Hypervisor = []; - ICADevices = [ Carbon IOBluetooth ]; - IMServicePlugIn = []; - IOBluetoothUI = [ IOBluetooth ]; - IOKit = []; - IOSurface = [ IOKit xpc ]; - ImageCaptureCore = []; - ImageIO = [ CoreGraphics ]; - InputMethodKit = [ Carbon ]; - InstallerPlugins = []; - InstantMessage = []; - JavaFrameEmbedding = []; - JavaNativeFoundation = []; - JavaRuntimeSupport = []; - JavaScriptCore = []; - Kerberos = []; - Kernel = [ IOKit ]; - LDAP = []; - LatentSemanticMapping = [ Carbon ]; - LocalAuthentication = []; - MapKit = []; - MediaAccessibility = [ CoreGraphics CoreText QuartzCore ]; - MediaPlayer = []; - MediaToolbox = [ AudioToolbox AudioUnit CoreMedia ]; - Metal = []; - MetalKit = [ ModelIO Metal ]; - ModelIO = [ ]; - NetFS = []; - OSAKit = [ Carbon ]; - OpenAL = []; - OpenCL = [ IOSurface OpenGL ]; - OpenGL = []; - PCSC = [ CoreData ]; - PreferencePanes = []; - PubSub = []; - QTKit = [ CoreMediaIO CoreMedia MediaToolbox QuickTime VideoToolbox ]; - QuickLook = [ ApplicationServices ]; - SceneKit = []; - ScreenSaver = []; - Scripting = []; - ScriptingBridge = []; - Security = [ IOKit ]; - SecurityFoundation = []; - SecurityInterface = [ Security ]; - ServiceManagement = [ Security ]; - Social = []; - SpriteKit = []; - StoreKit = []; - SyncServices = []; - SystemConfiguration = [ Security ]; - TWAIN = [ Carbon ]; - Tcl = []; - VideoDecodeAcceleration = [ CoreVideo ]; - VideoToolbox = [ CoreMedia CoreVideo ]; - WebKit = [ ApplicationServices Carbon JavaScriptCore OpenGL ]; + CoreFoundation = {}; + CoreAudio = { inherit IOKit; }; + CoreAudioKit = { inherit AudioUnit; }; + CoreData = {}; + CoreGraphics = { inherit Accelerate IOKit IOSurface SystemConfiguration; }; + CoreImage = {}; + CoreLocation = {}; + CoreMIDI = {}; + CoreMIDIServer = { inherit CoreMIDI; }; + CoreMedia = { inherit ApplicationServices AudioToolbox AudioUnit CoreAudio CoreGraphics CoreVideo; }; + CoreMediaIO = { inherit CoreMedia; }; + CoreText = { inherit CoreGraphics; }; + CoreVideo = { inherit ApplicationServices CoreGraphics IOSurface OpenGL; }; + CoreWLAN = { inherit SecurityFoundation; }; + DVDPlayback = {}; + DirectoryService = {}; + DiscRecording = { inherit libobjc CoreServices IOKit; }; + DiscRecordingUI = {}; + DiskArbitration = { inherit IOKit; }; + EventKit = {}; + ExceptionHandling = {}; + FWAUserLib = {}; + ForceFeedback = { inherit IOKit; }; + Foundation = { inherit libobjc CoreFoundation Security ApplicationServices SystemConfiguration; }; + GLKit = {}; + GLUT = { inherit OpenGL; }; + GSS = {}; + GameCenter = {}; + GameController = {}; + GameKit = { inherit Cocoa Foundation GameCenter GameController GameplayKit Metal MetalKit ModelIO SceneKit SpriteKit; }; + GameplayKit = {}; + Hypervisor = {}; + ICADevices = { inherit libobjc Carbon IOBluetooth; }; + IMServicePlugIn = {}; + IOBluetoothUI = { inherit IOBluetooth; }; + IOKit = {}; + IOSurface = { inherit IOKit xpc; }; + ImageCaptureCore = {}; + ImageIO = { inherit CoreGraphics; }; + InputMethodKit = { inherit Carbon; }; + InstallerPlugins = {}; + InstantMessage = {}; + JavaFrameEmbedding = {}; + JavaNativeFoundation = {}; + JavaRuntimeSupport = {}; + JavaScriptCore = { inherit libobjc; }; + Kerberos = {}; + Kernel = { inherit IOKit; }; + LDAP = {}; + LatentSemanticMapping = { inherit Carbon; }; + LocalAuthentication = {}; + MapKit = {}; + MediaAccessibility = { inherit CoreGraphics CoreText QuartzCore; }; + MediaPlayer = {}; + MediaToolbox = { inherit AudioToolbox AudioUnit CoreMedia; }; + Metal = {}; + MetalKit = { inherit ModelIO Metal; }; + ModelIO = {}; + NetFS = {}; + OSAKit = { inherit Carbon; }; + OpenAL = {}; + OpenCL = { inherit IOSurface OpenGL; }; + OpenGL = {}; + PCSC = { inherit CoreData; }; + PreferencePanes = {}; + PubSub = {}; + QTKit = { inherit CoreMediaIO CoreMedia MediaToolbox QuickTime VideoToolbox; }; + QuickLook = { inherit ApplicationServices; }; + SceneKit = {}; + ScreenSaver = {}; + Scripting = {}; + ScriptingBridge = {}; + Security = { inherit IOKit; }; + SecurityFoundation = {}; + SecurityInterface = { inherit Security SecurityFoundation; }; + ServiceManagement = { inherit Security; }; + Social = {}; + SpriteKit = {}; + StoreKit = {}; + SyncServices = {}; + SystemConfiguration = { inherit Security; }; + TWAIN = { inherit Carbon; }; + Tcl = {}; + VideoDecodeAcceleration = { inherit CoreVideo; }; + VideoToolbox = { inherit CoreMedia CoreVideo; }; + WebKit = { inherit libobjc ApplicationServices Carbon JavaScriptCore OpenGL; }; # Umbrellas - Accelerate = [ CoreWLAN IOBluetooth ]; - ApplicationServices = [ CoreServices CoreText ImageIO ]; - Carbon = [ ApplicationServices CoreServices Foundation IOKit Security QuartzCore ]; - CoreBluetooth = []; + Accelerate = { inherit CoreWLAN IOBluetooth; }; + ApplicationServices = { inherit CoreGraphics CoreServices CoreText ImageIO; }; + Carbon = { inherit libobjc ApplicationServices CoreServices Foundation IOKit Security QuartzCore; }; + CoreBluetooth = {}; # TODO: figure out which part of the umbrella depends on CoreFoundation and move it there. - CoreServices = [ CFNetwork CoreFoundation CoreAudio CoreData DiskArbitration Security NetFS OpenDirectory ServiceManagement ]; - IOBluetooth = [ IOKit ]; - JavaVM = []; - OpenDirectory = []; - Quartz = [ QuickLook QTKit ]; - QuartzCore = [ ApplicationServices CoreVideo OpenCL CoreImage Metal ]; - QuickTime = [ ApplicationServices AudioUnit Carbon CoreAudio CoreServices OpenGL QuartzCore ]; + CoreServices = { inherit CFNetwork CoreFoundation CoreAudio CoreData DiskArbitration Security NetFS OpenDirectory ServiceManagement; }; + IOBluetooth = { inherit CoreBluetooth IOKit; }; + JavaVM = {}; + OpenDirectory = {}; + Quartz = { inherit QuartzCore QuickLook QTKit; }; + QuartzCore = { inherit libobjc ApplicationServices CoreVideo OpenCL CoreImage Metal; }; + QuickTime = { inherit ApplicationServices AudioUnit Carbon CoreAudio CoreServices OpenGL QuartzCore; }; - vmnet = []; + vmnet = {}; } diff --git a/pkgs/top-level/darwin-packages.nix b/pkgs/top-level/darwin-packages.nix index ff94d8126e0..6fafe09438c 100644 --- a/pkgs/top-level/darwin-packages.nix +++ b/pkgs/top-level/darwin-packages.nix @@ -14,7 +14,9 @@ in extraBuildInputs = []; }; - apple_sdk = callPackage ../os-specific/darwin/apple-sdk { }; + apple_sdk = callPackage ../os-specific/darwin/apple-sdk { + inherit (darwin) darwin-stubs print-reexports; + }; binutils-unwrapped = callPackage ../os-specific/darwin/binutils { inherit (darwin) cctools; From f6c54e8f08b356ccbd098f0cd349f7f55eec9912 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Wed, 16 Sep 2020 20:28:32 +0900 Subject: [PATCH 12/18] qt512.qtbase: patch framework detection to support tbd frameworks --- pkgs/development/libraries/qt-5/5.12/default.nix | 4 ++++ .../0015-qtbase-tbd-frameworks.patch | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 pkgs/development/libraries/qt-5/5.12/qtbase.patch.d/0015-qtbase-tbd-frameworks.patch diff --git a/pkgs/development/libraries/qt-5/5.12/default.nix b/pkgs/development/libraries/qt-5/5.12/default.nix index fcceb6d6cf2..95da38206e4 100644 --- a/pkgs/development/libraries/qt-5/5.12/default.nix +++ b/pkgs/development/libraries/qt-5/5.12/default.nix @@ -55,6 +55,10 @@ let ./qtbase.patch.d/0001-qtbase-mkspecs-mac.patch ./qtbase.patch.d/0002-qtbase-mac.patch ./qtbase.patch.d/0013-define-kiosurfacesuccess.patch + + # Patch framework detection to support X.framework/X.tbd, + # extending the current support for X.framework/X. + ./qtbase.patch.d/0015-qtbase-tbd-frameworks.patch ] ++ [ ./qtbase.patch.d/0003-qtbase-mkspecs.patch diff --git a/pkgs/development/libraries/qt-5/5.12/qtbase.patch.d/0015-qtbase-tbd-frameworks.patch b/pkgs/development/libraries/qt-5/5.12/qtbase.patch.d/0015-qtbase-tbd-frameworks.patch new file mode 100644 index 00000000000..8a5939978a6 --- /dev/null +++ b/pkgs/development/libraries/qt-5/5.12/qtbase.patch.d/0015-qtbase-tbd-frameworks.patch @@ -0,0 +1,15 @@ +diff --git a/src/gui/Qt5GuiConfigExtras.cmake.in b/src/gui/Qt5GuiConfigExtras.cmake.in +index 84dbbfebd4..615bfed124 100644 +--- a/src/gui/Qt5GuiConfigExtras.cmake.in ++++ b/src/gui/Qt5GuiConfigExtras.cmake.in +@@ -119,6 +119,10 @@ macro(_qt5gui_find_extra_libs Name Libs LibDir IncDirs) + if (NOT EXISTS "${Qt5Gui_${_cmake_lib_name}_LIBRARY}") + set(Qt5Gui_${_cmake_lib_name}_LIBRARY) + endif() ++ set(Qt5Gui_${_cmake_lib_name}_LIBRARY "${Qt5Gui_${_cmake_lib_name}_LIBRARY}/${_lib}.tbd") ++ if (NOT EXISTS "${Qt5Gui_${_cmake_lib_name}_LIBRARY}") ++ set(Qt5Gui_${_cmake_lib_name}_LIBRARY) ++ endif() + !!ENDIF + if (NOT Qt5Gui_${_cmake_lib_name}_LIBRARY) + # The above find_library call doesn\'t work for finding From 1f52024720e48ade2745b91ce19fbd2e300ef39e Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 12 Nov 2020 16:18:13 +0900 Subject: [PATCH 13/18] qt514.qtbase: patch framework detection to support tbd frameworks --- pkgs/development/libraries/qt-5/5.14/default.nix | 4 ++++ .../0012-qtbase-tbd-frameworks.patch | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 pkgs/development/libraries/qt-5/5.14/qtbase.patch.d/0012-qtbase-tbd-frameworks.patch diff --git a/pkgs/development/libraries/qt-5/5.14/default.nix b/pkgs/development/libraries/qt-5/5.14/default.nix index 469157a5f72..7bc9b5f19bd 100644 --- a/pkgs/development/libraries/qt-5/5.14/default.nix +++ b/pkgs/development/libraries/qt-5/5.14/default.nix @@ -55,6 +55,10 @@ let optionals stdenv.isDarwin [ ./qtbase.patch.d/0001-qtbase-mkspecs-mac.patch ./qtbase.patch.d/0002-qtbase-mac.patch + + # Patch framework detection to support X.framework/X.tbd, + # extending the current support for X.framework/X. + ./qtbase.patch.d/0012-qtbase-tbd-frameworks.patch ] ++ [ ./qtbase.patch.d/0003-qtbase-mkspecs.patch diff --git a/pkgs/development/libraries/qt-5/5.14/qtbase.patch.d/0012-qtbase-tbd-frameworks.patch b/pkgs/development/libraries/qt-5/5.14/qtbase.patch.d/0012-qtbase-tbd-frameworks.patch new file mode 100644 index 00000000000..8a5939978a6 --- /dev/null +++ b/pkgs/development/libraries/qt-5/5.14/qtbase.patch.d/0012-qtbase-tbd-frameworks.patch @@ -0,0 +1,15 @@ +diff --git a/src/gui/Qt5GuiConfigExtras.cmake.in b/src/gui/Qt5GuiConfigExtras.cmake.in +index 84dbbfebd4..615bfed124 100644 +--- a/src/gui/Qt5GuiConfigExtras.cmake.in ++++ b/src/gui/Qt5GuiConfigExtras.cmake.in +@@ -119,6 +119,10 @@ macro(_qt5gui_find_extra_libs Name Libs LibDir IncDirs) + if (NOT EXISTS "${Qt5Gui_${_cmake_lib_name}_LIBRARY}") + set(Qt5Gui_${_cmake_lib_name}_LIBRARY) + endif() ++ set(Qt5Gui_${_cmake_lib_name}_LIBRARY "${Qt5Gui_${_cmake_lib_name}_LIBRARY}/${_lib}.tbd") ++ if (NOT EXISTS "${Qt5Gui_${_cmake_lib_name}_LIBRARY}") ++ set(Qt5Gui_${_cmake_lib_name}_LIBRARY) ++ endif() + !!ENDIF + if (NOT Qt5Gui_${_cmake_lib_name}_LIBRARY) + # The above find_library call doesn\'t work for finding From 16075a712c867d2ecc74d0ccfdcf831b2c7dd9b5 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 12 Nov 2020 16:18:37 +0900 Subject: [PATCH 14/18] qt515.qtbase: patch framework detection to support tbd frameworks --- pkgs/development/libraries/qt-5/5.15/default.nix | 4 ++++ .../0012-qtbase-tbd-frameworks.patch | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 pkgs/development/libraries/qt-5/5.15/qtbase.patch.d/0012-qtbase-tbd-frameworks.patch diff --git a/pkgs/development/libraries/qt-5/5.15/default.nix b/pkgs/development/libraries/qt-5/5.15/default.nix index 1a90c610a5b..22fb9392d6d 100644 --- a/pkgs/development/libraries/qt-5/5.15/default.nix +++ b/pkgs/development/libraries/qt-5/5.15/default.nix @@ -55,6 +55,10 @@ let optionals stdenv.isDarwin [ ./qtbase.patch.d/0001-qtbase-mkspecs-mac.patch ./qtbase.patch.d/0002-qtbase-mac.patch + + # Patch framework detection to support X.framework/X.tbd, + # extending the current support for X.framework/X. + ./qtbase.patch.d/0012-qtbase-tbd-frameworks.patch ] ++ [ ./qtbase.patch.d/0003-qtbase-mkspecs.patch diff --git a/pkgs/development/libraries/qt-5/5.15/qtbase.patch.d/0012-qtbase-tbd-frameworks.patch b/pkgs/development/libraries/qt-5/5.15/qtbase.patch.d/0012-qtbase-tbd-frameworks.patch new file mode 100644 index 00000000000..8a5939978a6 --- /dev/null +++ b/pkgs/development/libraries/qt-5/5.15/qtbase.patch.d/0012-qtbase-tbd-frameworks.patch @@ -0,0 +1,15 @@ +diff --git a/src/gui/Qt5GuiConfigExtras.cmake.in b/src/gui/Qt5GuiConfigExtras.cmake.in +index 84dbbfebd4..615bfed124 100644 +--- a/src/gui/Qt5GuiConfigExtras.cmake.in ++++ b/src/gui/Qt5GuiConfigExtras.cmake.in +@@ -119,6 +119,10 @@ macro(_qt5gui_find_extra_libs Name Libs LibDir IncDirs) + if (NOT EXISTS "${Qt5Gui_${_cmake_lib_name}_LIBRARY}") + set(Qt5Gui_${_cmake_lib_name}_LIBRARY) + endif() ++ set(Qt5Gui_${_cmake_lib_name}_LIBRARY "${Qt5Gui_${_cmake_lib_name}_LIBRARY}/${_lib}.tbd") ++ if (NOT EXISTS "${Qt5Gui_${_cmake_lib_name}_LIBRARY}") ++ set(Qt5Gui_${_cmake_lib_name}_LIBRARY) ++ endif() + !!ENDIF + if (NOT Qt5Gui_${_cmake_lib_name}_LIBRARY) + # The above find_library call doesn\'t work for finding From 47c770e0e603f5db7dc3daafcb2dba14fd2300bc Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Wed, 9 Sep 2020 09:50:35 +0900 Subject: [PATCH 15/18] darwin/make-bootstrap-tools: remove references to old libSystem --- pkgs/stdenv/darwin/make-bootstrap-tools.nix | 53 ++++++--------------- 1 file changed, 15 insertions(+), 38 deletions(-) diff --git a/pkgs/stdenv/darwin/make-bootstrap-tools.nix b/pkgs/stdenv/darwin/make-bootstrap-tools.nix index 31e12963937..1243b96e505 100644 --- a/pkgs/stdenv/darwin/make-bootstrap-tools.nix +++ b/pkgs/stdenv/darwin/make-bootstrap-tools.nix @@ -28,11 +28,8 @@ in rec { buildCommand = '' mkdir -p $out/bin $out/lib $out/lib/system - # We're not going to bundle the actual libSystem.dylib; instead we reconstruct it on - # the other side. See the notes in stdenv/darwin/default.nix for more information. - # We also need the .o files for various low-level boot stuff. + # Copy libSystem's .o files for various low-level boot stuff. cp -d ${darwin.Libsystem}/lib/*.o $out/lib - cp -d ${darwin.Libsystem}/lib/system/*.dylib $out/lib/system # Resolv is actually a link to another package, so let's copy it properly cp -L ${darwin.Libsystem}/lib/libresolv.9.dylib $out/lib @@ -208,39 +205,6 @@ in rec { 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 @@ -309,7 +273,20 @@ in rec { ${build}/on-server/sh -c 'echo Hello World' - export flags="-idirafter ${unpack}/include-Libsystem --sysroot=${unpack} -L${unpack}/lib" + # This approximates a bootstrap version of libSystem can that be + # assembled via fetchurl. Adapted from main libSystem expression. + mkdir libSystem-boot + cp -vr \ + ${darwin.darwin-stubs}/usr/lib/libSystem.B.tbd \ + ${darwin.darwin-stubs}/usr/lib/system \ + libSystem-boot + + substituteInPlace libSystem-boot/libSystem.B.tbd \ + --replace "/usr/lib/system/" "$PWD/libSystem-boot/system/" + ln -s libSystem.B.tbd libSystem-boot/libSystem.tbd + # End of bootstrap libSystem + + export flags="-idirafter ${unpack}/include-Libsystem --sysroot=${unpack} -L${unpack}/lib -L$PWD/libSystem-boot" export CPP="clang -E $flags" export CC="clang $flags -Wl,-rpath,${unpack}/lib -Wl,-v -Wl,-sdk_version,10.10" From 70f3863540a8c6350b92b93cb5c13a66e54200d2 Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Tue, 10 Nov 2020 11:23:49 +0900 Subject: [PATCH 16/18] trash-cli: remove reference to libSystem.dylib proxy on darwin --- pkgs/tools/misc/trash-cli/default.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkgs/tools/misc/trash-cli/default.nix b/pkgs/tools/misc/trash-cli/default.nix index 141cceff24d..33c8792d418 100644 --- a/pkgs/tools/misc/trash-cli/default.nix +++ b/pkgs/tools/misc/trash-cli/default.nix @@ -16,8 +16,10 @@ python3Packages.buildPythonApplication rec { (substituteAll { src = ./nix-paths.patch; df = "${coreutils}/bin/df"; - libc = let ext = if stdenv.isDarwin then ".dylib" else ".so.6"; - in "${stdenv.cc.libc}/lib/libc${ext}"; + libc = + if stdenv.hostPlatform.isDarwin + then "/usr/lib/libSystem.dylib" + else "${stdenv.cc.libc}/lib/libc.so.6"; }) # Fix build on Python 3.6. From 7e49fb6592a6af157d861d07315b683d5724f96e Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 12 Nov 2020 16:50:06 +0900 Subject: [PATCH 17/18] darwin/apple-sdk: explain why Kernel.framework has no .tbd file --- pkgs/os-specific/darwin/apple-sdk/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/os-specific/darwin/apple-sdk/default.nix b/pkgs/os-specific/darwin/apple-sdk/default.nix index dbfd3b05fa5..97523cf15a8 100644 --- a/pkgs/os-specific/darwin/apple-sdk/default.nix +++ b/pkgs/os-specific/darwin/apple-sdk/default.nix @@ -108,6 +108,7 @@ let local tbd_source=${darwin-stubs}/System/Library/Frameworks/$nested_path/Versions/$current if [ "${name}" != "Kernel" ]; then + # The Kernel.framework has headers but no actual library component. cp -v $tbd_source/*.tbd . fi From f2b81a021eccc072029f8a93b45b2c9a9ce0aa2a Mon Sep 17 00:00:00 2001 From: Andrew Childs Date: Thu, 12 Nov 2020 16:50:26 +0900 Subject: [PATCH 18/18] darwin/print-reexports: add an overview comment --- .../darwin/apple-sdk/print-reexports/main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c b/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c index 7ad793eb425..df46e3f18e8 100644 --- a/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c +++ b/pkgs/os-specific/darwin/apple-sdk/print-reexports/main.c @@ -1,3 +1,22 @@ +/** + * Display the list of re-exported libraries from a TAPI v2 .tbd file, one per + * line on stdout. + * + * TAPI files are the equivalent of library files for the purposes of linking. + * Like dylib files, they may re-export other libraries. In upstream usage + * these refer to the absolute paths of dylibs, and are resolved to .tbd files + * in combination with the syslibroot option. In nixpkgs, the .tbd files refer + * directly to other .tbd files without a syslibroot. Note that each .tbd file + * contains an install name, so the re-exported path does not affect the final + * result. + * + * In nixpkgs each framework is a distinct store path and some frameworks + * re-export other frameworks. The re-exported names are rewritten to refer to + * the store paths of dependencies via textual substitution. This utility is + * used to emit every file that is listed as a re-exported library, which + * allows the framework builder to verify their existence. + */ + #include #include #include