diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/files/dispatchConfig.cmake b/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/files/dispatchConfig.cmake new file mode 100644 index 000000000000..514017631268 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/files/dispatchConfig.cmake @@ -0,0 +1,20 @@ +add_library(BlocksRuntime @buildType@ IMPORTED) +set_target_properties(BlocksRuntime PROPERTIES + IMPORTED_LOCATION "@lib@/lib/${CMAKE_@buildType@_LIBRARY_PREFIX}BlocksRuntime${CMAKE_@buildType@_LIBRARY_SUFFIX}" +) + +add_library(dispatch @buildType@ IMPORTED) +set_target_properties(dispatch PROPERTIES + IMPORTED_LOCATION "@lib@/lib/${CMAKE_@buildType@_LIBRARY_PREFIX}dispatch${CMAKE_@buildType@_LIBRARY_SUFFIX}" +) + +set_target_properties(dispatch PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "@dev@/include" + INTERFACE_LINK_LIBRARIES "BlocksRuntime" +) + +add_library(swiftDispatch @buildType@ IMPORTED) +set_target_properties(swiftDispatch PROPERTIES + IMPORTED_LOCATION "@out-swift@/lib/${CMAKE_@buildType@_LIBRARY_PREFIX}swiftDispatch${CMAKE_@buildType@_LIBRARY_SUFFIX}" + INTERFACE_INCLUDE_DIRECTORIES "@dev-swift@/lib/swift;@dev-swift@/lib/swift/@swiftPlatform@" +) diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/package.nix b/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/package.nix new file mode 100644 index 000000000000..dbb318a4e9b7 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/package.nix @@ -0,0 +1,94 @@ +{ + lib, + cmake, + fetchFromGitHub, + fetchpatch2, + lld, + ninja, + stdenv, + swift-corelibs-libdispatch, + swift_release, + swift_sources, +}: + +let + swift-corelibs-libdispatch-no-overlay-lib = placeholder "out"; + swift-corelibs-libdispatch-no-overlay-dev = placeholder "dev"; +in + +stdenv.mkDerivation (finalAttrs: { + pname = "swift-corelibs-libdispatch"; + version = swift_release; + + outputs = [ + "out" + "dev" + "man" + ]; + + src = fetchFromGitHub { + owner = "swiftlang"; + repo = "swift-corelibs-libdispatch"; + tag = "swift-${finalAttrs.version}-RELEASE"; + inherit (swift_sources.swift-corelibs-libdispatch) hash; + }; + + patches = [ + ./patches/0001-gnu-install-dirs.patch + # Nixpkgs includes `sys/cdefs.h` from Alpine, which breaks the build due to `-Werror`. + ./patches/0002-Don-t-include-sys-cdefs-on-Musl.patch + # Fixes `implicit conversion changes signedness` error. + (fetchpatch2 { + url = "https://github.com/swiftlang/swift-corelibs-libdispatch/commit/38872e2d44d66d2fb94186988509defc734888a5.patch?full_index=1"; + hash = "sha256-BXTv79ej93CBrHtEzHDu+3WkIfzEctwyqBoPkNQQkAA="; + }) + ]; + + strictDeps = true; + + cmakeFlags = [ + # The Swift overlay is built separately using the no-overlay derivation as a base. + (lib.cmakeBool "ENABLE_SWIFT" false) + ] + ++ lib.optionals stdenv.hostPlatform.isMusl [ + # Musl requires _GNU_SOURCE or the getprogname shim fails to build. + (lib.cmakeFeature "CMAKE_C_FLAGS" "-D_GNU_SOURCE=1") + ] + ++ lib.optionals stdenv.hostPlatform.isWindows [ + # Linking for Windows requires using LLD. + (lib.cmakeFeature "CMAKE_LINKER_TYPE" "LLD") + ]; + + nativeBuildInputs = [ + cmake + ninja + ] + ++ lib.optionals stdenv.hostPlatform.isWindows [ lld ]; + + postInstall = '' + libExt=${stdenv.hostPlatform.extensions.library} + + # Provide a CMake module. This is primarily used to glue together parts of + # the Swift toolchain. Modifying the CMake config to do this for us is + # otherwise more trouble. + mkdir -p "''${!outputDev}/lib/cmake/dispatch" + substitute ${./files/dispatchConfig.cmake} "''${!outputDev}/lib/cmake/dispatch/dispatchConfig.cmake" \ + --replace-fail '@buildType@' ${if stdenv.hostPlatform.isStatic then "STATIC" else "SHARED"} \ + --replace-fail '@swiftPlatform@' ${stdenv.hostPlatform.swift.platform} \ + --replace-fail '@lib@' ${swift-corelibs-libdispatch-no-overlay-lib} \ + --replace-fail '@dev@' ${swift-corelibs-libdispatch-no-overlay-dev} \ + --replace-fail '@out-swift@' "$out" \ + --replace-fail '@dev-swift@' "''${!outputDev}" + ''; + + __structuredAttrs = true; + + meta = { + description = "Grand Central Dispatch"; + homepage = "https://github.com/swiftlang/swift-corelibs-libdispatch"; + platforms = lib.platforms.freebsd ++ lib.platforms.linux ++ lib.platforms.windows; + license = lib.licenses.asl20; + maintainers = with lib.maintainers; [ cmm ]; + teams = [ lib.teams.swift ]; + }; +}) diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/patches/0001-gnu-install-dirs.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/patches/0001-gnu-install-dirs.patch new file mode 100644 index 000000000000..c6abc42dc584 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/patches/0001-gnu-install-dirs.patch @@ -0,0 +1,60 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Sat, 4 Jul 2026 15:19:17 -0400 +Subject: [PATCH 1/2] gnu-install-dirs + +--- + src/BlocksRuntime/CMakeLists.txt | 4 ++-- + src/CMakeLists.txt | 4 ++-- + src/swift/CMakeLists.txt | 6 +++--- + 3 files changed, 7 insertions(+), 7 deletions(-) + +diff --git a/src/BlocksRuntime/CMakeLists.txt b/src/BlocksRuntime/CMakeLists.txt +index f6fde93..189131e 100644 +--- a/src/BlocksRuntime/CMakeLists.txt ++++ b/src/BlocksRuntime/CMakeLists.txt +@@ -34,6 +34,6 @@ endif() + set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS BlocksRuntime) + install(TARGETS BlocksRuntime + EXPORT dispatchExports +- ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} +- LIBRARY DESTINATION ${INSTALL_TARGET_DIR} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 846fb39..d09a5aa 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -182,6 +182,6 @@ endif() + set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS dispatch) + install(TARGETS dispatch + EXPORT dispatchExports +- ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} +- LIBRARY DESTINATION ${INSTALL_TARGET_DIR} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/src/swift/CMakeLists.txt b/src/swift/CMakeLists.txt +index 38bef37..3326735 100644 +--- a/src/swift/CMakeLists.txt ++++ b/src/swift/CMakeLists.txt +@@ -40,12 +40,12 @@ get_swift_host_arch(swift_arch) + install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftmodule + ${CMAKE_CURRENT_BINARY_DIR}/swift/Dispatch.swiftdoc +- DESTINATION ${INSTALL_TARGET_DIR}/${swift_arch}) ++ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/../lib/swift$<$>:_static>/${SWIFT_SYSTEM_NAME}") + set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS swiftDispatch) + install(TARGETS swiftDispatch + EXPORT dispatchExports +- ARCHIVE DESTINATION ${INSTALL_TARGET_DIR} +- LIBRARY DESTINATION ${INSTALL_TARGET_DIR} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + if(HAVE_OBJC AND NOT BUILD_SHARED_LIBS) + set_property(GLOBAL APPEND PROPERTY DISPATCH_EXPORTS DispatchStubs) +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/patches/0002-Don-t-include-sys-cdefs-on-Musl.patch b/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/patches/0002-Don-t-include-sys-cdefs-on-Musl.patch new file mode 100644 index 000000000000..9ef0c0462ba9 --- /dev/null +++ b/pkgs/development/compilers/swift_ng/by-name/sw/swift-corelibs-libdispatch/patches/0002-Don-t-include-sys-cdefs-on-Musl.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Randy Eckenrode +Date: Thu, 13 Aug 2026 20:26:09 -0400 +Subject: [PATCH 2/2] =?UTF-8?q?Don=E2=80=99t=20include=20=20on?= + =?UTF-8?q?=20Musl?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Nixpkgs includes `sys/cdefs.h` from Alpine, which causes the +`__has_header` check to pass. This would be harmless, but the `#warning` +at the top of `sys/cdefs.h` is turned into an error by `-Werror`. +--- + os/generic_unix_base.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/os/generic_unix_base.h b/os/generic_unix_base.h +index b77d2ad..95ffd80 100644 +--- a/os/generic_unix_base.h ++++ b/os/generic_unix_base.h +@@ -25,7 +25,7 @@ + #endif + #include + +-#if __has_include() ++#if __has_include() && (!defined(__linux__) || defined(__GLIBC__)) + #include + #endif + +-- +2.54.0 + diff --git a/pkgs/development/compilers/swift_ng/sources-6.2.json b/pkgs/development/compilers/swift_ng/sources-6.2.json index 5ba460c73672..46e9a46b54d8 100644 --- a/pkgs/development/compilers/swift_ng/sources-6.2.json +++ b/pkgs/development/compilers/swift_ng/sources-6.2.json @@ -1,5 +1,8 @@ { "llvm-project": { "hash": "sha256-5Nb8rQmk6onrc4wKW/kT38FsYsWTqMBWtsHYZLA/0Po=" + }, + "swift-corelibs-libdispatch": { + "hash": "sha256-Tu2G9FAP4q1xgM1n9q17T6VrqJ3tv8RezyUex38yNds=" } }