diff --git a/pkgs/development/compilers/swift/default.nix b/pkgs/development/compilers/swift/default.nix index ce20f3a0e813..1cd19a521350 100644 --- a/pkgs/development/compilers/swift/default.nix +++ b/pkgs/development/compilers/swift/default.nix @@ -72,6 +72,11 @@ let inherit (darwin) DarwinTools; }; + swiftpm = callPackage ./swiftpm { + inherit (darwin) DarwinTools cctools; + inherit (apple_sdk.frameworks) CryptoKit LocalAuthentication; + }; + }; in self diff --git a/pkgs/development/compilers/swift/swiftpm/cmake-glue/ArgumentParserConfig.cmake b/pkgs/development/compilers/swift/swiftpm/cmake-glue/ArgumentParserConfig.cmake new file mode 100644 index 000000000000..201cbb3048bb --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/cmake-glue/ArgumentParserConfig.cmake @@ -0,0 +1,5 @@ +add_library(ArgumentParser SHARED IMPORTED) +set_property(TARGET ArgumentParser PROPERTY IMPORTED_LOCATION "@out@/lib/swift/@swiftOs@/libArgumentParser@dylibExt@") + +add_library(ArgumentParserToolInfo SHARED IMPORTED) +set_property(TARGET ArgumentParserToolInfo PROPERTY IMPORTED_LOCATION "@out@/lib/swift/@swiftOs@/libArgumentParserToolInfo@dylibExt@") diff --git a/pkgs/development/compilers/swift/swiftpm/cmake-glue/LLBuildConfig.cmake b/pkgs/development/compilers/swift/swiftpm/cmake-glue/LLBuildConfig.cmake new file mode 100644 index 000000000000..d240bcb3429d --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/cmake-glue/LLBuildConfig.cmake @@ -0,0 +1,5 @@ +add_library(libllbuild SHARED IMPORTED) +set_property(TARGET libllbuild PROPERTY IMPORTED_LOCATION "@out@/lib/libllbuild@dylibExt@") + +add_library(llbuildSwift SHARED IMPORTED) +set_property(TARGET llbuildSwift PROPERTY IMPORTED_LOCATION "@out@/lib/swift/pm/llbuild/libllbuildSwift@dylibExt@") diff --git a/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftCollectionsConfig.cmake b/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftCollectionsConfig.cmake new file mode 100644 index 000000000000..e26bdaca7e73 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftCollectionsConfig.cmake @@ -0,0 +1,8 @@ +add_library(SwiftCollections::Collections STATIC IMPORTED) +set_property(TARGET SwiftCollections::Collections PROPERTY IMPORTED_LOCATION "@out@/lib/swift_static/@swiftOs@/libCollections@staticLibExt@") + +add_library(SwiftCollections::DequeModule STATIC IMPORTED) +set_property(TARGET SwiftCollections::DequeModule PROPERTY IMPORTED_LOCATION "@out@/lib/swift_static/@swiftOs@/libDequeModule@staticLibExt@") + +add_library(SwiftCollections::OrderedCollections STATIC IMPORTED) +set_property(TARGET SwiftCollections::OrderedCollections PROPERTY IMPORTED_LOCATION "@out@/lib/swift_static/@swiftOs@/libOrderedCollections@staticLibExt@") diff --git a/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftCryptoConfig.cmake b/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftCryptoConfig.cmake new file mode 100644 index 000000000000..89644f62f9ff --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftCryptoConfig.cmake @@ -0,0 +1,2 @@ +add_library(Crypto SHARED IMPORTED) +set_property(TARGET Crypto PROPERTY IMPORTED_LOCATION "@out@/lib/swift/@swiftOs@/libCrypto@dylibExt@") diff --git a/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftDriverConfig.cmake b/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftDriverConfig.cmake new file mode 100644 index 000000000000..5439714c480f --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftDriverConfig.cmake @@ -0,0 +1,8 @@ +add_library(SwiftDriver SHARED IMPORTED) +set_property(TARGET SwiftDriver PROPERTY IMPORTED_LOCATION "@out@/lib/libSwiftDriver@dylibExt@") + +add_library(SwiftDriverExecution SHARED IMPORTED) +set_property(TARGET SwiftDriverExecution PROPERTY IMPORTED_LOCATION "@out@/lib/libSwiftDriverExecution@dylibExt@") + +add_library(SwiftOptions SHARED IMPORTED) +set_property(TARGET SwiftOptions PROPERTY IMPORTED_LOCATION "@out@/lib/libSwiftOptions@dylibExt@") diff --git a/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftSystemConfig.cmake b/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftSystemConfig.cmake new file mode 100644 index 000000000000..af48f34e71b8 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/cmake-glue/SwiftSystemConfig.cmake @@ -0,0 +1,2 @@ +add_library(SwiftSystem::SystemPackage STATIC IMPORTED) +set_property(TARGET SwiftSystem::SystemPackage PROPERTY IMPORTED_LOCATION "@out@/lib/swift_static/@swiftOs@/libSystemPackage@staticLibExt@") diff --git a/pkgs/development/compilers/swift/swiftpm/cmake-glue/TSCConfig.cmake b/pkgs/development/compilers/swift/swiftpm/cmake-glue/TSCConfig.cmake new file mode 100644 index 000000000000..76c5e6ccd072 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/cmake-glue/TSCConfig.cmake @@ -0,0 +1,8 @@ +add_library(TSCLibc SHARED IMPORTED) +set_property(TARGET TSCLibc PROPERTY IMPORTED_LOCATION "@out@/lib/libTSCLibc@dylibExt@") + +add_library(TSCBasic SHARED IMPORTED) +set_property(TARGET TSCBasic PROPERTY IMPORTED_LOCATION "@out@/lib/libTSCBasic@dylibExt@") + +add_library(TSCUtility SHARED IMPORTED) +set_property(TARGET TSCUtility PROPERTY IMPORTED_LOCATION "@out@/lib/libTSCUtility@dylibExt@") diff --git a/pkgs/development/compilers/swift/swiftpm/cmake-glue/YamsConfig.cmake b/pkgs/development/compilers/swift/swiftpm/cmake-glue/YamsConfig.cmake new file mode 100644 index 000000000000..7f586698bd4a --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/cmake-glue/YamsConfig.cmake @@ -0,0 +1,5 @@ +add_library(CYaml SHARED IMPORTED) +set_property(TARGET CYaml PROPERTY IMPORTED_LOCATION "@out@/lib/libCYaml@dylibExt@") + +add_library(Yams SHARED IMPORTED) +set_property(TARGET Yams PROPERTY IMPORTED_LOCATION "@out@/lib/swift/@swiftOs@/libYams@dylibExt@") diff --git a/pkgs/development/compilers/swift/swiftpm/default.nix b/pkgs/development/compilers/swift/swiftpm/default.nix new file mode 100644 index 000000000000..a5fd766ede17 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/default.nix @@ -0,0 +1,462 @@ +{ lib +, callPackage +, stdenv +, fetchFromGitHub +, cmake +, ninja +, git +, swift +, Foundation +, XCTest +, sqlite +, ncurses +, substituteAll +, runCommandLocal +, makeWrapper +, DarwinTools # sw_vers +, cctools # vtool +, xcbuild +, CryptoKit +, LocalAuthentication +}: + +let + + inherit (swift) swiftOs swiftModuleSubdir swiftStaticModuleSubdir; + sharedLibraryExt = stdenv.hostPlatform.extensions.sharedLibrary; + + # Common attributes for the bootstrap swiftpm and the final swiftpm. + commonAttrs = rec { + # Releases are made as part of the Swift toolchain, so versions should match. + version = "5.7"; + src = fetchFromGitHub { + owner = "apple"; + repo = "swift-package-manager"; + rev = "swift-${version}-RELEASE"; + hash = "sha256-MZah+/XfeK46YamxwuE3Kiv+u5bj7VmjEh6ztDF+0j4="; + }; + nativeBuildInputs = [ makeWrapper ]; + # Required at run-time for the host platform to build package manifests. + propagatedBuildInputs = [ Foundation ]; + patches = [ + ./patches/cmake-disable-rpath.patch + ./patches/disable-sandbox.patch + ./patches/fix-clang-cxx.patch + (substituteAll { + src = ./patches/disable-xctest.patch; + inherit (builtins) storeDir; + }) + (substituteAll { + src = ./patches/fix-stdlib-path.patch; + inherit (builtins) storeDir; + swiftLib = swift.swift.lib; + }) + ]; + postPatch = '' + # The location of xcrun is hardcoded. We need PATH lookup instead. + find Sources -name '*.swift' | xargs sed -i -e 's|/usr/bin/xcrun|xcrun|g' + + # Patch the location where swiftpm looks for its API modules. + substituteInPlace Sources/PackageModel/UserToolchain.swift \ + --replace \ + 'librariesPath = applicationPath.parentDirectory' \ + "librariesPath = AbsolutePath(\"$out\")" + ''; + }; + + # Tools invoked by swiftpm at run-time. + runtimeDeps = [ git ] + ++ lib.optionals stdenv.isDarwin [ + xcbuild.xcrun + # vtool is used to determine a minimum deployment target. This is part of + # cctools, but adding that as a build input puts an unwrapped linker in + # PATH, and breaks builds. This small derivation exposes just vtool. + (runCommandLocal "vtool" { } '' + mkdir -p $out/bin + ln -s ${cctools}/bin/vtool $out/bin/vtool + '') + ]; + + # Common attributes for the bootstrap derivations. + mkBootstrapDerivation = attrs: stdenv.mkDerivation (attrs // { + nativeBuildInputs = (attrs.nativeBuildInputs or [ ]) + ++ [ cmake ninja swift ] + ++ lib.optionals stdenv.isDarwin [ DarwinTools ]; + + buildInputs = (attrs.buildInputs or [ ]) + ++ [ Foundation ]; + + postPatch = (attrs.postPatch or "") + + lib.optionalString stdenv.isDarwin '' + # On Darwin only, Swift uses arm64 as cpu arch. + if [ -e cmake/modules/SwiftSupport.cmake ]; then + substituteInPlace cmake/modules/SwiftSupport.cmake \ + --replace '"aarch64" PARENT_SCOPE' '"arm64" PARENT_SCOPE' + fi + ''; + + preConfigure = (attrs.preConfigure or "") + + '' + # Builds often don't set a target, and our default minimum macOS deployment + # target on x86_64-darwin is too low. Harmless on non-Darwin. + export MACOSX_DEPLOYMENT_TARGET=10.15.4 + ''; + + postInstall = (attrs.postInstall or "") + + lib.optionalString stdenv.isDarwin '' + # The install name of libraries is incorrectly set to lib/ (via our + # CMake setup hook) instead of lib/swift/. This'd by easily fixed by + # fixDarwinDylibNames, but some builds create libraries that reference + # eachother, and we also have to fix those references. + dylibs="$(find $out/lib/swift* -name '*.dylib')" + changes="" + for dylib in $dylibs; do + changes+=" -change $(otool -D $dylib | tail -n 1) $dylib" + done + for dylib in $dylibs; do + install_name_tool -id $dylib $changes $dylib + done + ''; + + cmakeFlags = (attrs.cmakeFlags or [ ]) + ++ [ + # Some builds link to libraries within the same build. Make sure these + # create references to $out. None of our builds run their own products, + # so we don't have to account for that scenario. + "-DCMAKE_BUILD_WITH_INSTALL_NAME_DIR=ON" + ]; + }); + + # Generated by swiftpm2nix. + generated = callPackage ./generated { }; + + # On Darwin, we only want ncurses in the linker search path, because headers + # are part of libsystem. Adding its headers to the search path causes strange + # mixing and errors. + # TODO: Find a better way to prevent this conflict. + ncursesInput = if stdenv.isDarwin then ncurses.out else ncurses; + + # Derivations for bootstrapping dependencies using CMake. + # This is based on the `swiftpm/Utilities/bootstrap` script. + # + # Some of the installation steps here are a bit hacky, because it seems like + # these packages were not really meant to be installed using CMake. The + # regular swiftpm bootstrap simply refers to the source and build + # directories. The advantage of separate builds is that we can more easily + # link libs together using existing Nixpkgs infra. + # + # In the end, we don't expose these derivations, and they only exist during + # the bootstrap phase. The final swiftpm derivation does not depend on them. + + swift-system = mkBootstrapDerivation { + name = "swift-system"; + src = generated.sources.swift-system; + + postInstall = '' + # Provide a CMake module. + mkdir -p $out/lib/cmake/SwiftSystem + export staticLibExt="${stdenv.hostPlatform.extensions.staticLibrary}" + export swiftOs="${swiftOs}" + substituteAll ${./cmake-glue/SwiftSystemConfig.cmake} $out/lib/cmake/SwiftSystem/SwiftSystemConfig.cmake + '' + + lib.optionalString (!stdenv.isDarwin) '' + # The cmake rules apparently only use the Darwin install convention. + # Fix up the installation so to module can be found on non-Darwin. + mkdir -p $out/${swiftStaticModuleSubdir} + mv $out/lib/swift_static/${swiftOs}/*.swiftmodule $out/${swiftStaticModuleSubdir}/ + ''; + }; + + swift-collections = mkBootstrapDerivation { + name = "swift-collections"; + src = generated.sources.swift-collections; + + postPatch = '' + # Only builds static libs on Linux, but this installation difference is a + # hassle. Because this installation is temporary for the bootstrap, may + # as well build static libs everywhere. + sed -i -e '/BUILD_SHARED_LIBS/d' CMakeLists.txt + ''; + + postInstall = '' + # Provide a CMake module. + mkdir -p $out/lib/cmake/SwiftCollections + export staticLibExt="${stdenv.hostPlatform.extensions.staticLibrary}" + export swiftOs="${swiftOs}" + substituteAll ${./cmake-glue/SwiftCollectionsConfig.cmake} $out/lib/cmake/SwiftCollections/SwiftCollectionsConfig.cmake + '' + + lib.optionalString (!stdenv.isDarwin) '' + # The cmake rules apparently only use the Darwin install convention. + # Fix up the installation so to module can be found on non-Darwin. + mkdir -p $out/${swiftStaticModuleSubdir} + mv $out/lib/swift_static/${swiftOs}/*.swiftmodule $out/${swiftStaticModuleSubdir}/ + ''; + }; + + swift-tools-support-core = mkBootstrapDerivation { + name = "swift-tools-support-core"; + src = generated.sources.swift-tools-support-core; + + buildInputs = [ + swift-system + sqlite + ]; + + postInstall = '' + # Swift modules are not installed. + mkdir -p $out/${swiftModuleSubdir} + cp swift/*.swift{module,doc} $out/${swiftModuleSubdir}/ + + # Static libs are not installed. + cp lib/*.a $out/lib/ + + # Headers are not installed. + mkdir -p $out/include + cp -r ../Sources/TSCclibc/include $out/include/TSC + + # Provide a CMake module. + mkdir -p $out/lib/cmake/TSC + export dylibExt="${stdenv.hostPlatform.extensions.sharedLibrary}" + substituteAll ${./cmake-glue/TSCConfig.cmake} $out/lib/cmake/TSC/TSCConfig.cmake + ''; + }; + + swift-argument-parser = mkBootstrapDerivation { + name = "swift-argument-parser"; + src = generated.sources.swift-argument-parser; + + buildInputs = [ ncursesInput sqlite ]; + + cmakeFlags = [ + "-DBUILD_TESTING=NO" + "-DBUILD_EXAMPLES=NO" + ]; + + postInstall = '' + # Provide a CMake module. + mkdir -p $out/lib/cmake/ArgumentParser + export dylibExt="${stdenv.hostPlatform.extensions.sharedLibrary}" + export swiftOs="${swiftOs}" + substituteAll ${./cmake-glue/ArgumentParserConfig.cmake} $out/lib/cmake/ArgumentParser/ArgumentParserConfig.cmake + '' + + lib.optionalString stdenv.isLinux '' + # Fix rpath so ArgumentParserToolInfo can be found. + patchelf --add-rpath "$out/lib/swift/${swiftOs}" \ + $out/lib/swift/${swiftOs}/libArgumentParser.so + ''; + }; + + Yams = mkBootstrapDerivation { + name = "Yams"; + src = generated.sources.Yams; + + # Conflicts with BUILD file on case-insensitive filesystems. + cmakeBuildDir = "_build"; + + postInstall = '' + # Provide a CMake module. + mkdir -p $out/lib/cmake/Yams + export dylibExt="${stdenv.hostPlatform.extensions.sharedLibrary}" + export swiftOs="${swiftOs}" + substituteAll ${./cmake-glue/YamsConfig.cmake} $out/lib/cmake/Yams/YamsConfig.cmake + ''; + }; + + llbuild = mkBootstrapDerivation { + name = "llbuild"; + src = generated.sources.swift-llbuild; + + nativeBuildInputs = lib.optional stdenv.isDarwin xcbuild; + buildInputs = [ ncursesInput sqlite ]; + + patches = [ + ./patches/llbuild-cmake-disable-rpath.patch + ]; + + postPatch = '' + # Substitute ncurses for curses. + find . -name CMakeLists.txt | xargs sed -i -e 's/curses/ncurses/' + + # Use absolute install names instead of rpath. + substituteInPlace \ + products/libllbuild/CMakeLists.txt \ + products/llbuildSwift/CMakeLists.txt \ + --replace '@rpath' "$out/lib" + + # This subdirectory is enabled for Darwin only, but requires ObjC XCTest + # (and only Swift XCTest is open source). + substituteInPlace perftests/CMakeLists.txt \ + --replace 'add_subdirectory(Xcode/' '#add_subdirectory(Xcode/' + ''; + + cmakeFlags = [ + "-DLLBUILD_SUPPORT_BINDINGS=Swift" + ]; + + postInstall = '' + # Install module map. + cp ../products/libllbuild/include/module.modulemap $out/include + + # Swift modules are not installed. + mkdir -p $out/${swiftModuleSubdir} + cp products/llbuildSwift/*.swift{module,doc} $out/${swiftModuleSubdir}/ + + # Provide a CMake module. + mkdir -p $out/lib/cmake/LLBuild + export dylibExt="${stdenv.hostPlatform.extensions.sharedLibrary}" + substituteAll ${./cmake-glue/LLBuildConfig.cmake} $out/lib/cmake/LLBuild/LLBuildConfig.cmake + ''; + }; + + swift-driver = mkBootstrapDerivation { + name = "swift-driver"; + src = generated.sources.swift-driver; + + buildInputs = [ + Yams + llbuild + swift-system + swift-argument-parser + swift-tools-support-core + ]; + + postInstall = '' + # Swift modules are not installed. + mkdir -p $out/${swiftModuleSubdir} + cp swift/*.swift{module,doc} $out/${swiftModuleSubdir}/ + + # Provide a CMake module. + mkdir -p $out/lib/cmake/SwiftDriver + export dylibExt="${stdenv.hostPlatform.extensions.sharedLibrary}" + export swiftOs="${swiftOs}" + substituteAll ${./cmake-glue/SwiftDriverConfig.cmake} $out/lib/cmake/SwiftDriver/SwiftDriverConfig.cmake + ''; + }; + + swift-crypto = mkBootstrapDerivation { + name = "swift-crypto"; + src = generated.sources.swift-crypto; + + postPatch = '' + substituteInPlace CMakeLists.txt \ + --replace /usr/bin/ar $NIX_CC/bin/ar + ''; + + postInstall = '' + # Static libs are not installed. + cp lib/*.a $out/lib/ + + # Headers are not installed. + cp -r ../Sources/CCryptoBoringSSL/include $out/include + + # Provide a CMake module. + mkdir -p $out/lib/cmake/SwiftCrypto + export dylibExt="${stdenv.hostPlatform.extensions.sharedLibrary}" + export swiftOs="${swiftOs}" + substituteAll ${./cmake-glue/SwiftCryptoConfig.cmake} $out/lib/cmake/SwiftCrypto/SwiftCryptoConfig.cmake + ''; + }; + + # Build a bootrapping swiftpm using CMake. + swiftpm-bootstrap = mkBootstrapDerivation (commonAttrs // { + pname = "swiftpm-bootstrap"; + + buildInputs = [ + llbuild + swift-argument-parser + swift-collections + swift-crypto + swift-driver + swift-system + swift-tools-support-core + ]; + + cmakeFlags = [ + "-DUSE_CMAKE_INSTALL=ON" + ]; + + postInstall = '' + for program in $out/bin/swift-*; do + wrapProgram $program --prefix PATH : ${lib.makeBinPath runtimeDeps} + done + ''; + }); + +# Build the final swiftpm with the bootstrapping swiftpm. +in stdenv.mkDerivation (commonAttrs // { + pname = "swiftpm"; + + nativeBuildInputs = commonAttrs.nativeBuildInputs ++ [ + swift + swiftpm-bootstrap + ]; + buildInputs = [ + ncursesInput + sqlite + XCTest + ] + ++ lib.optionals stdenv.isDarwin [ + CryptoKit + LocalAuthentication + ]; + + configurePhase = generated.configure + '' + # Functionality provided by Xcode XCTest, but not available in + # swift-corelibs-xctest. + swiftpmMakeMutable swift-tools-support-core + substituteInPlace .build/checkouts/swift-tools-support-core/Sources/TSCTestSupport/XCTestCasePerf.swift \ + --replace 'canImport(Darwin)' 'false' + ''; + + buildPhase = '' + # Required to link with swift-corelibs-xctest on Darwin. + export SWIFTTSC_MACOS_DEPLOYMENT_TARGET=10.12 + + TERM=dumb swift-build -c release + ''; + + # TODO: Tests depend on indexstore-db being provided by an existing Swift + # toolchain. (ie. looks for `../lib/libIndexStore.so` relative to swiftc. + #doCheck = true; + #checkPhase = '' + # TERM=dumb swift-test -c release + #''; + + # The following is dervied from Utilities/bootstrap, see install_swiftpm. + installPhase = '' + binPath="$(swift-build --show-bin-path -c release)" + + mkdir -p $out/bin $out/lib/swift + + cp $binPath/swift-package $out/bin/ + wrapProgram $out/bin/swift-package \ + --prefix PATH : ${lib.makeBinPath runtimeDeps} + for tool in swift-build swift-test swift-run swift-package-collection; do + ln -s $out/bin/swift-package $out/bin/$tool + done + + installSwiftpmModule() { + mkdir -p $out/lib/swift/pm/$2 + cp $binPath/lib$1${sharedLibraryExt} $out/lib/swift/pm/$2/ + + if [[ -f $binPath/$1.swiftinterface ]]; then + cp $binPath/$1.swiftinterface $out/lib/swift/pm/$2/ + else + cp -r $binPath/$1.swiftmodule $out/lib/swift/pm/$2/ + fi + cp $binPath/$1.swiftdoc $out/lib/swift/pm/$2/ + } + installSwiftpmModule PackageDescription ManifestAPI + installSwiftpmModule PackagePlugin PluginAPI + ''; + + setupHook = ./setup-hook.sh; + + meta = { + description = "The Package Manager for the Swift Programming Language"; + homepage = "https://github.com/apple/swift-package-manager"; + platforms = with lib.platforms; linux ++ darwin; + license = lib.licenses.asl20; + maintainers = with lib.maintainers; [ dtzWill trepetti dduan trundle stephank ]; + }; +}) diff --git a/pkgs/development/compilers/swift/swiftpm/generated/Package.resolved b/pkgs/development/compilers/swift/swiftpm/generated/Package.resolved new file mode 100644 index 000000000000..5eff23cf8c43 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/generated/Package.resolved @@ -0,0 +1,79 @@ +{ + "object": { + "pins": [ + { + "package": "swift-argument-parser", + "repositoryURL": "https://github.com/apple/swift-argument-parser.git", + "state": { + "branch": null, + "revision": "e394bf350e38cb100b6bc4172834770ede1b7232", + "version": "1.0.3" + } + }, + { + "package": "swift-collections", + "repositoryURL": "https://github.com/apple/swift-collections.git", + "state": { + "branch": null, + "revision": "f504716c27d2e5d4144fa4794b12129301d17729", + "version": "1.0.3" + } + }, + { + "package": "swift-crypto", + "repositoryURL": "https://github.com/apple/swift-crypto.git", + "state": { + "branch": null, + "revision": "ddb07e896a2a8af79512543b1c7eb9797f8898a5", + "version": "1.1.7" + } + }, + { + "package": "swift-driver", + "repositoryURL": "https://github.com/apple/swift-driver.git", + "state": { + "branch": "release/5.7", + "revision": "719426df790661020de657bf38beb2a8b1de5ad3", + "version": null + } + }, + { + "package": "llbuild", + "repositoryURL": "https://github.com/apple/swift-llbuild.git", + "state": { + "branch": "release/5.7", + "revision": "564424db5fdb62dcb5d863bdf7212500ef03a87b", + "version": null + } + }, + { + "package": "swift-system", + "repositoryURL": "https://github.com/apple/swift-system.git", + "state": { + "branch": null, + "revision": "836bc4557b74fe6d2660218d56e3ce96aff76574", + "version": "1.1.1" + } + }, + { + "package": "swift-tools-support-core", + "repositoryURL": "https://github.com/apple/swift-tools-support-core.git", + "state": { + "branch": "release/5.7", + "revision": "184eba382f6abbb362ffc02942d790ff35019ad4", + "version": null + } + }, + { + "package": "Yams", + "repositoryURL": "https://github.com/jpsim/Yams.git", + "state": { + "branch": null, + "revision": "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa", + "version": "4.0.6" + } + } + ] + }, + "version": 1 +} diff --git a/pkgs/development/compilers/swift/swiftpm/generated/default.nix b/pkgs/development/compilers/swift/swiftpm/generated/default.nix new file mode 100644 index 000000000000..b83d885738cf --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/generated/default.nix @@ -0,0 +1,62 @@ +# This file was generated by swiftpm2nix. +{ lib, fetchgit }: rec { + sources = { + "swift-argument-parser" = fetchgit { + url = "https://github.com/apple/swift-argument-parser.git"; + rev = "e394bf350e38cb100b6bc4172834770ede1b7232"; + sha256 = "1jph9w7lk9nr20fsv2c8p4hisx3dda817fh7pybd0r0j1jwa9nmw"; + }; + "swift-collections" = fetchgit { + url = "https://github.com/apple/swift-collections.git"; + rev = "f504716c27d2e5d4144fa4794b12129301d17729"; + sha256 = "0l0pv16zil3n7fac7mdf5qxklxr5rwiig5bixgca1ybq7arlnv7i"; + }; + "swift-crypto" = fetchgit { + url = "https://github.com/apple/swift-crypto.git"; + rev = "ddb07e896a2a8af79512543b1c7eb9797f8898a5"; + sha256 = "020b8q4ss2k7a65r5dgh59z40i6sn7ij1allxkh8c8a9d0jzn313"; + }; + "swift-driver" = fetchgit { + url = "https://github.com/apple/swift-driver.git"; + rev = "719426df790661020de657bf38beb2a8b1de5ad3"; + sha256 = "0cfz9g5mds8isn1simxal4vn3z7yh2kh6wg5267w3m0ifrcxfkmj"; + }; + "swift-llbuild" = fetchgit { + url = "https://github.com/apple/swift-llbuild.git"; + rev = "564424db5fdb62dcb5d863bdf7212500ef03a87b"; + sha256 = "07zbp2dyfqd1bnyg7snpr9brn40jf22ivly5v10mql3hrg76a18h"; + }; + "swift-system" = fetchgit { + url = "https://github.com/apple/swift-system.git"; + rev = "836bc4557b74fe6d2660218d56e3ce96aff76574"; + sha256 = "0402hkx2q2dv27gccnn8ma79ngvwiwzkhcv4zlcdldmy6cgi0px7"; + }; + "swift-tools-support-core" = fetchgit { + url = "https://github.com/apple/swift-tools-support-core.git"; + rev = "184eba382f6abbb362ffc02942d790ff35019ad4"; + sha256 = "005akmisnkcg6zjwm545183c12xm8z504yxxqmnqf0rakfcab1mi"; + }; + "Yams" = fetchgit { + url = "https://github.com/jpsim/Yams.git"; + rev = "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa"; + sha256 = "1893y13sis2aimi1a5kgkczbf06z4yig054xb565yg2xm13srb45"; + }; + }; + configure = '' + mkdir -p .build/checkouts + ln -sf ${./Package.resolved} ./Package.resolved + install -m 0600 ${./workspace-state.json} ./.build/workspace-state.json + '' + + lib.concatStrings (lib.mapAttrsToList (name: src: '' + ln -s '${src}' '.build/checkouts/${name}' + '') sources) + + '' + # Helper that makes a swiftpm dependency mutable by copying the source. + swiftpmMakeMutable() { + local orig="$(readlink .build/checkouts/$1)" + rm .build/checkouts/$1 + cp -r "$orig" .build/checkouts/$1 + chmod -R u+w .build/checkouts/$1 + } + ''; +} diff --git a/pkgs/development/compilers/swift/swiftpm/generated/workspace-state.json b/pkgs/development/compilers/swift/swiftpm/generated/workspace-state.json new file mode 100644 index 000000000000..69f3c07de4b0 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/generated/workspace-state.json @@ -0,0 +1,144 @@ +{ + "object": { + "artifacts": [], + "dependencies": [ + { + "basedOn": null, + "packageRef": { + "identity": "swift-argument-parser", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-argument-parser.git", + "name": "swift-argument-parser" + }, + "state": { + "checkoutState": { + "revision": "e394bf350e38cb100b6bc4172834770ede1b7232", + "version": "1.0.3" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-argument-parser" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-collections", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-collections.git", + "name": "swift-collections" + }, + "state": { + "checkoutState": { + "revision": "f504716c27d2e5d4144fa4794b12129301d17729", + "version": "1.0.3" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-collections" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-crypto", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-crypto.git", + "name": "swift-crypto" + }, + "state": { + "checkoutState": { + "revision": "ddb07e896a2a8af79512543b1c7eb9797f8898a5", + "version": "1.1.7" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-crypto" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-driver", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-driver.git", + "name": "swift-driver" + }, + "state": { + "checkoutState": { + "branch": "release/5.7", + "revision": "719426df790661020de657bf38beb2a8b1de5ad3" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-driver" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-llbuild", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-llbuild.git", + "name": "llbuild" + }, + "state": { + "checkoutState": { + "branch": "release/5.7", + "revision": "564424db5fdb62dcb5d863bdf7212500ef03a87b" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-llbuild" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-system", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-system.git", + "name": "swift-system" + }, + "state": { + "checkoutState": { + "revision": "836bc4557b74fe6d2660218d56e3ce96aff76574", + "version": "1.1.1" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-system" + }, + { + "basedOn": null, + "packageRef": { + "identity": "swift-tools-support-core", + "kind": "remoteSourceControl", + "location": "https://github.com/apple/swift-tools-support-core.git", + "name": "swift-tools-support-core" + }, + "state": { + "checkoutState": { + "branch": "release/5.7", + "revision": "184eba382f6abbb362ffc02942d790ff35019ad4" + }, + "name": "sourceControlCheckout" + }, + "subpath": "swift-tools-support-core" + }, + { + "basedOn": null, + "packageRef": { + "identity": "yams", + "kind": "remoteSourceControl", + "location": "https://github.com/jpsim/Yams.git", + "name": "Yams" + }, + "state": { + "checkoutState": { + "revision": "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa", + "version": "4.0.6" + }, + "name": "sourceControlCheckout" + }, + "subpath": "Yams" + } + ] + }, + "version": 5 +} diff --git a/pkgs/development/compilers/swift/swiftpm/patches/cmake-disable-rpath.patch b/pkgs/development/compilers/swift/swiftpm/patches/cmake-disable-rpath.patch new file mode 100644 index 000000000000..9aeba452f9e8 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/patches/cmake-disable-rpath.patch @@ -0,0 +1,36 @@ +Disable rpath for the bootstrap build with CMake. + +--- a/Sources/PackageDescription/CMakeLists.txt ++++ b/Sources/PackageDescription/CMakeLists.txt +@@ -31,14 +31,11 @@ if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) + set(SWIFT_INTERFACE_PATH ${CMAKE_BINARY_DIR}/pm/ManifestAPI/PackageDescription.swiftinterface) + target_compile_options(PackageDescription PUBLIC + $<$:-emit-module-interface-path$${SWIFT_INTERFACE_PATH}>) +- target_link_options(PackageDescription PRIVATE +- "SHELL:-Xlinker -install_name -Xlinker @rpath/libPackageDescription.dylib") + endif() + + set_target_properties(PackageDescription PROPERTIES + Swift_MODULE_NAME PackageDescription + Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/pm/ManifestAPI +- INSTALL_NAME_DIR \\@rpath + OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/ManifestAPI + OUTPUT_NAME PackageDescription + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/ManifestAPI +--- a/Sources/PackagePlugin/CMakeLists.txt ++++ b/Sources/PackagePlugin/CMakeLists.txt +@@ -29,14 +29,11 @@ if(CMAKE_HOST_SYSTEM_NAME STREQUAL Darwin) + set(SWIFT_INTERFACE_PATH ${CMAKE_BINARY_DIR}/pm/PluginAPI/PackagePlugin.swiftinterface) + target_compile_options(PackagePlugin PUBLIC + $<$:-emit-module-interface-path$${SWIFT_INTERFACE_PATH}>) +- target_link_options(PackagePlugin PRIVATE +- "SHELL:-Xlinker -install_name -Xlinker @rpath/libPackagePlugin.dylib") + endif() + + set_target_properties(PackagePlugin PROPERTIES + Swift_MODULE_NAME PackagePlugin + Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/pm/PluginAPI +- INSTALL_NAME_DIR \\@rpath + OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/PluginAPI + OUTPUT_NAME PackagePlugin + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/pm/PluginAPI diff --git a/pkgs/development/compilers/swift/swiftpm/patches/disable-sandbox.patch b/pkgs/development/compilers/swift/swiftpm/patches/disable-sandbox.patch new file mode 100644 index 000000000000..406e1d68d0e4 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/patches/disable-sandbox.patch @@ -0,0 +1,21 @@ +Nix may already sandbox the build, in which case sandbox_apply will fail. + +--- a/Sources/Basics/Sandbox.swift ++++ b/Sources/Basics/Sandbox.swift +@@ -30,12 +30,14 @@ public enum Sandbox { + readOnlyDirectories: [AbsolutePath] = [] + ) -> [String] { + #if os(macOS) ++ let env = ProcessInfo.processInfo.environment ++ if env["NIX_BUILD_TOP"] == nil || env["IN_NIX_SHELL"] != nil { + let profile = macOSSandboxProfile(strictness: strictness, writableDirectories: writableDirectories, readOnlyDirectories: readOnlyDirectories) + return ["/usr/bin/sandbox-exec", "-p", profile] + command +- #else ++ } ++ #endif + // rdar://40235432, rdar://75636874 tracks implementing sandboxes for other platforms. + return command +- #endif + } + + /// Basic strictness level of a sandbox applied to a command line. diff --git a/pkgs/development/compilers/swift/swiftpm/patches/disable-xctest.patch b/pkgs/development/compilers/swift/swiftpm/patches/disable-xctest.patch new file mode 100644 index 000000000000..e24d154d2987 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/patches/disable-xctest.patch @@ -0,0 +1,48 @@ +XCTest is not fully open-source, only the Swift library parts. We don't have a +command-line runner available, so disable support. + +--- a/Sources/Commands/TestingSupport.swift ++++ b/Sources/Commands/TestingSupport.swift +@@ -60,7 +60,7 @@ enum TestingSupport { + /// - Returns: Array of TestSuite + static func getTestSuites(fromTestAt path: AbsolutePath, swiftTool: SwiftTool, swiftOptions: SwiftToolOptions) throws -> [TestSuite] { + // Run the correct tool. +- #if os(macOS) ++ #if false + let data: String = try withTemporaryFile { tempFile in + let args = [try TestingSupport.xctestHelperPath(swiftTool: swiftTool).pathString, path.pathString, tempFile.path.pathString] + var env = try TestingSupport.constructTestEnvironment(toolchain: try swiftTool.getToolchain(), options: swiftOptions, buildParameters: swiftTool.buildParametersForTest()) +--- a/Sources/swiftpm-xctest-helper/main.swift ++++ b/Sources/swiftpm-xctest-helper/main.swift +@@ -9,8 +9,11 @@ + */ + + #if os(macOS) +-import XCTest + import func Darwin.C.exit ++print("Not supported in Nix.") ++exit(1) ++#if false ++import XCTest + + /// A helper tool to get list of tests from a XCTest Bundle on macOS. + /// +@@ -132,6 +135,7 @@ do { + exit(1) + } + ++#endif // nix + #else + + #if os(Windows) +--- a/Sources/PackageModel/Destination.swift ++++ b/Sources/PackageModel/Destination.swift +@@ -174,7 +174,7 @@ public struct Destination: Encodable, Equatable { + arguments: ["/usr/bin/xcrun", "--sdk", "macosx", "--show-sdk-platform-path"], + environment: environment).spm_chomp() + +- if let platformPath = platformPath, !platformPath.isEmpty { ++ if let platformPath = platformPath, !platformPath.isEmpty && !platformPath.starts(with: "@storeDir@") { + // For XCTest framework. + let fwk = AbsolutePath(platformPath).appending( + components: "Developer", "Library", "Frameworks") diff --git a/pkgs/development/compilers/swift/swiftpm/patches/fix-clang-cxx.patch b/pkgs/development/compilers/swift/swiftpm/patches/fix-clang-cxx.patch new file mode 100644 index 000000000000..60c4e33eb154 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/patches/fix-clang-cxx.patch @@ -0,0 +1,121 @@ +Swiftpm may invoke clang, not clang++, to compile C++. Our cc-wrapper also +doesn't pick up the arguments that enable C++ compilation in this case. Patch +swiftpm to properly invoke clang++. + +--- a/Sources/Build/LLBuildManifestBuilder.swift ++++ b/Sources/Build/LLBuildManifestBuilder.swift +@@ -782,7 +782,7 @@ extension LLBuildManifestBuilder { + + args += ["-c", path.source.pathString, "-o", path.object.pathString] + +- let clangCompiler = try buildParameters.toolchain.getClangCompiler().pathString ++ let clangCompiler = try buildParameters.toolchain.getClangCompiler(isCXX: isCXX).pathString + args.insert(clangCompiler, at: 0) + + let objectFileNode: Node = .file(path.object) +--- a/Sources/PackageModel/Destination.swift ++++ b/Sources/PackageModel/Destination.swift +@@ -153,7 +153,7 @@ public struct Destination: Encodable, Equatable { + + var extraCPPFlags: [String] = [] + #if os(macOS) +- extraCPPFlags += ["-lc++"] ++ extraCPPFlags += ["-lc++", "-lc++abi"] + #elseif os(Windows) + extraCPPFlags += [] + #else +--- a/Sources/PackageModel/Toolchain.swift ++++ b/Sources/PackageModel/Toolchain.swift +@@ -20,7 +20,7 @@ public protocol Toolchain { + var macosSwiftStdlib: AbsolutePath { get } + + /// Path of the `clang` compiler. +- func getClangCompiler() throws -> AbsolutePath ++ func getClangCompiler(isCXX: Bool) throws -> AbsolutePath + + // FIXME: This is a temporary API until index store is widely available in + // the OSS clang compiler. This API should not used for any other purpose. +--- a/Sources/PackageModel/UserToolchain.swift ++++ b/Sources/PackageModel/UserToolchain.swift +@@ -57,7 +57,7 @@ public final class UserToolchain: Toolchain { + /// Only use search paths, do not fall back to `xcrun`. + let useXcrun: Bool + +- private var _clangCompiler: AbsolutePath? ++ private var _clangCompiler: [Bool: AbsolutePath] = [:] + + private let environment: EnvironmentVariables + +@@ -150,29 +150,31 @@ public final class UserToolchain: Toolchain { + } + + /// Returns the path to clang compiler tool. +- public func getClangCompiler() throws -> AbsolutePath { ++ public func getClangCompiler(isCXX: Bool) throws -> AbsolutePath { + // Check if we already computed. +- if let clang = self._clangCompiler { ++ if let clang = self._clangCompiler[isCXX] { + return clang + } + + // Check in the environment variable first. +- if let toolPath = UserToolchain.lookup(variable: "CC", searchPaths: self.envSearchPaths, environment: environment) { +- self._clangCompiler = toolPath ++ let envVar = isCXX ? "CXX" : "CC"; ++ if let toolPath = UserToolchain.lookup(variable: envVar, searchPaths: self.envSearchPaths, environment: environment) { ++ self._clangCompiler[isCXX] = toolPath + return toolPath + } + + // Then, check the toolchain. ++ let tool = isCXX ? "clang++" : "clang"; + do { +- if let toolPath = try? UserToolchain.getTool("clang", binDir: self.destination.binDir) { +- self._clangCompiler = toolPath ++ if let toolPath = try? UserToolchain.getTool(tool, binDir: self.destination.binDir) { ++ self._clangCompiler[isCXX] = toolPath + return toolPath + } + } + + // Otherwise, lookup it up on the system. +- let toolPath = try UserToolchain.findTool("clang", envSearchPaths: self.envSearchPaths, useXcrun: useXcrun) +- self._clangCompiler = toolPath ++ let toolPath = try UserToolchain.findTool(tool, envSearchPaths: self.envSearchPaths, useXcrun: useXcrun) ++ self._clangCompiler[isCXX] = toolPath + return toolPath + } + +--- a/Sources/SPMBuildCore/BuildParameters.swift ++++ b/Sources/SPMBuildCore/BuildParameters.swift +@@ -342,7 +342,7 @@ private struct _Toolchain: Encodable { + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(toolchain.swiftCompilerPath, forKey: .swiftCompiler) +- try container.encode(toolchain.getClangCompiler(), forKey: .clangCompiler) ++ try container.encode(toolchain.getClangCompiler(isCXX: false), forKey: .clangCompiler) + + try container.encode(toolchain.extraCCFlags, forKey: .extraCCFlags) + try container.encode(toolchain.extraCPPFlags, forKey: .extraCPPFlags) +--- a/Sources/XCBuildSupport/XcodeBuildSystem.swift ++++ b/Sources/XCBuildSupport/XcodeBuildSystem.swift +@@ -172,7 +172,7 @@ public final class XcodeBuildSystem: SPMBuildCore.BuildSystem { + // Generate a table of any overriding build settings. + var settings: [String: String] = [:] + // An error with determining the override should not be fatal here. +- settings["CC"] = try? buildParameters.toolchain.getClangCompiler().pathString ++ settings["CC"] = try? buildParameters.toolchain.getClangCompiler(isCXX: false).pathString + // Always specify the path of the effective Swift compiler, which was determined in the same way as for the native build system. + settings["SWIFT_EXEC"] = buildParameters.toolchain.swiftCompilerPath.pathString + settings["LIBRARY_SEARCH_PATHS"] = "$(inherited) \(buildParameters.toolchain.toolchainLibDir.pathString)" +--- a/Tests/BuildTests/MockBuildTestHelper.swift ++++ b/Tests/BuildTests/MockBuildTestHelper.swift +@@ -15,7 +15,7 @@ struct MockToolchain: PackageModel.Toolchain { + #else + let extraCPPFlags: [String] = ["-lstdc++"] + #endif +- func getClangCompiler() throws -> AbsolutePath { ++ func getClangCompiler(isCXX: Bool) throws -> AbsolutePath { + return AbsolutePath("/fake/path/to/clang") + } + diff --git a/pkgs/development/compilers/swift/swiftpm/patches/fix-stdlib-path.patch b/pkgs/development/compilers/swift/swiftpm/patches/fix-stdlib-path.patch new file mode 100644 index 000000000000..327ccf37e425 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/patches/fix-stdlib-path.patch @@ -0,0 +1,23 @@ +Swiftpm looks for the Swift stdlib relative to the swift compiler, but that's a +wrapper in our case. It wants to add the stdlib to the rpath, which is +necessary for back-deployment of some features. + +--- a/Sources/PackageModel/Toolchain.swift ++++ b/Sources/PackageModel/Toolchain.swift +@@ -43,10 +43,16 @@ extension Toolchain { + } + + public var macosSwiftStdlib: AbsolutePath { ++ if swiftCompilerPath.pathString.starts(with: "@storeDir@") { ++ return AbsolutePath("@swiftLib@/lib/swift/macosx") ++ } + return AbsolutePath("../../lib/swift/macosx", relativeTo: resolveSymlinks(swiftCompilerPath)) + } + + public var toolchainLibDir: AbsolutePath { ++ if swiftCompilerPath.pathString.starts(with: "@storeDir@") { ++ return AbsolutePath("@swiftLib@/lib") ++ } + // FIXME: Not sure if it's better to base this off of Swift compiler or our own binary. + return AbsolutePath("../../lib", relativeTo: resolveSymlinks(swiftCompilerPath)) + } diff --git a/pkgs/development/compilers/swift/swiftpm/patches/llbuild-cmake-disable-rpath.patch b/pkgs/development/compilers/swift/swiftpm/patches/llbuild-cmake-disable-rpath.patch new file mode 100644 index 000000000000..785e82cc34b6 --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/patches/llbuild-cmake-disable-rpath.patch @@ -0,0 +1,14 @@ +Specifying `-platform_version` targeting macos before 10.15 causes cctools ld +to link with `@rpath`. This may have something to do with Swift ABI stability. + +--- a/products/llbuildSwift/CMakeLists.txt ++++ b/products/llbuildSwift/CMakeLists.txt +@@ -22,7 +17,7 @@ endif() + + # TODO(compnerd) move both of these outside of the CMake into the invocation + if(CMAKE_SYSTEM_NAME STREQUAL Darwin) +- add_compile_options(-target ${CMAKE_OSX_ARCHITECTURES}-apple-macosx10.10) ++ add_compile_options(-target ${CMAKE_OSX_ARCHITECTURES}-apple-macosx10.15) + if(NOT CMAKE_OSX_SYSROOT STREQUAL "") + add_compile_options(-sdk ${CMAKE_OSX_SYSROOT}) + endif() diff --git a/pkgs/development/compilers/swift/swiftpm/setup-hook.sh b/pkgs/development/compilers/swift/swiftpm/setup-hook.sh new file mode 100644 index 000000000000..654887d930ca --- /dev/null +++ b/pkgs/development/compilers/swift/swiftpm/setup-hook.sh @@ -0,0 +1,60 @@ +# Build using 'swift-build'. +swiftpmBuildPhase() { + runHook preBuild + + local buildCores=1 + if [ "${enableParallelBuilding-1}" ]; then + buildCores="$NIX_BUILD_CORES" + fi + + local flagsArray=( + -j $buildCores + -c "${swiftpmBuildConfig-release}" + $swiftpmFlags "${swiftpmFlagsArray[@]}" + ) + + echoCmd 'build flags' "${flagsArray[@]}" + TERM=dumb swift-build "${flagsArray[@]}" + + runHook postBuild +} + +if [ -z "${dontUseSwiftpmBuild-}" -a -z "${buildPhase-}" ]; then + buildPhase=swiftpmBuildPhase +fi + +# Check using 'swift-test'. +swiftpmCheckPhase() { + runHook preCheck + + local buildCores=1 + if [ "${enableParallelBuilding-1}" ]; then + buildCores="$NIX_BUILD_CORES" + fi + + local flagsArray=( + -j $buildCores + -c "${swiftpmBuildConfig-release}" + $swiftpmFlags "${swiftpmFlagsArray[@]}" + ) + + echoCmd 'check flags' "${flagsArray[@]}" + TERM=dumb swift-test "${flagsArray[@]}" + + runHook postCheck +} + +if [ -z "${dontUseSwiftpmCheck-}" -a -z "${checkPhase-}" ]; then + checkPhase=swiftpmCheckPhase +fi + +# Helper used to find the binary output path. +# Useful for performing the installPhase of swiftpm packages. +swiftpmBinPath() { + local flagsArray=( + -c "${swiftpmBuildConfig-release}" + $swiftpmFlags "${swiftpmFlagsArray[@]}" + ) + + swift-build --show-bin-path "${flagsArray[@]}" +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6af03574ebcb..21c57e3e5480 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15042,7 +15042,7 @@ with pkgs; svdtools = callPackage ../development/embedded/svdtools { }; swiftPackages = recurseIntoAttrs (callPackage ../development/compilers/swift { }); - inherit (swiftPackages) swift; + inherit (swiftPackages) swift swiftpm; swiftpm2nix = callPackage ../development/tools/swiftpm2nix { };