swiftPackages_ng.swift-corelibs-libdispatch: init at 6.2.4

This could probably be done as a drop-in replacement for the existing
`swiftPackages.Dispatch` package, but it’s easier to keep it separate.
One key change from this package is that the Swift overlay uses the same
shared libraries as the non-Swift build of the package, which makes
bootstrapping easier because everything can link the same libdispatch.
This commit is contained in:
Randy Eckenrode
2026-08-06 19:56:05 -04:00
parent b2f39c4a7e
commit cf5da7e5b8
5 changed files with 209 additions and 0 deletions

View File

@@ -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@"
)

View File

@@ -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 ];
};
})

View File

@@ -0,0 +1,60 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
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$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_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

View File

@@ -0,0 +1,32 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Thu, 13 Aug 2026 20:26:09 -0400
Subject: [PATCH 2/2] =?UTF-8?q?Don=E2=80=99t=20include=20<sys/cdefs>=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 <sys/param.h>
-#if __has_include(<sys/cdefs.h>)
+#if __has_include(<sys/cdefs.h>) && (!defined(__linux__) || defined(__GLIBC__))
#include <sys/cdefs.h>
#endif
--
2.54.0

View File

@@ -1,5 +1,8 @@
{
"llvm-project": {
"hash": "sha256-5Nb8rQmk6onrc4wKW/kT38FsYsWTqMBWtsHYZLA/0Po="
},
"swift-corelibs-libdispatch": {
"hash": "sha256-Tu2G9FAP4q1xgM1n9q17T6VrqJ3tv8RezyUex38yNds="
}
}