From 631053dd680d298d0986fd6d8fb40c7917270a36 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 15 May 2025 20:59:25 -0700 Subject: [PATCH 1/3] build: hoist the BlocksRuntime `add_subdirectory` Move the subdirectory recursion for the BlocksRuntime to the top level as this is a separate target entity. --- CMakeLists.txt | 3 +++ src/CMakeLists.txt | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 525fe1292..29143322a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -330,6 +330,9 @@ add_subdirectory(dispatch) add_subdirectory(man) add_subdirectory(os) add_subdirectory(private) +if(NOT APPLE) + add_subdirectory(src/BlocksRuntime) +endif() add_subdirectory(src) if(BUILD_TESTING) add_subdirectory(tests) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a1f8a0c58..feeaa25e8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,4 @@ -if(NOT APPLE) - add_subdirectory(BlocksRuntime) -endif() - add_library(dispatch allocator.c apply.c From 7b1423ee2bea70e769b5ff0d945287f4eaa17b56 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 15 May 2025 21:01:06 -0700 Subject: [PATCH 2/3] build: always build libdispatch in shared mode As per the discussion with @rokhinip, @mikeash, and @compnerd, always build libdispatch in shared mode. The rationale for this is the following: If someone does a `-static-stdlib` build of Swift code as a plugin which is hosted in a C/C++ environment, you cannot have two dispatch implementations to run this. You need a single one, and because the host environment may be dynamically linked - you need to dynamically link libdispatch (the C portions). This prepares us to be able to build the rest of the dispatch code (swiftDispatch) both statically and dynamically. Until we have a resolution on BlocksRuntime, build the library both ways. Note that in order to use a static copy of BlocksRuntime, `-static-libclosure` must be used at *compile* time. --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index feeaa25e8..641f56be6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ -add_library(dispatch +add_library(dispatch SHARED allocator.c apply.c benchmark.c From ebde4d47e4ced5d6db5bc31843e0c930edb1c215 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 16 May 2025 10:49:00 -0700 Subject: [PATCH 3/3] build: support static libclosure builds While we are still undecided on the state of libclosure (whether it should be supported as a dynamic-only linked dependency or whether we should support statically linking against the library), tweak the build to support the static builds on Windows. --- src/BlocksRuntime/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/BlocksRuntime/CMakeLists.txt b/src/BlocksRuntime/CMakeLists.txt index fc3d60252..4a06e1bfd 100644 --- a/src/BlocksRuntime/CMakeLists.txt +++ b/src/BlocksRuntime/CMakeLists.txt @@ -9,6 +9,9 @@ if(WIN32) if(NOT BUILD_SHARED_LIBS) target_compile_definitions(BlocksRuntime PRIVATE BlocksRuntime_STATIC) + target_compile_options(BlocksRuntime PUBLIC + "$<$:SHELL:$<$:-Xclang >-static-libclosure>" + $<$:SHELL:-Xcc -static-libclosure>) endif() endif()