From 860cbce30dfe1a32fd00943cfbba97c7af7cb54d Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Thu, 6 Aug 2026 19:56:05 -0400 Subject: [PATCH] swiftPackages_ng.swiftpm: init at 6.2.4 --- .../swift_ng/by-name/sw/swiftpm/package.nix | 174 +++++++++ .../patches/0001-gnu-install-dirs.patch | 362 ++++++++++++++++++ .../0002-darwin-swift-corelibs-xctest.patch | 102 +++++ .../patches/0003-disable-sandbox.patch | 47 +++ .../patches/0005-fix-manifest-path.patch | 31 ++ .../patches/0006-nix-build-caches.patch | 36 ++ .../patches/0007-nix-pkgconfig-vars.patch | 41 ++ .../patches/0008-set-compiler-vendor.patch | 30 ++ .../patches/0009-add-missing-libraries.patch | 45 +++ .../0010-Load-IndexStore-from-the-store.patch | 35 ++ ...1-Always-find-Clang-in-the-toolchain.patch | 40 ++ .../backdeploy-references-stdlib/package.nix | 53 +++ .../src/Package.swift | 14 + .../src/Sources/main.swift | 11 + .../compilers/swift_ng/sources-6.2.json | 3 + 15 files changed, 1024 insertions(+) create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/package.nix create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0001-gnu-install-dirs.patch create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0002-darwin-swift-corelibs-xctest.patch create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0003-disable-sandbox.patch create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0005-fix-manifest-path.patch create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0006-nix-build-caches.patch create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0007-nix-pkgconfig-vars.patch create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0008-set-compiler-vendor.patch create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0009-add-missing-libraries.patch create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0010-Load-IndexStore-from-the-store.patch create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0011-Always-find-Clang-in-the-toolchain.patch create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/package.nix create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/src/Package.swift create mode 100644 pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/src/Sources/main.swift diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/package.nix b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/package.nix new file mode 100644 index 000000000000..e80082a64aef --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/package.nix @@ -0,0 +1,174 @@ +{ + lib, + callPackage, + cmake, + fetchFromGitHub, + fetchpatch2, + llvmPackages, + ninja, + replaceVars, + sqlite, + stdenv, + swift, + swift-argument-parser, + swift-asn1, + swift-build, + swift-certificates, + swift-collections, + swift-crypto, + swift-driver, + swift-llbuild, + swift-syntax, + swift-system, + swift-tools-support-core, + swift_release, + swift_sources, +}: + +let + swift-syntax-no-toolchain = swift-syntax.override { useToolchainLibraries = false; }; + + rpaths = lib.makeLibraryPath [ + sqlite + swift-argument-parser + swift-asn1 + swift-build + swift-certificates + swift-collections + swift-crypto + swift-driver + swift-llbuild + swift-syntax-no-toolchain + swift-system + swift-tools-support-core + ]; +in + +stdenv.mkDerivation (finalAttrs: { + pname = "swiftpm"; + version = swift_release; + + outputs = [ + "out" + "dev" + ]; + + src = fetchFromGitHub { + owner = "swiftlang"; + repo = "swift-package-manager"; + tag = "swift-${finalAttrs.version}-RELEASE"; + inherit (swift_sources.swift-package-manager) hash; + }; + + patches = [ + ./patches/0001-gnu-install-dirs.patch + # Use swift-corelibs-xctest even on Darwin (because XCTest.framework is not available in nixpkgs). + ./patches/0002-darwin-swift-corelibs-xctest.patch + # SwiftPM tries to use `sandbox-exec` for sandboxing, which will fail when it is run in the Nix sandbox. + ./patches/0003-disable-sandbox.patch + # SwiftPM falls back to looking for manifests and plugins in the Swift compiler location. Find them in $out. + ./patches/0005-fix-manifest-path.patch + # Silence warnings about not finding the cache folder when building packages by moving it to $NIX_BUILD_TOP. + ./patches/0006-nix-build-caches.patch + # SwiftPM does its own `.pc` parsing, so it avoids the `pkg-config` wrapper used in nixpkgs to support + # cross-compilation. This patch adds support for `"PKG_CONFIG_PATH_FOR_TARGET` to SwiftPM. + ./patches/0007-nix-pkgconfig-vars.patch + # SwiftPM assumes that you are using Apple Clang on macOS, but nixpkgs builds Clang from upstream LLVM. + # This effectively disables using `-index-store-path`, which isn’t supported by LLVM’s Clang. + ./patches/0008-set-compiler-vendor.patch + # A couple of required libraries are missing from the `CMakeLists.txt` files. + ./patches/0009-add-missing-libraries.patch + # SwiftPM tries to load IndexStoreDB from the toolchain, but load it from the store instead. + (replaceVars ./patches/0010-Load-IndexStore-from-the-store.patch { + libclang = lib.getLib llvmPackages.libclang; + }) + # SwiftPM tries to find Clang via `CC`, but that can be GCC on Linux, which doesn’t actually work with SwiftPM. + ./patches/0011-Always-find-Clang-in-the-toolchain.patch + # Build missing `swift-package-collection` and `swift-package-registry` binaries. + (fetchpatch2 { + url = "https://github.com/swiftlang/swift-package-manager/commit/e1910f814cc1be40c709c3987a29488b9bee2f92.patch?full_index=1"; + hash = "sha256-4Ew/cKlk+Zn8cIQvh0jQy4Fz+xGYBYwch4+SBu1nKpI="; + }) + ]; + + postPatch = '' + # Need to reference $out, so this can’t be substituted by `replaceVars`. + substituteInPlace Sources/PackageModel/UserToolchain.swift \ + --replace-fail '@out@' "$out" + + # Replace hardcoded references to `xcrun` with `PATH`-based references. + find Sources -name '*.swift' -exec sed -i '{}' -e 's|/usr/bin/xcrun|xcrun|g' \; + + # Set the deployment target when building package manifests to one supported in nixpkgs. + substituteInPlace Sources/PackageLoading/ManifestLoader.swift \ + --replace-fail '.tripleString(forPlatformVersion: version)' ".tripleString(forPlatformVersion: \"$MACOSX_DEPLOYMENT_TARGET\")" + ''; + + strictDeps = true; + + preConfigure = '' + appendToVar cmakeFlags -DCMAKE_Swift_COMPILER_TARGET=${stdenv.hostPlatform.swift.triple} + appendToVar cmakeFlags -DCMAKE_Swift_FLAGS=-module-cache-path\ "$NIX_BUILD_TOP/module-cache" + ''; + + nativeBuildInputs = [ + cmake + ninja + swift + ]; + + buildInputs = [ + sqlite + swift-argument-parser + swift-asn1 + swift-build + swift-certificates + swift-collections + swift-crypto + swift-driver + swift-llbuild + swift-syntax-no-toolchain + swift-system + swift-tools-support-core + ]; + + postInstall = + lib.optionalString stdenv.hostPlatform.isDarwin '' + # Replace `@rpath` with absolute paths on Darwin. For some reason, this isn’t always done during installation. + # `fixDarwinDylibNames` doesn’t work either. + IFS= readarray -d "" dylibs < <(find "$out" -type f -and -name '*.dylib' -print0) + declare -a mappings + + for dylib in "''${dylibs[@]}"; do + mappings+=(-change "@rpath/$(basename "$dylib")" "$dylib") + done + + for dylib in "''${dylibs[@]}"; do + install_name_tool "$dylib" ''${mappings[@]} + done + '' + + lib.optionalString stdenv.hostPlatform.isElf '' + for output in "''${outputs[@]}"; do + while IFS= read -d "" f; do + if isELF "$f"; then + patchelf --add-rpath ${lib.escapeShellArg rpaths} "$f" + fi + done < <(find "$output" -type f -print0) + done + ''; + + passthru.tests = lib.packagesFromDirectoryRecursive { + inherit callPackage; + directory = ./tests; + }; + + __structuredAttrs = true; + + meta = { + description = "Package Manager for the Swift Programming Language"; + homepage = "https://github.com/swiftlang/swift-package-manager"; + inherit (swift.meta) badPlatforms platforms; + license = lib.licenses.asl20; + maintainers = lib.teams.swift.members; + }; +}) diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0001-gnu-install-dirs.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0001-gnu-install-dirs.patch new file mode 100644 index 000000000000..5851bb9b15a4 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0001-gnu-install-dirs.patch @@ -0,0 +1,362 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Fri, 19 Dec 2025 20:12:12 -0500 +Subject: [PATCH 01/11] gnu-install-dirs + +--- + Sources/Basics/CMakeLists.txt | 6 +++--- + Sources/Build/CMakeLists.txt | 6 +++--- + Sources/Commands/CMakeLists.txt | 6 +++--- + Sources/CoreCommands/CMakeLists.txt | 6 +++--- + Sources/DriverSupport/CMakeLists.txt | 6 +++--- + Sources/PackageCollections/CMakeLists.txt | 6 +++--- + Sources/PackageCollectionsModel/CMakeLists.txt | 6 +++--- + Sources/PackageCollectionsSigning/CMakeLists.txt | 6 +++--- + Sources/PackageGraph/CMakeLists.txt | 6 +++--- + Sources/PackageLoading/CMakeLists.txt | 6 +++--- + Sources/PackageModel/CMakeLists.txt | 6 +++--- + Sources/PackageModelSyntax/CMakeLists.txt | 6 +++--- + Sources/PackageRegistryCommand/CMakeLists.txt | 6 +++--- + Sources/QueryEngine/CMakeLists.txt | 6 +++--- + Sources/SPMBuildCore/CMakeLists.txt | 6 +++--- + Sources/SourceControl/CMakeLists.txt | 6 +++--- + Sources/SwiftSDKCommand/CMakeLists.txt | 6 +++--- + Sources/Workspace/CMakeLists.txt | 6 +++--- + Sources/_AsyncFileSystem/CMakeLists.txt | 6 +++--- + Sources/swift-experimental-sdk/CMakeLists.txt | 2 +- + Sources/swift-package/CMakeLists.txt | 2 +- + Sources/swift-run/CMakeLists.txt | 2 +- + Sources/swift-sdk/CMakeLists.txt | 2 +- + Sources/swift-test/CMakeLists.txt | 2 +- + 24 files changed, 62 insertions(+), 62 deletions(-) + +diff --git a/Sources/Basics/CMakeLists.txt b/Sources/Basics/CMakeLists.txt +index e2910d09b..2f523dedb 100644 +--- a/Sources/Basics/CMakeLists.txt ++++ b/Sources/Basics/CMakeLists.txt +@@ -97,7 +97,7 @@ target_link_options(Basics PRIVATE + "$<$:SHELL:-Xlinker -framework -Xlinker Security>") + + install(TARGETS Basics +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS Basics) +diff --git a/Sources/Build/CMakeLists.txt b/Sources/Build/CMakeLists.txt +index 495bd7a87..9b32067ff 100644 +--- a/Sources/Build/CMakeLists.txt ++++ b/Sources/Build/CMakeLists.txt +@@ -49,7 +49,7 @@ set_target_properties(Build PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + install(TARGETS Build +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS Build) +diff --git a/Sources/Commands/CMakeLists.txt b/Sources/Commands/CMakeLists.txt +index c62c7424e..5efcc760d 100644 +--- a/Sources/Commands/CMakeLists.txt ++++ b/Sources/Commands/CMakeLists.txt +@@ -80,6 +80,6 @@ set_target_properties(Commands PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + install(TARGETS Commands +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/CoreCommands/CMakeLists.txt b/Sources/CoreCommands/CMakeLists.txt +index 54bc10b2b..dbaadcb3f 100644 +--- a/Sources/CoreCommands/CMakeLists.txt ++++ b/Sources/CoreCommands/CMakeLists.txt +@@ -29,6 +29,6 @@ set_target_properties(CoreCommands PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + install(TARGETS CoreCommands +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/DriverSupport/CMakeLists.txt b/Sources/DriverSupport/CMakeLists.txt +index 1044df0e9..29234574c 100644 +--- a/Sources/DriverSupport/CMakeLists.txt ++++ b/Sources/DriverSupport/CMakeLists.txt +@@ -18,7 +18,7 @@ target_link_libraries(DriverSupport PUBLIC + SwiftDriver) + + install(TARGETS DriverSupport +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS DriverSupport) +diff --git a/Sources/PackageCollections/CMakeLists.txt b/Sources/PackageCollections/CMakeLists.txt +index 63eb94c2f..4f3c183e4 100644 +--- a/Sources/PackageCollections/CMakeLists.txt ++++ b/Sources/PackageCollections/CMakeLists.txt +@@ -56,6 +56,6 @@ if(NOT APPLE) + endif() + + install(TARGETS PackageCollections +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/PackageCollectionsModel/CMakeLists.txt b/Sources/PackageCollectionsModel/CMakeLists.txt +index 9f98827a5..c99c5d81c 100644 +--- a/Sources/PackageCollectionsModel/CMakeLists.txt ++++ b/Sources/PackageCollectionsModel/CMakeLists.txt +@@ -20,6 +20,6 @@ if(NOT APPLE) + endif() + + install(TARGETS PackageCollectionsModel +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/PackageCollectionsSigning/CMakeLists.txt b/Sources/PackageCollectionsSigning/CMakeLists.txt +index 5f3d69abe..7390bb783 100644 +--- a/Sources/PackageCollectionsSigning/CMakeLists.txt ++++ b/Sources/PackageCollectionsSigning/CMakeLists.txt +@@ -36,6 +36,6 @@ if(NOT APPLE) + endif() + + install(TARGETS PackageCollectionsSigning +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/PackageGraph/CMakeLists.txt b/Sources/PackageGraph/CMakeLists.txt +index 46bd6580f..4e7a5e04d 100644 +--- a/Sources/PackageGraph/CMakeLists.txt ++++ b/Sources/PackageGraph/CMakeLists.txt +@@ -51,7 +51,7 @@ set_target_properties(PackageGraph PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + install(TARGETS PackageGraph +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS PackageGraph) +diff --git a/Sources/PackageLoading/CMakeLists.txt b/Sources/PackageLoading/CMakeLists.txt +index 476588dbf..f363cd12d 100644 +--- a/Sources/PackageLoading/CMakeLists.txt ++++ b/Sources/PackageLoading/CMakeLists.txt +@@ -36,7 +36,7 @@ set_target_properties(PackageLoading PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + install(TARGETS PackageLoading +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS PackageLoading) +diff --git a/Sources/PackageModel/CMakeLists.txt b/Sources/PackageModel/CMakeLists.txt +index 48ff3b9ba..3c2e305a9 100644 +--- a/Sources/PackageModel/CMakeLists.txt ++++ b/Sources/PackageModel/CMakeLists.txt +@@ -75,7 +75,7 @@ set_target_properties(PackageModel PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + install(TARGETS PackageModel +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS PackageModel) +diff --git a/Sources/PackageModelSyntax/CMakeLists.txt b/Sources/PackageModelSyntax/CMakeLists.txt +index 02142c690..70dcf942c 100644 +--- a/Sources/PackageModelSyntax/CMakeLists.txt ++++ b/Sources/PackageModelSyntax/CMakeLists.txt +@@ -39,7 +39,7 @@ set_target_properties(PackageModelSyntax PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + install(TARGETS PackageModelSyntax +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS PackageModelSyntax) +diff --git a/Sources/PackageRegistryCommand/CMakeLists.txt b/Sources/PackageRegistryCommand/CMakeLists.txt +index 92c7785ed..a62300a1a 100644 +--- a/Sources/PackageRegistryCommand/CMakeLists.txt ++++ b/Sources/PackageRegistryCommand/CMakeLists.txt +@@ -34,6 +34,6 @@ if(NOT APPLE) + endif() + + install(TARGETS PackageRegistryCommand +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/QueryEngine/CMakeLists.txt b/Sources/QueryEngine/CMakeLists.txt +index 869c52c45..36d71c89c 100644 +--- a/Sources/QueryEngine/CMakeLists.txt ++++ b/Sources/QueryEngine/CMakeLists.txt +@@ -27,6 +27,6 @@ if(NOT APPLE) + endif() + + install(TARGETS QueryEngine +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/SPMBuildCore/CMakeLists.txt b/Sources/SPMBuildCore/CMakeLists.txt +index eaf92ddd1..ed7f25ca9 100644 +--- a/Sources/SPMBuildCore/CMakeLists.txt ++++ b/Sources/SPMBuildCore/CMakeLists.txt +@@ -40,7 +40,7 @@ target_link_libraries(SPMBuildCore PUBLIC + + + install(TARGETS SPMBuildCore +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS SPMBuildCore) +diff --git a/Sources/SourceControl/CMakeLists.txt b/Sources/SourceControl/CMakeLists.txt +index 8e1377d9b..e660bae2d 100644 +--- a/Sources/SourceControl/CMakeLists.txt ++++ b/Sources/SourceControl/CMakeLists.txt +@@ -22,7 +22,7 @@ set_target_properties(SourceControl PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + install(TARGETS SourceControl +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS SourceControl) +diff --git a/Sources/SwiftSDKCommand/CMakeLists.txt b/Sources/SwiftSDKCommand/CMakeLists.txt +index 4dcfa36a2..ccca0ac3b 100644 +--- a/Sources/SwiftSDKCommand/CMakeLists.txt ++++ b/Sources/SwiftSDKCommand/CMakeLists.txt +@@ -29,6 +29,6 @@ set_target_properties(SwiftSDKCommand PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + install(TARGETS SwiftSDKCommand +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/Workspace/CMakeLists.txt b/Sources/Workspace/CMakeLists.txt +index cdc939112..78b79ac25 100644 +--- a/Sources/Workspace/CMakeLists.txt ++++ b/Sources/Workspace/CMakeLists.txt +@@ -62,6 +62,6 @@ set_target_properties(Workspace PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + install(TARGETS Workspace +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/_AsyncFileSystem/CMakeLists.txt b/Sources/_AsyncFileSystem/CMakeLists.txt +index adf09b29c..ad2ce7c4a 100644 +--- a/Sources/_AsyncFileSystem/CMakeLists.txt ++++ b/Sources/_AsyncFileSystem/CMakeLists.txt +@@ -24,8 +24,8 @@ set_target_properties(_AsyncFileSystem PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + + install(TARGETS _AsyncFileSystem +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS _AsyncFileSystem) +diff --git a/Sources/swift-experimental-sdk/CMakeLists.txt b/Sources/swift-experimental-sdk/CMakeLists.txt +index edad12be8..f07bd15a7 100644 +--- a/Sources/swift-experimental-sdk/CMakeLists.txt ++++ b/Sources/swift-experimental-sdk/CMakeLists.txt +@@ -15,4 +15,4 @@ target_compile_options(swift-experimental-sdk PRIVATE + -parse-as-library) + + install(TARGETS swift-experimental-sdk +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/swift-package/CMakeLists.txt b/Sources/swift-package/CMakeLists.txt +index 3468bdefc..4b4a8d190 100644 +--- a/Sources/swift-package/CMakeLists.txt ++++ b/Sources/swift-package/CMakeLists.txt +@@ -16,4 +16,4 @@ target_compile_options(swift-package PRIVATE + -parse-as-library) + + install(TARGETS swift-package +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/swift-run/CMakeLists.txt b/Sources/swift-run/CMakeLists.txt +index 9c609f84e..719a2228a 100644 +--- a/Sources/swift-run/CMakeLists.txt ++++ b/Sources/swift-run/CMakeLists.txt +@@ -15,4 +15,4 @@ target_compile_options(swift-run PRIVATE + -parse-as-library) + + install(TARGETS swift-run +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/swift-sdk/CMakeLists.txt b/Sources/swift-sdk/CMakeLists.txt +index ee3be128b..4ed4a522a 100644 +--- a/Sources/swift-sdk/CMakeLists.txt ++++ b/Sources/swift-sdk/CMakeLists.txt +@@ -15,4 +15,4 @@ target_compile_options(swift-sdk PRIVATE + -parse-as-library) + + install(TARGETS swift-sdk +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +diff --git a/Sources/swift-test/CMakeLists.txt b/Sources/swift-test/CMakeLists.txt +index 79c910294..ef2305587 100644 +--- a/Sources/swift-test/CMakeLists.txt ++++ b/Sources/swift-test/CMakeLists.txt +@@ -15,4 +15,4 @@ target_compile_options(swift-test PRIVATE + -parse-as-library) + + install(TARGETS swift-test +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0002-darwin-swift-corelibs-xctest.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0002-darwin-swift-corelibs-xctest.patch new file mode 100644 index 000000000000..475cb0b2c893 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0002-darwin-swift-corelibs-xctest.patch @@ -0,0 +1,102 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sat, 13 Dec 2025 22:57:10 -0500 +Subject: [PATCH 02/11] darwin-swift-corelibs-xctest + +--- + .../Commands/Utilities/TestingSupport.swift | 65 ------------------- + 1 file changed, 65 deletions(-) + +diff --git a/Sources/Commands/Utilities/TestingSupport.swift b/Sources/Commands/Utilities/TestingSupport.swift +index 81b329613..536babca5 100644 +--- a/Sources/Commands/Utilities/TestingSupport.swift ++++ b/Sources/Commands/Utilities/TestingSupport.swift +@@ -29,46 +29,6 @@ import func TSCBasic.withTemporaryFile + /// Note: In the long term this should be factored into a reusable module that + /// can run and report results on tests from both CLI and libSwiftPM API. + enum TestingSupport { +- /// Locates XCTestHelper tool inside the libexec directory and bin directory. +- /// Note: It is a fatalError if we are not able to locate the tool. +- /// +- /// - Returns: Path to XCTestHelper tool. +- static func xctestHelperPath(swiftCommandState: SwiftCommandState) throws -> AbsolutePath { +- var triedPaths = [AbsolutePath]() +- +- func findXCTestHelper(swiftBuildPath: AbsolutePath) -> AbsolutePath? { +- // XCTestHelper tool is installed in libexec. +- let maybePath = swiftBuildPath.parentDirectory.parentDirectory.appending( +- components: "libexec", "swift", "pm", "swiftpm-xctest-helper" +- ) +- if swiftCommandState.fileSystem.isFile(maybePath) { +- return maybePath +- } else { +- triedPaths.append(maybePath) +- return nil +- } +- } +- +- if let firstCLIArgument = CommandLine.arguments.first { +- let runningSwiftBuildPath = try AbsolutePath(validating: firstCLIArgument, relativeTo: swiftCommandState.originalWorkingDirectory) +- if let xctestHelperPath = findXCTestHelper(swiftBuildPath: runningSwiftBuildPath) { +- return xctestHelperPath +- } +- } +- +- // This will be true during swiftpm development or when using swift.org toolchains. +- let xcodePath = try AsyncProcess.checkNonZeroExit(args: "/usr/bin/xcode-select", "--print-path").spm_chomp() +- let installedSwiftBuildPath = try AsyncProcess.checkNonZeroExit( +- args: "/usr/bin/xcrun", "--find", "swift-build", +- environment: ["DEVELOPER_DIR": xcodePath] +- ).spm_chomp() +- if let xctestHelperPath = findXCTestHelper(swiftBuildPath: try AbsolutePath(validating: installedSwiftBuildPath)) { +- return xctestHelperPath +- } +- +- throw InternalError("XCTestHelper binary not found, tried \(triedPaths.map { $0.pathString }.joined(separator: ", "))") +- } +- + static func getTestSuites( + in testProducts: [BuiltTestProduct], + swiftCommandState: SwiftCommandState, +@@ -112,30 +72,6 @@ enum TestingSupport { + ) throws -> [TestSuite] { + // Run the correct tool. + var args = [String]() +- #if os(macOS) +- let data: String = try withTemporaryFile { tempFile in +- args = [try Self.xctestHelperPath(swiftCommandState: swiftCommandState).pathString, path.pathString, tempFile.path.pathString] +- let env = try Self.constructTestEnvironment( +- toolchain: try swiftCommandState.getTargetToolchain(), +- destinationBuildParameters: swiftCommandState.buildParametersForTest( +- enableCodeCoverage: enableCodeCoverage, +- shouldSkipBuilding: shouldSkipBuilding, +- experimentalTestOutput: experimentalTestOutput +- ).productsBuildParameters, +- sanitizers: sanitizers, +- library: .xctest +- ) +- try Self.runProcessWithExistenceCheck( +- path: path, +- fileSystem: swiftCommandState.fileSystem, +- args: args, +- env: env +- ) +- +- // Read the temporary file's content. +- return try swiftCommandState.fileSystem.readFileContents(AbsolutePath(tempFile.path)) +- } +- #else + let env = try Self.constructTestEnvironment( + toolchain: try swiftCommandState.getTargetToolchain(), + destinationBuildParameters: swiftCommandState.buildParametersForTest( +@@ -152,7 +88,6 @@ enum TestingSupport { + args: args, + env: env + ) +- #endif + // Parse json and return TestSuites. + return try TestSuite.parse(jsonString: data, context: args.joined(separator: " ")) + } +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0003-disable-sandbox.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0003-disable-sandbox.patch new file mode 100644 index 000000000000..dd9952255e9d --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0003-disable-sandbox.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sat, 13 Dec 2025 22:57:33 -0500 +Subject: [PATCH 03/11] disable-sandbox + +--- + Sources/Basics/Sandbox.swift | 22 ++++++++++++---------- + 1 file changed, 12 insertions(+), 10 deletions(-) + +diff --git a/Sources/Basics/Sandbox.swift b/Sources/Basics/Sandbox.swift +index f24636cac..8b65b2489 100644 +--- a/Sources/Basics/Sandbox.swift ++++ b/Sources/Basics/Sandbox.swift +@@ -57,18 +57,20 @@ public enum Sandbox { + allowNetworkConnections: [SandboxNetworkPermission] = [] + ) throws -> [String] { + #if os(macOS) +- let profile = try macOSSandboxProfile( +- fileSystem: fileSystem, +- strictness: strictness, +- writableDirectories: writableDirectories, +- readOnlyDirectories: readOnlyDirectories, +- allowNetworkConnections: allowNetworkConnections +- ) +- return ["/usr/bin/sandbox-exec", "-p", profile] + command +- #else ++ let env = ProcessInfo.processInfo.environment ++ if env["NIX_BUILD_TOP"] == nil || env["IN_NIX_SHELL"] != nil { ++ let profile = try macOSSandboxProfile( ++ fileSystem: fileSystem, ++ strictness: strictness, ++ writableDirectories: writableDirectories, ++ readOnlyDirectories: readOnlyDirectories, ++ allowNetworkConnections: allowNetworkConnections ++ ) ++ return ["/usr/bin/sandbox-exec", "-p", profile] + command ++ } ++ #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. +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0005-fix-manifest-path.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0005-fix-manifest-path.patch new file mode 100644 index 000000000000..a9ac3f1db1b0 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0005-fix-manifest-path.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sat, 13 Dec 2025 22:58:33 -0500 +Subject: [PATCH 05/11] fix-manifest-path + +--- + Sources/PackageModel/UserToolchain.swift | 8 ++++++++ + 1 file changed, 8 insertions(+) + +diff --git a/Sources/PackageModel/UserToolchain.swift b/Sources/PackageModel/UserToolchain.swift +index 7f21304c6..39d7333c5 100644 +--- a/Sources/PackageModel/UserToolchain.swift ++++ b/Sources/PackageModel/UserToolchain.swift +@@ -956,6 +956,14 @@ public final class UserToolchain: Toolchain { + } + } + ++ // The manifest and plugin paths should be in the store if they’re nowhere else. ++ if let storeLibraryPath = try? Basics.AbsolutePath(validating: "@out@/lib/swift/pm") { ++ return .init( ++ manifestLibraryPath: storeLibraryPath.appending("ManifestAPI"), ++ pluginLibraryPath: storeLibraryPath.appending("PluginAPI") ++ ) ++ } ++ + // we are using a SwiftPM outside a toolchain, use the compiler path to compute the location + return .init(swiftCompilerPath: swiftCompilerPath) + } +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0006-nix-build-caches.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0006-nix-build-caches.patch new file mode 100644 index 000000000000..aa72be9610f4 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0006-nix-build-caches.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sat, 13 Dec 2025 22:58:44 -0500 +Subject: [PATCH 06/11] nix-build-caches + +--- + Sources/Basics/FileSystem/FileSystem+Extensions.swift | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/Sources/Basics/FileSystem/FileSystem+Extensions.swift b/Sources/Basics/FileSystem/FileSystem+Extensions.swift +index 5f9674b2e..49f83e175 100644 +--- a/Sources/Basics/FileSystem/FileSystem+Extensions.swift ++++ b/Sources/Basics/FileSystem/FileSystem+Extensions.swift +@@ -12,6 +12,7 @@ + + import struct Foundation.Data + import class Foundation.FileManager ++import class Foundation.ProcessInfo + import struct Foundation.UUID + + import struct TSCBasic.ByteString +@@ -245,6 +246,11 @@ extension FileSystem { + /// SwiftPM cache directory under user's caches directory (if exists) + public var swiftPMCacheDirectory: AbsolutePath { + get throws { ++ let env = ProcessInfo.processInfo.environment ++ // Set up the caches in the build environment for Nix-managed builds ++ if let nixBuildTop = env["NIX_BUILD_TOP"] { ++ return try! AbsolutePath(validating: nixBuildTop).appending("swiftpm-cache") ++ } + if let path = self.idiomaticUserCacheDirectory { + return path.appending("org.swift.swiftpm") + } else { +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0007-nix-pkgconfig-vars.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0007-nix-pkgconfig-vars.patch new file mode 100644 index 000000000000..5721c1c66f43 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0007-nix-pkgconfig-vars.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sat, 13 Dec 2025 22:59:18 -0500 +Subject: [PATCH 07/11] nix-pkgconfig-vars + +--- + Sources/PackageLoading/PkgConfig.swift | 17 ++++++++++------- + 1 file changed, 10 insertions(+), 7 deletions(-) + +diff --git a/Sources/PackageLoading/PkgConfig.swift b/Sources/PackageLoading/PkgConfig.swift +index 21e0c514e..eaf9c803c 100644 +--- a/Sources/PackageLoading/PkgConfig.swift ++++ b/Sources/PackageLoading/PkgConfig.swift +@@ -131,14 +131,17 @@ public struct PkgConfig { + + private static var envSearchPaths: [Basics.AbsolutePath] { + get throws { +- if let configPath = Environment.current["PKG_CONFIG_PATH"] { +- #if os(Windows) +- return try configPath.split(separator: ";").map({ try AbsolutePath(validating: String($0)) }) +- #else +- return try configPath.split(separator: ":").map({ try AbsolutePath(validating: String($0)) }) +- #endif ++ var result: [Basics.AbsolutePath] = [] ++ for envVar in ["PKG_CONFIG_PATH", "PKG_CONFIG_PATH_FOR_TARGET"] { ++ if let configPath = Environment.current[EnvironmentKey(envVar)] { ++ #if os(Windows) ++ result += try configPath.split(separator: ";").map({ try Basics.AbsolutePath(validating: String($0)) }) ++ #else ++ result += try configPath.split(separator: ":").map({ try Basics.AbsolutePath(validating: String($0)) }) ++ #endif ++ } + } +- return [] ++ return result + } + } + } +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0008-set-compiler-vendor.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0008-set-compiler-vendor.patch new file mode 100644 index 000000000000..ea210e2efb26 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0008-set-compiler-vendor.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sat, 13 Dec 2025 22:59:36 -0500 +Subject: [PATCH 08/11] set-compiler-vendor + +--- + Sources/PackageModel/UserToolchain.swift | 6 ------ + 1 file changed, 6 deletions(-) + +diff --git a/Sources/PackageModel/UserToolchain.swift b/Sources/PackageModel/UserToolchain.swift +index 39d7333c5..b63997bad 100644 +--- a/Sources/PackageModel/UserToolchain.swift ++++ b/Sources/PackageModel/UserToolchain.swift +@@ -409,13 +409,7 @@ public final class UserToolchain: Toolchain { + } + + public func _isClangCompilerVendorApple() throws -> Bool? { +- // Assume the vendor is Apple on macOS. +- // FIXME: This might not be the best way to determine this. +- #if os(macOS) +- return true +- #else + return false +- #endif + } + + /// Returns the path to lldb. +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0009-add-missing-libraries.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0009-add-missing-libraries.patch new file mode 100644 index 000000000000..0f6fb621536f --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0009-add-missing-libraries.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sat, 13 Dec 2025 22:59:57 -0500 +Subject: [PATCH 09/11] add-missing-libraries + +--- + Sources/PackageSigning/CMakeLists.txt | 1 + + Sources/SwiftBuildSupport/CMakeLists.txt | 2 ++ + 2 files changed, 3 insertions(+) + +diff --git a/Sources/PackageSigning/CMakeLists.txt b/Sources/PackageSigning/CMakeLists.txt +index 13a7b8cd5..d00c7d01e 100644 +--- a/Sources/PackageSigning/CMakeLists.txt ++++ b/Sources/PackageSigning/CMakeLists.txt +@@ -21,6 +21,7 @@ target_link_libraries(PackageSigning PUBLIC + Basics + Crypto + PackageModel ++ SwiftASN1 + TSCBasic + TSCUtility + X509) +diff --git a/Sources/SwiftBuildSupport/CMakeLists.txt b/Sources/SwiftBuildSupport/CMakeLists.txt +index 3bd426bbf..c926ab811 100644 +--- a/Sources/SwiftBuildSupport/CMakeLists.txt ++++ b/Sources/SwiftBuildSupport/CMakeLists.txt +@@ -19,6 +19,7 @@ add_library(SwiftBuildSupport STATIC + PIFBuilder.swift + SwiftBuildSystem.swift) + target_link_libraries(SwiftBuildSupport PUBLIC ++ ArgumentParser + Build + DriverSupport + TSCBasic +@@ -26,6 +27,7 @@ target_link_libraries(SwiftBuildSupport PUBLIC + PackageGraph + SwiftBuild::SwiftBuild + SwiftBuild::SWBBuildService ++ SwiftSystem::SystemPackage + ) + + set_target_properties(SwiftBuildSupport PROPERTIES +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0010-Load-IndexStore-from-the-store.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0010-Load-IndexStore-from-the-store.patch new file mode 100644 index 000000000000..8d4e7cbf3889 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0010-Load-IndexStore-from-the-store.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sat, 11 Jul 2026 14:43:47 -0400 +Subject: [PATCH 10/11] Load IndexStore from the store + +--- + Sources/Build/LLBuildProgressTracker.swift | 9 +++------ + 1 file changed, 3 insertions(+), 6 deletions(-) + +diff --git a/Sources/Build/LLBuildProgressTracker.swift b/Sources/Build/LLBuildProgressTracker.swift +index 63a6a6caa..ac9b63419 100644 +--- a/Sources/Build/LLBuildProgressTracker.swift ++++ b/Sources/Build/LLBuildProgressTracker.swift +@@ -114,15 +114,12 @@ public final class BuildExecutionContext { + // library is currently installed as `libIndexStore.dll` rather than + // `IndexStore.dll`. In the future, this may require a fallback + // search, preferring `IndexStore.dll` over `libIndexStore.dll`. +- let indexStoreLib = self.toolsBuildParameters.toolchain.swiftCompilerPath +- .parentDirectory +- .appending("libIndexStore.dll") ++ let indexStoreLib = TSCAbsolutePath("@libclang@").appending(components: "lib", "libIndexStore.dll") + #else + let ext = self.toolsBuildParameters.triple.dynamicLibraryExtension +- let indexStoreLib = try toolsBuildParameters.toolchain.toolchainLibDir +- .appending("libIndexStore" + ext) ++ let indexStoreLib = TSCAbsolutePath("@libclang@").appending(components: "lib", "libIndexStore" + ext) + #endif +- return try .success(IndexStoreAPI(dylib: TSCAbsolutePath(indexStoreLib))) ++ return try .success(IndexStoreAPI(dylib: indexStoreLib)) + } catch { + return .failure(error) + } +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0011-Always-find-Clang-in-the-toolchain.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0011-Always-find-Clang-in-the-toolchain.patch new file mode 100644 index 000000000000..618822002a2f --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/patches/0011-Always-find-Clang-in-the-toolchain.patch @@ -0,0 +1,40 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sun, 23 Aug 2026 21:49:05 -0400 +Subject: [PATCH 11/11] Always find Clang in the toolchain +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +We want Swift to be usable in a default stdenv, which means `CC` is GCC +on Linux. Since SwiftPM doesn’t actually support GCC, use Clang from the +toolchain. This means you can’t override the Clang version, but that’s +probably not a good idea usually. +--- + Sources/PackageModel/UserToolchain.swift | 10 ---------- + 1 file changed, 10 deletions(-) + +diff --git a/Sources/PackageModel/UserToolchain.swift b/Sources/PackageModel/UserToolchain.swift +index b63997bad..903bdeba3 100644 +--- a/Sources/PackageModel/UserToolchain.swift ++++ b/Sources/PackageModel/UserToolchain.swift +@@ -377,16 +377,6 @@ public final class UserToolchain: Toolchain { + return clang + } + +- // Check in the environment variable first. +- if let toolPath = UserToolchain.lookup( +- variable: "CC", +- searchPaths: self.envSearchPaths, +- environment: environment +- ) { +- self._clangCompiler = toolPath +- return toolPath +- } +- + // Then, check the toolchain. + if let toolPath = try? UserToolchain.getTool( + "clang", +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/package.nix b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/package.nix new file mode 100644 index 000000000000..ab218a518210 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/package.nix @@ -0,0 +1,53 @@ +{ + lib, + stdenv, + stdlib, + swift, + swiftpm, +}: + +stdenv.mkDerivation { + name = "test-swiftpm-backdeploy-references-stdlib"; + + src = ./src; + + strictDeps = true; + + nativeBuildInputs = [ + swift + swiftpm + ]; + + doCheck = true; + + checkPhase = '' + swift run -c release | grep 'x: 1;x: 2;x: 3;x: 4' + ''; + + postFixup = '' + # This check has to be done post-fixup to make sure the stdlib’s rpath hook has run. + foundStdlib=0 + foundSwift=0 + + IFS= readarray -d $'\n' -t rpaths < <(objdump --macho --rpaths $out/bin/backdeploy-references-stdlib | tail -n +2) + for rpath in "''${rpaths[@]}"; do + if [[ "$rpath" =~ ${lib.escapeShellArg (lib.getLib stdlib)} ]]; then + foundStdlib=1 + fi + if [[ "$rpath" =~ ${lib.escapeShellArg (lib.getLib swift)} ]]; then + foundSwift=1 + fi + done + rm -rf "$out" + if [[ "$foundStdlib" == 0 || "$foundSwift" == 1 ]]; then + exit 1 + else + touch "$out" + fi + ''; + + __structuredAttrs = true; + + # Backdeployment is only used on Darwin. + meta.platforms = lib.platforms.darwin; +} diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/src/Package.swift b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/src/Package.swift new file mode 100644 index 000000000000..d5d9308d9948 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/src/Package.swift @@ -0,0 +1,14 @@ +// swift-tools-version: 6.2 + +import PackageDescription + +let package = Package( + name: "backdeploy-references-stdlib", + platforms: [.macOS("11.0")], + products: [ + .executable(name: "backdeploy-references-stdlib", targets: ["backdeploy-references-stdlib"]) + ], + targets: [ + .executableTarget(name: "backdeploy-references-stdlib", path: "Sources") + ] +) diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/src/Sources/main.swift b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/src/Sources/main.swift new file mode 100644 index 000000000000..6dbf25a4e06b --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swiftpm/tests/backdeploy-references-stdlib/src/Sources/main.swift @@ -0,0 +1,11 @@ +// Array.span can’t be backdeployed, so we have to work with buffer pointers for the test. +// See: https://forums.swift.org/t/using-span-on-pre-26-apple-os-versions/80513/4 +let arr = [1, 2, 3, 4] + +// Avoid `error: lifetime-dependent value escapes its scope` by extending the lifetime of the span. +arr.withUnsafeBufferPointer { ptr in + let span = ptr.span + for idx in span.indices { + print("x: \(span[idx]);", terminator: "") + } +} diff --git a/pkgs/development/compilers/swift_ng/sources-6.2.json b/pkgs/development/compilers/swift_ng/sources-6.2.json index fcd1710988d9..3bf0499947c8 100644 --- a/pkgs/development/compilers/swift_ng/sources-6.2.json +++ b/pkgs/development/compilers/swift_ng/sources-6.2.json @@ -32,6 +32,9 @@ "swift-llbuild": { "hash": "sha256-nZdiFXYrUiTSlSl6lxNFVpD2x8KGC4OVUUvJSOqH7gU=" }, + "swift-package-manager": { + "hash": "sha256-RIJLOoyDWWseBdDbJ5fluoZVq11jOdlV1yjq+m5xIws=" + }, "swift-syntax": { "hash": "sha256-DMMVJQj590RGGBkTgA89u01ZP2B8kbJTmfu+oxzYPds=" },