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

swift: 5.8 -> 5.9.2 #256956

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
121 changes: 19 additions & 102 deletions pkgs/development/compilers/swift/compiler/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ let
"autolink-driver"
"compiler"
# "clang-builtin-headers"
"libexec"
"stdlib"
"sdk-overlay"
"static-mirror-lib"
Expand Down Expand Up @@ -142,9 +143,9 @@ let
# Create a tool used during the build to create a custom swift wrapper for
# each of the swift executables produced by the build.
#
# The build produces several `swift-frontend` executables during
# bootstrapping. Each of these has numerous aliases via symlinks, and the
# executable uses $0 to detect what tool is called.
# The build produces a `swift-frontend` executable per bootstrap stage. Each
# of these has one or more aliases via symlinks, and the executable uses $0
# to detect what tool is called.
wrapperParams = {
inherit bintools;
default_cc_wrapper = clang; # Instead of `@out@` in the original.
Expand All @@ -153,7 +154,7 @@ let
suffixSalt = lib.replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
use_response_file_by_default = 1;
swiftDriver = "";
# NOTE: @prog@ needs to be filled elsewhere.
# NOTE: @prog@ and @progName@ need to be filled elsewhere.
};
swiftWrapper = runCommand "swift-wrapper.sh" wrapperParams ''
substituteAll '${../wrapper/wrapper.sh}' "$out"
Expand All @@ -167,7 +168,7 @@ let
mv "$targetFile" "$unwrappedSwift"
sed < '${swiftWrapper}' > "$targetFile" \
-e "s|@prog@|'$unwrappedSwift'|g" \
-e 's|exec "$prog"|exec -a "$0" "$prog"|g'
-e 's|@progName@|"$0"|g'
chmod a+x "$targetFile"
'';

