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

[staging-next] swift: bootstrap using system stdlib #211908

Merged
merged 2 commits into from
Jan 28, 2023
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
43 changes: 39 additions & 4 deletions pkgs/development/compilers/swift/compiler/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
, CoreServices
, Foundation
, Combine
, MacOSX-SDK
, CLTools_Executables
}:

Expand Down Expand Up @@ -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 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

symlinking does not work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is modelled after libs in apple_sdk.nix. I think the idea is that we try to avoid users having to download the full SDK.

"${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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -395,17 +410,31 @@ 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
# is buggy. (Uses SWIFT_HOST_VARIANT_SDK before initialized.)
# 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
Expand All @@ -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,
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion pkgs/development/compilers/swift/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/darwin/apple-sdk-11.0/frameworks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
ScreenSaver = {};
ScreenTime = {};
ScriptingBridge = {};
Security = { inherit IOKit libDER xpc; };
Security = { inherit IOKit libDER; };
SecurityFoundation = { inherit Security; };
SecurityInterface = { inherit Security SecurityFoundation; };
SensorKit = {};
Expand Down