diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swift-tools-support-core/files/TSCConfig.cmake b/pkgs/development/compilers/swift_ng/by-name/sw/swift-tools-support-core/files/TSCConfig.cmake new file mode 100644 index 000000000000..aaf13a84c523 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swift-tools-support-core/files/TSCConfig.cmake @@ -0,0 +1,11 @@ +add_library(TSCBasic @buildType@ IMPORTED) +set_target_properties(TSCBasic PROPERTIES + IMPORTED_LOCATION "@lib@/lib/${CMAKE_@buildType@_LIBRARY_PREFIX}SwiftToolsSupport${CMAKE_@buildType@_LIBRARY_SUFFIX}" + INTERFACE_INCLUDE_DIRECTORIES "@dev@/include;@dev@/lib/swift/@swiftPlatform@" +) + +add_library(TSCUtility @buildType@ IMPORTED) +set_target_properties(TSCUtility PROPERTIES + IMPORTED_LOCATION "@lib@/lib/${CMAKE_@buildType@_LIBRARY_PREFIX}SwiftToolsSupport${CMAKE_@buildType@_LIBRARY_SUFFIX}" + INTERFACE_INCLUDE_DIRECTORIES "@dev@/include;@dev@/lib/swift/@swiftPlatform@" +) diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swift-tools-support-core/package.nix b/pkgs/development/compilers/swift_ng/by-name/sw/swift-tools-support-core/package.nix new file mode 100644 index 000000000000..f1b7c717d239 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swift-tools-support-core/package.nix @@ -0,0 +1,100 @@ +{ + lib, + cmake, + fetchFromGitHub, + gitUpdater, + llvm_libtool, + ninja, + stdenv, + swift-corelibs-libdispatch, + swift-foundation, + swift-minimal, + swift_release, + swift_sources, +}: + +let + swiftPlatform = stdenv.hostPlatform.swift.platform; + # Swift Tools Support Core requires Dispatch and Foundation. + swift = swift-minimal.override { inherit swift-corelibs-libdispatch swift-foundation; }; +in + +stdenv.mkDerivation (finalAttrs: { + pname = "swift-tools-support-core"; + version = swift_release; + + outputs = [ + "out" + "dev" + ]; + + src = fetchFromGitHub { + owner = "swiftlang"; + repo = "swift-tools-support-core"; + tag = "swift-${finalAttrs.version}-RELEASE"; + inherit (swift_sources.swift-tools-support-core) hash; + }; + + patches = [ + # Match the dynamic library structure of the SwiftPM build when using CMake. + ./patches/0001-build-SwiftToolsSupport.patch + ]; + + postPatch = + # Disable using XCTest framework properties that aren’t provided by swift-corelibs-xctest. + '' + substituteInPlace "Sources/TSCTestSupport/XCTestCasePerf.swift" \ + --replace-fail '#if canImport(Darwin)' '#if false' + ''; + + 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 + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ llvm_libtool ]; + + postInstall = '' + # Install the swiftmodule. + mkdir -p "''${!outputDev}/lib/swift/${swiftPlatform}" + cp -v swift/*.swiftmodule "''${!outputDev}/lib/swift/${swiftPlatform}" + + # Install the C module + mkdir -p "''${!outputDev}/include" + cp -v ../Sources/TSCclibc/include/* "''${!outputDev}/include" + + # Install CMake config file for the SwiftSupportTools library. + mkdir -p "''${!outputDev}/lib/cmake/TSC" + substitute ${./files/TSCConfig.cmake} "''${!outputDev}/lib/cmake/TSC/TSCConfig.cmake" \ + --replace-fail '@buildType@' ${if stdenv.hostPlatform.isStatic then "STATIC" else "SHARED"} \ + --replace-fail '@dev@' "''${!outputDev}" \ + --replace-fail '@lib@' "''${!outputLib}" \ + --replace-fail '@swiftPlatform@' ${swiftPlatform} + '' + # These are not linked into the shared library and are linked separate only on Linux. + + lib.optionalString (!stdenv.hostPlatform.isDarwin) '' + libExt=${stdenv.hostPlatform.extensions.staticLibrary} + for libName in TSCBasic TSCLibc; do + cp -v lib/lib$libName$libExt "''${!outputLib}/lib/lib$libName$libExt" + done + ''; + + __structuredAttrs = true; + + passthru.updateScript = gitUpdater { }; + + meta = { + homepage = "https://github.com/swiftlang/swift-tools-support-core"; + description = "Common infrastructure code used by SwiftPM and llbuild"; + platforms = lib.platforms.darwin ++ lib.platforms.linux; + license = lib.licenses.asl20; + teams = [ lib.teams.swift ]; + }; +}) diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swift-tools-support-core/patches/0001-build-SwiftToolsSupport.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swift-tools-support-core/patches/0001-build-SwiftToolsSupport.patch new file mode 100644 index 000000000000..e829a41f9263 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swift-tools-support-core/patches/0001-build-SwiftToolsSupport.patch @@ -0,0 +1,108 @@ +From 2e4200e2586b2389f2214506bfe5e06102060f15 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Mon, 8 Dec 2025 17:40:01 -0500 +Subject: [PATCH] build SwiftToolsSupport + +--- + Sources/TSCBasic/CMakeLists.txt | 7 +------ + Sources/TSCUtility/CMakeLists.txt | 25 +++++++++++++------------ + Sources/TSCclibc/CMakeLists.txt | 6 ++---- + 3 files changed, 16 insertions(+), 22 deletions(-) + +diff --git a/Sources/TSCBasic/CMakeLists.txt b/Sources/TSCBasic/CMakeLists.txt +index d8b85ea..ebb8cbe 100644 +--- a/Sources/TSCBasic/CMakeLists.txt ++++ b/Sources/TSCBasic/CMakeLists.txt +@@ -6,7 +6,7 @@ + # See http://swift.org/LICENSE.txt for license information + # See http://swift.org/CONTRIBUTORS.txt for Swift project authors + +-add_library(TSCBasic ++add_library(TSCBasic STATIC + Await.swift + ByteString.swift + CStringArray.swift +@@ -69,9 +69,4 @@ target_link_libraries(TSCBasic PRIVATE + set_target_properties(TSCBasic PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +-install(TARGETS TSCBasic +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) +- + set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCBasic) +diff --git a/Sources/TSCUtility/CMakeLists.txt b/Sources/TSCUtility/CMakeLists.txt +index 8e0a232..78e4558 100644 +--- a/Sources/TSCUtility/CMakeLists.txt ++++ b/Sources/TSCUtility/CMakeLists.txt +@@ -6,7 +6,7 @@ + # See http://swift.org/LICENSE.txt for license information + # See http://swift.org/CONTRIBUTORS.txt for Swift project authors + +-add_library(TSCUtility ++add_library(SwiftToolsSupport + Archiver.swift + ArgumentParser.swift + ArgumentParserShellCompletion.swift +@@ -42,29 +42,30 @@ add_library(TSCUtility + dlopen.swift + misc.swift + ) +-target_link_libraries(TSCUtility PUBLIC +- TSCBasic) +-target_link_libraries(TSCUtility PRIVATE ++target_link_libraries(SwiftToolsSupport PUBLIC ++ $) ++target_link_libraries(SwiftToolsSupport PRIVATE + TSCclibc + ${CMAKE_DL_LIBS} + Threads::Threads) + + if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) + if(CMAKE_SYSTEM_NAME STREQUAL OpenBSD OR CMAKE_SYSTEM_NAME STREQUAL FreeBSD) +- target_link_directories(TSCUtility PRIVATE /usr/local/lib) ++ target_link_directories(SwiftToolsSupport PRIVATE /usr/local/lib) + endif() + if(Foundation_FOUND) +- target_link_libraries(TSCUtility PUBLIC ++ target_link_libraries(SwiftToolsSupport PUBLIC + FoundationNetworking) + endif() + endif() + # NOTE(compnerd) workaround for CMake not setting up include flags yet +-set_target_properties(TSCUtility PROPERTIES ++set_target_properties(SwiftToolsSupport PROPERTIES ++ Swift_MODULE_NAME TSCUtility + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +-install(TARGETS TSCUtility +- ARCHIVE DESTINATION lib +- LIBRARY DESTINATION lib +- RUNTIME DESTINATION bin) ++install(TARGETS SwiftToolsSupport ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + +-set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCUtility) ++set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS SwiftToolsSupport) +diff --git a/Sources/TSCclibc/CMakeLists.txt b/Sources/TSCclibc/CMakeLists.txt +index e28860c..8048c24 100644 +--- a/Sources/TSCclibc/CMakeLists.txt ++++ b/Sources/TSCclibc/CMakeLists.txt +@@ -14,9 +14,7 @@ target_compile_definitions(TSCclibc PRIVATE + "$<$:_GNU_SOURCE>") + set_target_properties(TSCclibc PROPERTIES POSITION_INDEPENDENT_CODE YES) + +-if(NOT BUILD_SHARED_LIBS) +- install(TARGETS TSCclibc +- ARCHIVE DESTINATION lib) +-endif() ++install(TARGETS TSCclibc ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") + + set_property(GLOBAL APPEND PROPERTY TSC_EXPORTS TSCclibc) +-- +2.51.2 + diff --git a/pkgs/development/compilers/swift_ng/sources-6.2.json b/pkgs/development/compilers/swift_ng/sources-6.2.json index d6a43456bf69..c913713fd7a3 100644 --- a/pkgs/development/compilers/swift_ng/sources-6.2.json +++ b/pkgs/development/compilers/swift_ng/sources-6.2.json @@ -25,5 +25,8 @@ }, "swift-syntax": { "hash": "sha256-DMMVJQj590RGGBkTgA89u01ZP2B8kbJTmfu+oxzYPds=" + }, + "swift-tools-support-core": { + "hash": "sha256-mV+z5sdG/maUzXUhK1vMtsnLCclcjqyXSMO6J2FjBEg=" } }