Unverified Commit 6cf7bb99 authored by Domen Kožar's avatar Domen Kožar Committed by GitHub
Browse files

Merge pull request #225197 from stephank/feat/swift58

swift: 5.7.3 -> 5.8
parents cf9ada3a f85d1219
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -97,8 +97,6 @@ stdenv.mkDerivation {
    substituteInPlace cmake/builtin-config-ix.cmake \
      --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)'
  '' + lib.optionalString stdenv.isDarwin ''
    substituteInPlace cmake/builtin-config-ix.cmake \
      --replace 'set(ARM64 arm64 arm64e)' 'set(ARM64)'
    substituteInPlace cmake/config-ix.cmake \
      --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)'
  '' + lib.optionalString (useLLVM) ''
+12 −8
Original line number Diff line number Diff line
@@ -99,7 +99,6 @@ let
    # "clang-builtin-headers"
    "stdlib"
    "sdk-overlay"
    "parser-lib"
    "static-mirror-lib"
    "editor-integration"
    # "tools"
@@ -257,6 +256,7 @@ in stdenv.mkDerivation {
    ${copySource "llvm-project"}
    ${copySource "swift"}
    ${copySource "swift-experimental-string-processing"}
    ${copySource "swift-syntax"}
    ${lib.optionalString
      (!stdenv.isDarwin)
      (copySource "swift-corelibs-libdispatch")}
@@ -276,9 +276,13 @@ 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}
    patch -p1 -d swift -i ${./patches/swift-linux-fix-linking.patch}
    patch -p1 -d swift -i ${./patches/swift-darwin-libcxx-flags.patch}
    patch -p1 -d swift -i ${./patches/swift-darwin-link-cxxabi.patch}
    patch -p1 -d swift -i ${substituteAll {
      src = ./patches/swift-darwin-plistbuddy-workaround.patch;
      inherit swiftArch;
@@ -287,8 +291,6 @@ in stdenv.mkDerivation {
      src = ./patches/swift-prevent-sdk-dirs-warning.patch;
      inherit (builtins) storeDir;
    }}
    substituteInPlace swift/cmake/modules/SwiftConfigureSDK.cmake \
      --replace '/usr/include' "${stdenv.cc.libc_dev}/include"

    # This patch needs to know the lib output location, so must be substituted
    # in the same derivation as the compiler.
@@ -321,8 +323,8 @@ in stdenv.mkDerivation {
    ''}

    # Remove tests for cross compilation, which we don't currently support.
    rm swift/test/Interop/Cxx/class/constructors-copy-irgen.swift
    rm swift/test/Interop/Cxx/class/constructors-irgen.swift
    rm swift/test/Interop/Cxx/class/constructors-copy-irgen-*.swift
    rm swift/test/Interop/Cxx/class/constructors-irgen-*.swift

    # TODO: consider fixing and re-adding. This test fails due to a non-standard "install_prefix".
    rm swift/validation-test/Python/build_swift.swift
@@ -342,7 +344,7 @@ in stdenv.mkDerivation {
    rm swift/test/Serialization/restrict-swiftmodule-to-revision.swift

    # This test was flaky in ofborg, see #186476
    rm swift/test/AutoDiff/compiler_crashers_fixed/sr14290-missing-debug-scopes-in-pullback-trampoline.swift
    rm swift/test/AutoDiff/compiler_crashers_fixed/issue-56649-missing-debug-scopes-in-pullback-trampoline.swift

    patchShebangs .

@@ -446,7 +448,8 @@ in stdenv.mkDerivation {
      -DSWIFT_PATH_TO_CMARK_SOURCE=$SWIFT_SOURCE_ROOT/swift-cmark
      -DSWIFT_PATH_TO_CMARK_BUILD=$SWIFT_BUILD_ROOT/swift-cmark
      -DSWIFT_PATH_TO_LIBDISPATCH_SOURCE=$SWIFT_SOURCE_ROOT/swift-corelibs-libdispatch
      -DEXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR=$SWIFT_SOURCE_ROOT/swift-experimental-string-processing
      -DSWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE=$SWIFT_SOURCE_ROOT/swift-syntax
      -DSWIFT_PATH_TO_STRING_PROCESSING_SOURCE=$SWIFT_SOURCE_ROOT/swift-experimental-string-processing
      -DSWIFT_INSTALL_COMPONENTS=${lib.concatStringsSep ";" swiftInstallComponents}
      -DSWIFT_STDLIB_ENABLE_OBJC_INTEROP=${if stdenv.isDarwin then "ON" else "OFF"}
    "
@@ -501,6 +504,7 @@ in stdenv.mkDerivation {
    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
@@ -579,7 +583,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-14{-unwrapped,}
    mv llvm/bin/clang-15{-unwrapped,}
    mv swift/bin/swift-frontend{-unwrapped,}

    mkdir $out $lib
+1509 −0

File added.

Preview size limit exceeded, changes collapsed.

+63 −0
Original line number Diff line number Diff line
On Darwin, the SDK is a directory of stubs, and libc++ lives separately. We
need to patch the CMake files in several places to make the build for C++
interop succeed. The required flags can be read from cc-wrapper support files.

--- a/SwiftCompilerSources/CMakeLists.txt
+++ b/SwiftCompilerSources/CMakeLists.txt
@@ -105,18 +105,11 @@ function(add_swift_compiler_modules_library name)
       get_filename_component(swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY)
       set(sdk_option ${sdk_option} "-resource-dir" "${swift_exec_bin_dir}/../bootstrapping0/lib/swift")
     endif()
-    if(NOT EXISTS "${sdk_path}/usr/include/c++")
-      # Darwin SDKs in Xcode 12 or older do not include libc++, which prevents clang from finding libc++ when invoked
-      # from ClangImporter. This results in build errors. To workaround this, let's explicitly pass the path to libc++
-      # to clang.
-      message(WARNING "Building with an outdated Darwin SDK: libc++ missing from the ${SWIFT_HOST_VARIANT_SDK} SDK. Will use libc++ from the toolchain.")
-      get_filename_component(absolute_libcxx_path "${CMAKE_C_COMPILER}/../../include/c++/v1" REALPATH)
-      if (EXISTS "${absolute_libcxx_path}")
-        set(sdk_option ${sdk_option} "-Xcc" "-isystem" "-Xcc" "${absolute_libcxx_path}")
-      else()
-        message(ERROR "libc++ not found in the toolchain.")
-      endif()
-    endif()
+    file(READ "$ENV{NIX_CC}/nix-support/libcxx-cxxflags" nix_libcxx_cxxflags)
+    separate_arguments(nix_libcxx_cxxflags)
+    foreach(nix_libcxx_cxxflag ${nix_libcxx_cxxflags})
+      set(sdk_option ${sdk_option} "-Xcc" "${nix_libcxx_cxxflag}")
+    endforeach()
   elseif(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE")
     set(sdk_option "-sdk" "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}")
     get_filename_component(swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY)
--- a/cmake/modules/SwiftConfigureSDK.cmake
+++ b/cmake/modules/SwiftConfigureSDK.cmake
@@ -270,6 +270,18 @@ macro(configure_sdk_darwin
   # Add this to the list of known SDKs.
   list(APPEND SWIFT_CONFIGURED_SDKS "${prefix}")
 
+  set(cxx_overlay_opt "")
+  if("${prefix}" STREQUAL "OSX")
+    file(READ "$ENV{NIX_CC}/nix-support/libcxx-cxxflags" nix_libcxx_cxxflags)
+    separate_arguments(nix_libcxx_cxxflags)
+    foreach(nix_libcxx_cxxflag ${nix_libcxx_cxxflags})
+      set(cxx_overlay_opt ${cxx_overlay_opt} "-Xcc" "${nix_libcxx_cxxflag}")
+    endforeach()
+  endif()
+  set(SWIFT_SDK_${prefix}_CXX_OVERLAY_SWIFT_COMPILE_FLAGS
+      ${cxx_overlay_opt}
+    CACHE STRING "Extra flags for compiling the C++ overlay")
+
   _report_sdk("${prefix}")
 endmacro()
 
--- a/stdlib/public/Cxx/std/CMakeLists.txt
+++ b/stdlib/public/Cxx/std/CMakeLists.txt
@@ -145,6 +145,9 @@ add_swift_target_library(swiftstd STATIC NO_LINK_NAME IS_STDLIB
     SWIFT_COMPILE_FLAGS_LINUX
     ${SWIFT_SDK_LINUX_CXX_OVERLAY_SWIFT_COMPILE_FLAGS}
 
+    SWIFT_COMPILE_FLAGS_OSX
+    ${SWIFT_SDK_OSX_CXX_OVERLAY_SWIFT_COMPILE_FLAGS}
+
     LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
     TARGET_SDKS ALL_APPLE_PLATFORMS LINUX
     INSTALL_IN_COMPONENT compiler
+14 −0
Original line number Diff line number Diff line
This patches the stdlib backdeploy static lib to have its users link c++abi.
Without this, later steps that try to link this fail looking for global
new/delete operators (__Znwm/__ZdlPv).

--- a/stdlib/toolchain/Compatibility56/Overrides.cpp
+++ b/stdlib/toolchain/Compatibility56/Overrides.cpp
@@ -23,6 +23,7 @@
 using namespace swift;
 
 __asm__ (".linker_option \"-lc++\"");
+__asm__ (".linker_option \"-lc++abi\"");
 
 #define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
   Override_ ## name name;
Loading