Expand Down Expand Up @@ -254,7 +255,7 @@ in stdenv.mkDerivation {
mkdir src
cd src

${copySource "swift-cmark"}
${copySource "cmark"}
${copySource "llvm-project"}
${copySource "swift"}
${copySource "swift-experimental-string-processing"}
Expand All @@ -278,7 +279,6 @@ in stdenv.mkDerivation {
-e 's|/bin/cp|${coreutils}/bin/cp|g' \
-e 's|/usr/bin/file|${file}/bin/file|g'

patch -p1 -d swift -i ${./patches/swift-cmake-3.25-compat.patch}
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-libc-paths.patch}
Expand All @@ -300,23 +300,13 @@ in stdenv.mkDerivation {
substituteAll ${./patches/swift-separate-lib.patch} $TMPDIR/swift-separate-lib.patch
patch -p1 -d swift -i $TMPDIR/swift-separate-lib.patch

patch -p1 -d llvm-project -i ${./patches/lldb-build-fix.patch}

patch -p1 -d llvm-project/llvm -i ${./patches/llvm-module-cache.patch}

patch -p1 -d llvm-project/clang -i ${./patches/clang-toolchain-dir.patch}
patch -p1 -d llvm-project/clang -i ${./patches/clang-wrap.patch}
patch -p1 -d llvm-project/clang -i ${../../llvm/14/clang/purity.patch}
patch -p2 -d llvm-project/clang -i ${fetchpatch {
name = "clang-cmake-fix-interpreter.patch";
url = "https://github.com/llvm/llvm-project/commit/b5eaf500f2441eff2277ea2973878fb1f171fd0a.patch";
sha256 = "1rma1al0rbm3s3ql6bnvbcighp74lri1lcrwbyacgdqp80fgw1b6";
}}

# gcc-13 build fixes
patch -p2 -d llvm-project/llvm -i ${fetchpatch {
name = "gcc-13.patch";
url = "https://github.com/llvm/llvm-project/commit/ff1681ddb303223973653f7f5f3f3435b48a1983.patch";
hash = "sha256-nkRPWx8gNvYr7mlvEUiOAb1rTrf+skCZjAydJVUHrcI=";
}}
patch -p1 -d llvm-project/clang -i ${../../llvm/15/clang/purity.patch}

${lib.optionalString stdenv.isLinux ''
substituteInPlace llvm-project/clang/lib/Driver/ToolChains/Linux.cpp \
Expand Down Expand Up @@ -406,7 +396,7 @@ in stdenv.mkDerivation {
}

cmakeFlags="-GNinja"
buildProject swift-cmark
buildProject cmark

# Some notes:
# - The Swift build just needs Clang.
Expand All @@ -425,8 +415,7 @@ in stdenv.mkDerivation {
# 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.)
# build steps may fail.
OLD_NIX_SWIFTFLAGS_COMPILE="$NIX_SWIFTFLAGS_COMPILE"
OLD_NIX_LDFLAGS="$NIX_LDFLAGS"
export NIX_SWIFTFLAGS_COMPILE+=" -I ${appleSwiftCore}/lib/swift"
Expand All @@ -450,12 +439,16 @@ in stdenv.mkDerivation {
-DBOOTSTRAPPING_MODE=BOOTSTRAPPING${lib.optionalString stdenv.isDarwin "-WITH-HOSTLIBS"}
-DSWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING=ON
-DSWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY=ON
-DSWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP=ON
-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED=ON
-DSWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING=ON
-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION=ON
-DSWIFT_ENABLE_BACKTRACING=ON
-DSWIFT_BUILD_LIBEXEC=${if stdenv.isDarwin then "ON" else "OFF"}
-DLLVM_DIR=$SWIFT_BUILD_ROOT/llvm/lib/cmake/llvm
-DClang_DIR=$SWIFT_BUILD_ROOT/llvm/lib/cmake/clang
-DSWIFT_PATH_TO_CMARK_SOURCE=$SWIFT_SOURCE_ROOT/swift-cmark
-DSWIFT_PATH_TO_CMARK_BUILD=$SWIFT_BUILD_ROOT/swift-cmark
-DSWIFT_PATH_TO_CMARK_SOURCE=$SWIFT_SOURCE_ROOT/cmark
-DSWIFT_PATH_TO_CMARK_BUILD=$SWIFT_BUILD_ROOT/cmark
-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=$SWIFT_SOURCE_ROOT/swift-corelibs-libdispatch
-DSWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE=$SWIFT_SOURCE_ROOT/swift-syntax
-DSWIFT_PATH_TO_STRING_PROCESSING_SOURCE=$SWIFT_SOURCE_ROOT/swift-experimental-string-processing
Expand Down Expand Up @@ -506,75 +499,6 @@ in stdenv.mkDerivation {
-DPANEL_LIBRARIES=${ncurses}/lib/libpanel${stdenv.hostPlatform.extensions.sharedLibrary}
";
buildProject lldb llvm-project/lldb

${lib.optionalString stdenv.isDarwin ''
# Need to do a standalone build of concurrency for Darwin back deployment.
# Based on: utils/swift_build_support/swift_build_support/products/backdeployconcurrency.py
cmakeFlags="
-GNinja
-DCMAKE_Swift_COMPILER=$SWIFT_BUILD_ROOT/swift/bin/swiftc
-DSWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE=$SWIFT_SOURCE_ROOT/swift-syntax

-DTOOLCHAIN_DIR=/var/empty
-DSWIFT_NATIVE_LLVM_TOOLS_PATH=${stdenv.cc}/bin
-DSWIFT_NATIVE_CLANG_TOOLS_PATH=${stdenv.cc}/bin
-DSWIFT_NATIVE_SWIFT_TOOLS_PATH=$SWIFT_BUILD_ROOT/swift/bin

-DCMAKE_CROSSCOMPILING=ON

-DBUILD_SWIFT_CONCURRENCY_BACK_DEPLOYMENT_LIBRARIES=ON
-DSWIFT_INCLUDE_TOOLS=OFF
-DSWIFT_BUILD_STDLIB_EXTRA_TOOLCHAIN_CONTENT=OFF
-DSWIFT_BUILD_TEST_SUPPORT_MODULES=OFF
-DSWIFT_BUILD_STDLIB=OFF
-DSWIFT_BUILD_DYNAMIC_STDLIB=OFF
-DSWIFT_BUILD_STATIC_STDLIB=OFF
-DSWIFT_BUILD_REMOTE_MIRROR=OFF
-DSWIFT_BUILD_SDK_OVERLAY=OFF
-DSWIFT_BUILD_DYNAMIC_SDK_OVERLAY=OFF
-DSWIFT_BUILD_STATIC_SDK_OVERLAY=OFF
-DSWIFT_INCLUDE_TESTS=OFF
-DSWIFT_BUILD_PERF_TESTSUITE=OFF

-DSWIFT_HOST_VARIANT_ARCH=${swiftArch}
-DBUILD_STANDALONE=ON

-DSWIFT_INSTALL_COMPONENTS=back-deployment

-DSWIFT_SDKS=${{
"macos" = "OSX";
"ios" = "IOS";
#IOS_SIMULATOR
#TVOS
#TVOS_SIMULATOR
#WATCHOS
#WATCHOS_SIMULATOR
}.${targetPlatform.darwinPlatform}}

-DLLVM_DIR=$SWIFT_BUILD_ROOT/llvm/lib/cmake/llvm

-DSWIFT_DEST_ROOT=$out
-DSWIFT_HOST_VARIANT_SDK=OSX

-DSWIFT_DARWIN_DEPLOYMENT_VERSION_OSX=10.15
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_IOS=13.0
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_MACCATALYST=13.0
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_TVOS=13.0
-DSWIFT_DARWIN_DEPLOYMENT_VERSION_WATCHOS=6.0
"

# This depends on the special Clang build specific to the Swift branch.
# We also need to call a specific Ninja target.
export CC=$SWIFT_BUILD_ROOT/llvm/bin/clang
export CXX=$SWIFT_BUILD_ROOT/llvm/bin/clang++
ninjaFlags="back-deployment"

buildProject swift-concurrency-backdeploy swift

export CC=$NIX_CC/bin/clang
export CXX=$NIX_CC/bin/clang++
unset ninjaFlags
''}
'';

# TODO: ~50 failing tests on x86_64-linux. Other platforms not checked.
Expand All @@ -592,7 +516,7 @@ in stdenv.mkDerivation {
# Undo the clang and swift wrapping we did for the build.
# (This happened via patches to cmake files.)
cd $SWIFT_BUILD_ROOT
mv llvm/bin/clang-15{-unwrapped,}
mv llvm/bin/clang-16{-unwrapped,}
mv swift/bin/swift-frontend{-unwrapped,}

mkdir $out $lib
Expand All @@ -611,13 +535,6 @@ in stdenv.mkDerivation {
cd $SWIFT_BUILD_ROOT/swift
ninjaInstallPhase

${lib.optionalString stdenv.isDarwin ''
cd $SWIFT_BUILD_ROOT/swift-concurrency-backdeploy
installTargets=install-back-deployment
ninjaInstallPhase
unset installTargets
''}

# Separate $lib output here, because specific logic follows.
# Only move the dynamic run-time parts, to keep $lib small. Every Swift
# build will depend on it.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/cmake/Modules/FindLibEdit.cmake
+++ b/cmake/Modules/FindLibEdit.cmake
@@ -19,6 +19,7 @@ pkg_check_modules(PC_LIBEDIT QUIET libedit)
find_path(LibEdit_INCLUDE_DIRS NAMES histedit.h HINTS ${PC_LIBEDIT_INCLUDE_DIRS})
find_library(LibEdit_LIBRARIES NAMES edit HINTS ${PC_LIBEDIT_LIBRARY_DIRS})

+include(CMakePushCheckState)
include(CheckIncludeFile)
if(LibEdit_INCLUDE_DIRS AND EXISTS "${LibEdit_INCLUDE_DIRS}/histedit.h")
cmake_push_check_state()
Loading
Loading