From f4ae6b252d498b105f5ee39d5d55b6e7b9a88f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Kochen?= Date: Tue, 17 Jan 2023 22:22:29 +0100 Subject: [PATCH 1/2] Revert "darwin.apple_sdk_11_0: add Security dependency on xpc" This reverts commit 511f21df7c821bea7aba86fd4062d5fed9af948d. In apple_sdk_11_0, the xpc package contains only headers that are already part of libsystem, so this change did nothing. For Swift and `-fmodules`, this actually caused an error, because there was now a duplicate module in the search path. --- pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix b/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix index 2cf1c5dd0fc88..59cbc2b1063a1 100644 --- a/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix +++ b/pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix @@ -159,7 +159,7 @@ ScreenSaver = {}; ScreenTime = {}; ScriptingBridge = {}; - Security = { inherit IOKit libDER xpc; }; + Security = { inherit IOKit libDER; }; SecurityFoundation = { inherit Security; }; SecurityInterface = { inherit Security SecurityFoundation; }; SensorKit = {}; From 7220d26ed5d20cfbcbee81644fcdfc91932fcbb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Kochen?= Date: Tue, 17 Jan 2023 22:41:48 +0100 Subject: [PATCH 2/2] swift: bootstrap using system stdlib `BOOTSTRAPPING-WITH-HOSTLIBS` is also what official builds use on Darwin. It's unclear why `BOOTSTRAPPING` was working before, but it is probably not supported on Darwin to begin with. It was now causing crashes because of mixing of two copies of stdlib at run-time. --- .../compilers/swift/compiler/default.nix | 43 +++++++++++++++++-- .../patches/swift-darwin-fix-bootstrap.patch | 20 --------- pkgs/development/compilers/swift/default.nix | 2 +- 3 files changed, 40 insertions(+), 25 deletions(-) delete mode 100644 pkgs/development/compilers/swift/compiler/patches/swift-darwin-fix-bootstrap.patch diff --git a/pkgs/development/compilers/swift/compiler/default.nix b/pkgs/development/compilers/swift/compiler/default.nix index 0612deb471d17..306ddf8753a5e 100644 --- a/pkgs/development/compilers/swift/compiler/default.nix +++ b/pkgs/development/compilers/swift/compiler/default.nix @@ -36,6 +36,7 @@ , CoreServices , Foundation , Combine +, MacOSX-SDK , CLTools_Executables }: @@ -169,6 +170,21 @@ let chmod a+x "$targetFile" ''; + # On Darwin, we need to use BOOTSTRAPPING-WITH-HOSTLIBS because of ABI + # stability, and have to provide the definitions for the system stdlib. + appleSwiftCore = stdenv.mkDerivation { + name = "apple-swift-core"; + dontUnpack = true; + + installPhase = '' + mkdir -p $out/lib/swift + cp -r \ + "${MacOSX-SDK}/usr/lib/swift/Swift.swiftmodule" \ + "${MacOSX-SDK}/usr/lib/swift/libswiftCore.tbd" \ + $out/lib/swift/ + ''; + }; + in stdenv.mkDerivation { pname = "swift"; inherit (sources) version; @@ -263,7 +279,6 @@ in stdenv.mkDerivation { patch -p1 -d swift -i ${./patches/swift-wrap.patch} patch -p1 -d swift -i ${./patches/swift-nix-resource-root.patch} patch -p1 -d swift -i ${./patches/swift-linux-fix-linking.patch} - patch -p1 -d swift -i ${./patches/swift-darwin-fix-bootstrap.patch} patch -p1 -d swift -i ${substituteAll { src = ./patches/swift-darwin-plistbuddy-workaround.patch; inherit swiftArch; @@ -395,9 +410,23 @@ in stdenv.mkDerivation { " buildProject llvm llvm-project/llvm + '' + lib.optionalString stdenv.isDarwin '' + # Add appleSwiftCore to the search paths. We can't simply add it to + # buildInputs, because it is potentially an older stdlib than the one we're + # building. We have to remove it again after the main Swift build, or later + # build steps may fail. (Specific case: Concurrency backdeploy uses the + # Sendable protocol, which appears to not be present in the macOS 11 SDK.) + OLD_NIX_SWIFTFLAGS_COMPILE="$NIX_SWIFTFLAGS_COMPILE" + OLD_NIX_LDFLAGS="$NIX_LDFLAGS" + export NIX_SWIFTFLAGS_COMPILE+=" -I ${appleSwiftCore}/lib/swift" + export NIX_LDFLAGS+=" -L ${appleSwiftCore}/lib/swift" + '' + '' + # Some notes: - # - Building with libswift defaults to OFF in CMake, but is enabled in - # standard builds, so we enable it as well. + # - BOOTSTRAPPING_MODE defaults to OFF in CMake, but is enabled in standard + # builds, so we enable it as well. On Darwin, we have to use the system + # Swift libs because of ABI-stability, but this may be trouble if the + # builder is an older macOS. # - Experimental features are OFF by default in CMake, but some are # required to build the stdlib. # - SWIFT_STDLIB_ENABLE_OBJC_INTEROP is set explicitely because its check @@ -405,7 +434,7 @@ in stdenv.mkDerivation { # Fixed in: https://github.com/apple/swift/commit/84083afef1de5931904d5c815d53856cdb3fb232 cmakeFlags=" -GNinja - -DBOOTSTRAPPING_MODE=BOOTSTRAPPING + -DBOOTSTRAPPING_MODE=BOOTSTRAPPING${lib.optionalString stdenv.isDarwin "-WITH-HOSTLIBS"} -DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=ON -DLLVM_DIR=$SWIFT_BUILD_ROOT/llvm/lib/cmake/llvm -DClang_DIR=$SWIFT_BUILD_ROOT/llvm/lib/cmake/clang @@ -418,6 +447,12 @@ in stdenv.mkDerivation { " buildProject swift + '' + lib.optionalString stdenv.isDarwin '' + # Restore search paths to remove appleSwiftCore. + export NIX_SWIFTFLAGS_COMPILE="$OLD_NIX_SWIFTFLAGS_COMPILE" + export NIX_LDFLAGS="$OLD_NIX_LDFLAGS" + '' + '' + # These are based on flags in `utils/build-script-impl`. # # LLDB_USE_SYSTEM_DEBUGSERVER=ON disables the debugserver build on Darwin, diff --git a/pkgs/development/compilers/swift/compiler/patches/swift-darwin-fix-bootstrap.patch b/pkgs/development/compilers/swift/compiler/patches/swift-darwin-fix-bootstrap.patch deleted file mode 100644 index a87b90bd8ca7c..0000000000000 --- a/pkgs/development/compilers/swift/compiler/patches/swift-darwin-fix-bootstrap.patch +++ /dev/null @@ -1,20 +0,0 @@ -This patch fixes dylib references during bootstrapping. It's possible -`LIBSWIFT_BUILD_MODE=BOOTSTRAPPING` is not really well tested on Darwin, -because official builds don't use it. - -In the near future, Swift will require an existing Swift toolchain to -bootstrap, and we will likely have to replace this any way. - ---- a/stdlib/cmake/modules/AddSwiftStdlib.cmake -+++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake -@@ -1035,6 +1035,10 @@ function(add_swift_target_library_single target name) - set(install_name_dir "${SWIFTLIB_SINGLE_DARWIN_INSTALL_NAME_DIR}") - endif() - -+ if(DEFINED SWIFTLIB_SINGLE_BOOTSTRAPPING) -+ set(install_name_dir "${lib_dir}/${output_sub_dir}") -+ endif() -+ - set_target_properties("${target}" - PROPERTIES - INSTALL_NAME_DIR "${install_name_dir}") diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix index a51fa2805b765..e8eb4d738ca93 100644 --- a/pkgs/development/compilers/swift/default.nix +++ b/pkgs/development/compilers/swift/default.nix @@ -49,7 +49,7 @@ let swift-unwrapped = callPackage ./compiler { inherit (darwin) DarwinTools cctools sigtool; - inherit (apple_sdk) CLTools_Executables; + inherit (apple_sdk) MacOSX-SDK CLTools_Executables; inherit (apple_sdk.frameworks) CoreServices Foundation Combine; };