From f0392f4a53f023c1e1bda34353b60afc339c6ca3 Mon Sep 17 00:00:00 2001 From: hmelder Date: Mon, 29 Sep 2025 17:20:00 +0200 Subject: [PATCH 01/10] libobjc2: use libBlocksRuntime from libdispatch --- phases/{11-libobjc2.bat => 19-libobjc2.bat} | 1 + phases/{19-libcurl.bat => 20-libcurl.bat} | 0 phases/{20-gnustep-make.sh => 21-gnustep-make.sh} | 0 3 files changed, 1 insertion(+) rename phases/{11-libobjc2.bat => 19-libobjc2.bat} (96%) rename phases/{19-libcurl.bat => 20-libcurl.bat} (100%) rename phases/{20-gnustep-make.sh => 21-gnustep-make.sh} (100%) diff --git a/phases/11-libobjc2.bat b/phases/19-libobjc2.bat similarity index 96% rename from phases/11-libobjc2.bat rename to phases/19-libobjc2.bat index 4b8784b..1348908 100644 --- a/phases/11-libobjc2.bat +++ b/phases/19-libobjc2.bat @@ -18,6 +18,7 @@ echo ### Running cmake :: GNUSTEP_CONFIG is set to empty string to prevent CMake from finding it in install root. cmake .. %CMAKE_OPTIONS% ^ -D GNUSTEP_CONFIG= ^ + -D EMBEDDED_BLOCKS_RUNTIME=OFF ^ || exit /b 1 echo. diff --git a/phases/19-libcurl.bat b/phases/20-libcurl.bat similarity index 100% rename from phases/19-libcurl.bat rename to phases/20-libcurl.bat diff --git a/phases/20-gnustep-make.sh b/phases/21-gnustep-make.sh similarity index 100% rename from phases/20-gnustep-make.sh rename to phases/21-gnustep-make.sh From 056c1197c0ac36c39dc499c1152517265272303c Mon Sep 17 00:00:00 2001 From: hmelder Date: Mon, 29 Sep 2025 17:28:55 +0200 Subject: [PATCH 02/10] Add blocks rt patches for libobjc2 and libdispatch libBlocksRuntime does not export the symbols correctly when building on Windows. Additionally, libobjc2 has some CMake configuration bugs. --- patches/libdispatch-export-blocksrt.patch | 65 ++++ patches/libdispatch-own-blocksruntime.patch | 36 -- patches/libobjc2-blocksrt-detection.patch | 380 ++++++++++++++++++++ phases/18-libdispatch.bat | 2 - 4 files changed, 445 insertions(+), 38 deletions(-) create mode 100644 patches/libdispatch-export-blocksrt.patch delete mode 100644 patches/libdispatch-own-blocksruntime.patch create mode 100644 patches/libobjc2-blocksrt-detection.patch diff --git a/patches/libdispatch-export-blocksrt.patch b/patches/libdispatch-export-blocksrt.patch new file mode 100644 index 0000000..a95a32d --- /dev/null +++ b/patches/libdispatch-export-blocksrt.patch @@ -0,0 +1,65 @@ +diff --git a/src/BlocksRuntime/Block_private.h b/src/BlocksRuntime/Block_private.h +index b2e1512..df6fa19 100644 +--- a/src/BlocksRuntime/Block_private.h ++++ b/src/BlocksRuntime/Block_private.h +@@ -197,9 +197,17 @@ BLOCK_EXPORT bool _Block_tryRetain(const void *aBlock); + // Callable only from the ARR weak subsystem while in exclusion zone + BLOCK_EXPORT bool _Block_isDeallocating(const void *aBlock); + +- + // the raw data space for runtime classes for blocks + // class+meta used for stack, malloc, and collectable based blocks ++#if defined(_WIN32) ++extern void * _NSConcreteMallocBlock[32]; ++extern void * _NSConcreteAutoBlock[32]; ++extern void * _NSConcreteFinalizingBlock[32]; ++extern void * _NSConcreteWeakBlockVariable[32]; ++// declared in Block.h ++// extern void * _NSConcreteGlobalBlock[32]; ++// extern void * _NSConcreteStackBlock[32]; ++#else + BLOCK_EXPORT void * _NSConcreteMallocBlock[32]; + BLOCK_EXPORT void * _NSConcreteAutoBlock[32]; + BLOCK_EXPORT void * _NSConcreteFinalizingBlock[32]; +@@ -207,6 +215,7 @@ BLOCK_EXPORT void * _NSConcreteWeakBlockVariable[32]; + // declared in Block.h + // BLOCK_EXPORT void * _NSConcreteGlobalBlock[32]; + // BLOCK_EXPORT void * _NSConcreteStackBlock[32]; ++#endif + + + // the intercept routines that must be used under GC +diff --git a/src/BlocksRuntime/BlocksRuntime.def b/src/BlocksRuntime/BlocksRuntime.def +index a3b1aab..a4142b2 100644 +--- a/src/BlocksRuntime/BlocksRuntime.def ++++ b/src/BlocksRuntime/BlocksRuntime.def +@@ -2,3 +2,7 @@ LIBRARY BlocksRuntime + EXPORTS + _NSConcreteGlobalBlock CONSTANT + _NSConcreteStackBlock CONSTANT ++ _NSConcreteMallocBlock CONSTANT ++ _NSConcreteAutoBlock CONSTANT ++ _NSConcreteFinalizingBlock CONSTANT ++ _NSConcreteWeakBlockVariable CONSTANT +diff --git a/src/BlocksRuntime/data.c b/src/BlocksRuntime/data.c +index fe4745b..f96ea25 100644 +--- a/src/BlocksRuntime/data.c ++++ b/src/BlocksRuntime/data.c +@@ -19,12 +19,15 @@ We keep these in a separate file so that we can include the runtime code in test + #if defined(_WIN32) + void * _NSConcreteStackBlock[32] = { 0 }; + void * _NSConcreteGlobalBlock[32] = { 0 }; ++void * _NSConcreteMallocBlock[32] = { 0 }; ++void * _NSConcreteAutoBlock[32] = { 0 }; ++void * _NSConcreteFinalizingBlock[32] = { 0 }; ++void * _NSConcreteWeakBlockVariable[32] = { 0 }; + #else + BLOCK_ABI void * _NSConcreteStackBlock[32] = { 0 }; + BLOCK_ABI void * _NSConcreteGlobalBlock[32] = { 0 }; +-#endif +- + BLOCK_ABI void * _NSConcreteMallocBlock[32] = { 0 }; + BLOCK_ABI void * _NSConcreteAutoBlock[32] = { 0 }; + BLOCK_ABI void * _NSConcreteFinalizingBlock[32] = { 0 }; + BLOCK_ABI void * _NSConcreteWeakBlockVariable[32] = { 0 }; ++#endif diff --git a/patches/libdispatch-own-blocksruntime.patch b/patches/libdispatch-own-blocksruntime.patch deleted file mode 100644 index a634627..0000000 --- a/patches/libdispatch-own-blocksruntime.patch +++ /dev/null @@ -1,36 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 45461eb..7c954fb 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -178,6 +178,8 @@ if(NOT ANDROID) - find_package(LibRT) - endif() - -+find_package(BlocksRuntime QUIET) -+ - check_function_exists(_pthread_workqueue_init HAVE__PTHREAD_WORKQUEUE_INIT) - check_function_exists(getprogname HAVE_GETPROGNAME) - check_function_exists(mach_absolute_time HAVE_MACH_ABSOLUTE_TIME) -@@ -331,7 +333,7 @@ add_subdirectory(dispatch) - add_subdirectory(man) - add_subdirectory(os) - add_subdirectory(private) --if(NOT APPLE) -+if(NOT BlocksRuntime_FOUND) - add_subdirectory(src/BlocksRuntime) - endif() - add_subdirectory(src) -diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt -index ed5d2f4..257b02d 100644 ---- a/tests/CMakeLists.txt -+++ b/tests/CMakeLists.txt -@@ -80,9 +80,6 @@ function(add_unit_test name) - # to reduce probability of test failures due to machine load. - target_compile_options(${name} PRIVATE -DLENIENT_DEADLINES=1) - endif() -- target_include_directories(${name} -- SYSTEM BEFORE PRIVATE -- "${BlocksRuntime_INCLUDE_DIR}") - if("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC") - target_compile_options(${name} PRIVATE -Xclang -fblocks) - target_compile_options(${name} PRIVATE /W3 -Wno-deprecated-declarations) diff --git a/patches/libobjc2-blocksrt-detection.patch b/patches/libobjc2-blocksrt-detection.patch new file mode 100644 index 0000000..690e14b --- /dev/null +++ b/patches/libobjc2-blocksrt-detection.patch @@ -0,0 +1,380 @@ +From d5d32112d701dc8ed63fe7ca337f88372c8444fc Mon Sep 17 00:00:00 2001 +From: hmelder +Date: Thu, 9 Oct 2025 04:34:06 -0700 +Subject: [PATCH 1/6] remove unused CMake directory + +--- + CMake/CMakeLists.txt | 17 ------------ + CMake/typeinfo_test.cc | 62 ------------------------------------------ + 2 files changed, 79 deletions(-) + delete mode 100644 CMake/CMakeLists.txt + delete mode 100644 CMake/typeinfo_test.cc + +diff --git a/CMake/CMakeLists.txt b/CMake/CMakeLists.txt +deleted file mode 100644 +index a16bffff..00000000 +--- a/CMake/CMakeLists.txt ++++ /dev/null +@@ -1,17 +0,0 @@ +-cmake_minimum_required(VERSION 3.2) +-project(test_cxx_runtime) +- +-add_executable(test_cxx_runtime typeinfo_test.cc) +-add_executable(test_cxx_stdlib typeinfo_test.cc) +-if (CXX_RUNTIME) +- if (CXX_RUNTIME MATCHES ".*libc\\+\\+abi.*") +- find_library(M_LIBRARY m) +- if (M_LIBRARY) +- target_link_libraries(test_cxx_runtime ${M_LIBRARY}) +- endif() +- endif() +- set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") +- target_link_libraries(test_cxx_runtime ${CXX_RUNTIME}) +- set_target_properties(test_cxx_runtime PROPERTIES +- LINKER_LANGUAGE C) +-endif() +diff --git a/CMake/typeinfo_test.cc b/CMake/typeinfo_test.cc +deleted file mode 100644 +index 1d5536b2..00000000 +--- a/CMake/typeinfo_test.cc ++++ /dev/null +@@ -1,62 +0,0 @@ +-#include +- +-namespace __cxxabiv1 +-{ +- struct __class_type_info; +-} +- +-using __cxxabiv1::__class_type_info; +- +-namespace std +-{ +- /** +- * std::type_info defined with the GCC ABI. This may not be exposed in +- * public headers, but is required for correctly implementing the unified +- * exception model. +- */ +- class type_info +- { +- public: +- virtual ~type_info(); +- bool operator==(const type_info &) const; +- bool operator!=(const type_info &) const; +- bool before(const type_info &) const; +- private: +- type_info(const type_info& rhs); +- type_info& operator= (const type_info& rhs); +- const char *__type_name; +- protected: +- type_info(const char *name): __type_name(name) { } +- public: +- const char* name() const { return __type_name; } +- virtual bool __is_pointer_p() const; +- virtual bool __is_function_p() const; +- virtual bool __do_catch(const type_info *thrown_type, +- void **thrown_object, +- unsigned outer) const; +- virtual bool __do_upcast( +- const __class_type_info *target, +- void **thrown_object) const; +- }; +-} +- +-class type_info2 : public std::type_info +-{ +- public: +- type_info2() : type_info("foo") {} +- virtual bool __is_pointer_p() const; +- virtual bool __is_function_p() const { return true; } +- virtual bool __do_catch(const type_info *thrown_type, +- void **thrown_object, +- unsigned outer) const { return true; } +- virtual bool __do_upcast( +- const __class_type_info *target, +- void **thrown_object) const { return true; }; +-}; +-bool type_info2::__is_pointer_p() const { return true; } +- +-int main() +-{ +- type_info2 s; +- return s.__is_pointer_p(); +-} + +From 9d8fb81d30bd298cbe06a474ee8d14d4cfb000c9 Mon Sep 17 00:00:00 2001 +From: hmelder +Date: Thu, 9 Oct 2025 04:50:11 -0700 +Subject: [PATCH 2/6] Add FindBlocksRuntime.cmake from the libdispatch project + +This is a slightly modified version of the file found in swift-corelibs-libdispatch. Notabily, the non-existent HINTS are removed. +--- + cmake/FindBlocksRuntime.cmake | 44 +++++++++++++++++++++++++++++++++++ + 1 file changed, 44 insertions(+) + create mode 100644 cmake/FindBlocksRuntime.cmake + +diff --git a/cmake/FindBlocksRuntime.cmake b/cmake/FindBlocksRuntime.cmake +new file mode 100644 +index 00000000..c623065e +--- /dev/null ++++ b/cmake/FindBlocksRuntime.cmake +@@ -0,0 +1,44 @@ ++#.rst: ++# FindBlocksRuntime ++# ----------------- ++# ++# Find libBlocksRuntime library and headers. ++# ++# The module defines the following variables: ++# ++# ## ++# ++# BlocksRuntime_FOUND - true if libBlocksRuntime was found ++# BlocksRuntime_INCLUDE_DIR - include search path ++# BlocksRuntime_LIBRARIES - libraries to link ++ ++if(BlocksRuntime_INCLUDE_DIR AND BlocksRuntime_LIBRARIES) ++ set(BlocksRuntime_FOUND TRUE) ++else() ++ find_path(BlocksRuntime_INCLUDE_DIR ++ NAMES ++ Block.h Block_private.h) ++ find_library(BlocksRuntime_LIBRARIES ++ NAMES ++ BlocksRuntime libBlocksRuntime) ++ ++ include(FindPackageHandleStandardArgs) ++ find_package_handle_standard_args(BlocksRuntime ++ REQUIRED_VARS ++ BlocksRuntime_LIBRARIES ++ BlocksRuntime_INCLUDE_DIR) ++ ++ mark_as_advanced(BlocksRuntime_LIBRARIES BlocksRuntime_INCLUDE_DIR) ++endif() ++ ++if(BlocksRuntime_FOUND) ++ if(NOT TARGET BlocksRuntime::BlocksRuntime) ++ add_library(BlocksRuntime::BlocksRuntime UNKNOWN IMPORTED) ++ set_target_properties(BlocksRuntime::BlocksRuntime ++ PROPERTIES ++ IMPORTED_LOCATION ++ ${BlocksRuntime_LIBRARIES} ++ INTERFACE_INCLUDE_DIRECTORIES ++ ${BlocksRuntime_INCLUDE_DIR}) ++ endif() ++endif() + +From 08acb0aacbdd8afd5f52510d4b3013c004a54b0c Mon Sep 17 00:00:00 2001 +From: hmelder +Date: Thu, 9 Oct 2025 04:34:24 -0700 +Subject: [PATCH 3/6] CMakeLists.txt: Use FindBlocksRuntime + +Use cmake/FindBlocksRuntime.cmake to locate the external blocks runtime, +and do not compile the internal one. +--- + CMakeLists.txt | 46 ++++++++++++++++++++++++++++------------------ + 1 file changed, 28 insertions(+), 18 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 3f073375..e2468ed3 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -26,6 +26,9 @@ if (MINGW) + set(CMAKE_OBJCXX_IMPLICIT_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) + endif () + ++list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") ++list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX}) ++ + INCLUDE (CheckCXXSourceCompiles) + INCLUDE (FetchContent) + INCLUDE (CheckSymbolExists) +@@ -50,7 +53,6 @@ add_compile_definitions(GNUSTEP __OBJC_RUNTIME_INTERNAL__=1 __OBJC_BOOL) + set(CMAKE_CXX_STANDARD 17) + + set(libobjc_ASM_SRCS +- block_trampolines.S + objc_msgSend.S) + set(libobjc_OBJCXX_SRCS + arc.mm +@@ -62,7 +64,6 @@ set(libobjc_OBJC_SRCS + properties.m) + set(libobjc_C_SRCS + alias_table.c +- block_to_imp.c + builtin_classes.c + caps.c + category_loader.c +@@ -105,6 +106,7 @@ set(libobjc_HDRS + set(libobjc_CXX_SRCS + selector_table.cc + ) ++ + # Windows does not use DWARF EH, except when using the GNU ABI (MinGW) + if (WIN32 AND NOT MINGW) + list(APPEND libobjc_CXX_SRCS eh_win32_msvc.cc) +@@ -154,6 +156,11 @@ add_compile_definitions($<$:STRICT_APPLE_COM + configure_file(objc/objc-config.h.in objc/objc-config.h @ONLY) + include_directories("${PROJECT_BINARY_DIR}/objc/") + ++if (EMBEDDED_BLOCKS_RUNTIME) ++ list(APPEND libobjc_ASM_SRCS block_trampolines.S) ++ list(APPEND libobjc_C_SRCS block_to_imp.c) ++endif() ++ + if (OLDABI_COMPAT) + list(APPEND libobjc_C_SRCS legacy.c abi_version.c statics_loader.c) + add_definitions(-DOLDABI_COMPAT=1) +@@ -242,18 +249,9 @@ if (EMBEDDED_BLOCKS_RUNTIME) + list(APPEND libobjc_HDRS objc/blocks_runtime.h) + add_definitions(-DEMBEDDED_BLOCKS_RUNTIME) + else () +- find_library(BLOCKS_RUNTIME_LIBRARY BlocksRuntime) +- if (BLOCKS_RUNTIME_LIBRARY) +- set(CMAKE_REQUIRED_LIBRARIES ${BLOCKS_RUNTIME_LIBRARY}) +- check_symbol_exists(_Block_use_RR2 "Block_private.h" HAVE_BLOCK_USE_RR2) +- if (HAVE_BLOCK_USE_RR2) +- add_definitions(-DHAVE_BLOCK_USE_RR2) +- else () +- message(FATAL_ERROR "libBlocksRuntime does not contain _Block_use_RR2(). Enable EMBEDDED_BLOCKS_RUNTIME to use the built-in blocks runtime.") +- endif () +- unset(CMAKE_REQUIRED_LIBRARIES) +- else () +- message(FATAL_ERROR "libBlocksRuntime not found. Enable EMBEDDED_BLOCKS_RUNTIME to use the built-in blocks runtime.") ++ find_package(BlocksRuntime) ++ if (NOT BlocksRuntime_FOUND) ++ message(FATAL_ERROR "An external blocks runtime is required when not using the embedded one.") + endif () + endif () + +@@ -270,6 +268,22 @@ if (WIN32 AND NOT MINGW) + target_link_libraries(objc PUBLIC ntdll.dll) + endif() + ++if (NOT EMBEDDED_BLOCKS_RUNTIME) ++ # Check if the blocks runtime exports _Block_use_RR2 ++ set(CMAKE_REQUIRED_LIBRARIES ${BlocksRuntime_LIBRARIES}) ++ set(CMAKE_REQUIRED_INCLUDES ${BlocksRuntime_INCLUDE_DIR}) ++ check_symbol_exists(_Block_use_RR2 "Block_private.h" HAVE_BLOCK_USE_RR2) ++ unset(CMAKE_REQUIRED_LIBRARIES) ++ unset(CMAKE_REQUIRED_INCLUDES) ++ ++ if (NOT HAVE_BLOCK_USE_RR2) ++ message(FATAL_ERROR "The external blocks runtime is not supported. It does not export _Block_use_RR2().") ++ endif() ++ ++ target_compile_definitions(objc PRIVATE HAVE_BLOCK_USE_RR2) ++ target_link_libraries(objc PUBLIC BlocksRuntime::BlocksRuntime) ++endif() ++ + target_link_libraries(objc PRIVATE tsl::robin_map) + + set_target_properties(objc PROPERTIES +@@ -295,10 +309,6 @@ if (M_LIBRARY) + target_link_libraries(objc PUBLIC ${M_LIBRARY}) + endif () + +-if (BLOCKS_RUNTIME_LIBRARY) +- target_link_libraries(objc PUBLIC ${BLOCKS_RUNTIME_LIBRARY}) +-endif () +- + # Make weak symbols work on OS X + if (APPLE) + set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS + +From 9320daefcaccb0418b535d83e75a8c2017deec50 Mon Sep 17 00:00:00 2001 +From: hmelder +Date: Thu, 9 Oct 2025 04:36:42 -0700 +Subject: [PATCH 4/6] Only call init_trampolines when using the internal blocks + rt + +--- + loader.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/loader.c b/loader.c +index 449d7a7c..f4df0471 100644 +--- a/loader.c ++++ b/loader.c +@@ -59,7 +59,9 @@ static void init_runtime(void) + init_alias_table(); + init_early_blocks(); + init_arc(); ++#if defined(EMBEDDED_BLOCKS_RUNTIME) + init_trampolines(); ++#endif + init_builtin_classes(); + first_run = NO; + if (getenv("LIBOBJC_MEMORY_PROFILE")) + +From 5c7378c1ba6809cab4d539531bd0dcff6576dea2 Mon Sep 17 00:00:00 2001 +From: hmelder +Date: Thu, 9 Oct 2025 04:38:11 -0700 +Subject: [PATCH 5/6] Conditionally include BlockImpTest.m + +--- + Test/CMakeLists.txt | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt +index 3e37fb79..3aa27b73 100644 +--- a/Test/CMakeLists.txt ++++ b/Test/CMakeLists.txt +@@ -16,7 +16,6 @@ set(TESTS + AllocatePair.m + AssociatedObject.m + AssociatedObject2.m +- BlockImpTest.m + BlockTest_arc.m + ConstantString.m + Category.m +@@ -54,6 +53,10 @@ set(TESTS + UnexpectedException.m + ) + ++if (EMBEDDED_BLOCKS_RUNTIME) ++ list(APPEND TESTS BlockImpTest.m) ++endif() ++ + set(ENABLE_ALL_OBJC_ARC_TESTS On) + + if (WIN32) + +From 6a18e54a0209051d37db00d76b668d8f3ac23627 Mon Sep 17 00:00:00 2001 +From: hmelder +Date: Thu, 9 Oct 2025 04:39:13 -0700 +Subject: [PATCH 6/6] External symbols should be imported from the DLL + +--- + NSBlocks.m | 12 ++++++++---- + 1 file changed, 8 insertions(+), 4 deletions(-) + +diff --git a/NSBlocks.m b/NSBlocks.m +index 49eee9d9..e5cccbdb 100644 +--- a/NSBlocks.m ++++ b/NSBlocks.m +@@ -7,10 +7,14 @@ + #include + + #ifdef EMBEDDED_BLOCKS_RUNTIME +-#define BLOCK_STORAGE OBJC_PUBLIC ++# define BLOCK_STORAGE OBJC_PUBLIC + #else +-#define BLOCK_STORAGE extern +-#endif ++# if defined(_WIN32) ++# define BLOCK_STORAGE __attribute__((dllimport)) ++# else ++# define BLOCK_STORAGE extern ++# endif // defined(_WIN32) ++#endif // EMBEDDED_BLOCKS_RUNTIME + + BLOCK_STORAGE struct objc_class _NSConcreteGlobalBlock; + BLOCK_STORAGE struct objc_class _NSConcreteStackBlock; +@@ -76,4 +80,4 @@ PRIVATE void init_early_blocks(void) + _NSConcreteMallocBlock.info = objc_class_flag_is_block; + _NSConcreteAutoBlock.info = objc_class_flag_is_block; + _NSConcreteFinalizingBlock.info = objc_class_flag_is_block; +-} +\ No newline at end of file ++} diff --git a/phases/18-libdispatch.bat b/phases/18-libdispatch.bat index 37f3ccf..1efca48 100644 --- a/phases/18-libdispatch.bat +++ b/phases/18-libdispatch.bat @@ -29,8 +29,6 @@ cmake .. %CMAKE_OPTIONS% ^ -D INSTALL_PRIVATE_HEADERS=YES ^ -D CMAKE_CXX_FLAGS_RELWITHDEBINFO="/Zi" ^ -D CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO="/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF" ^ - -D BlocksRuntime_INCLUDE_DIR=%INSTALL_PREFIX%\include ^ - -D BlocksRuntime_LIBRARIES=%INSTALL_PREFIX%\lib\objc.lib ^ -D CMAKE_C_COMPILER=clang-cl ^ -D CMAKE_CXX_COMPILER=clang-cl ^ || exit /b 1 From 614d79169345abec6b0dcb33cf347c4c65e16c33 Mon Sep 17 00:00:00 2001 From: hmelder Date: Fri, 24 Oct 2025 04:46:40 -0700 Subject: [PATCH 03/10] rename xml2 and xslt phases --- phases/{16-libxml2.bat => 15-libxml2.bat} | 0 phases/{17-libxslt.bat => 16-libxslt.bat} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename phases/{16-libxml2.bat => 15-libxml2.bat} (100%) rename phases/{17-libxslt.bat => 16-libxslt.bat} (100%) diff --git a/phases/16-libxml2.bat b/phases/15-libxml2.bat similarity index 100% rename from phases/16-libxml2.bat rename to phases/15-libxml2.bat diff --git a/phases/17-libxslt.bat b/phases/16-libxslt.bat similarity index 100% rename from phases/17-libxslt.bat rename to phases/16-libxslt.bat From 9084cb23d9dbedb5ef0518175ffaf2b33ebddfad Mon Sep 17 00:00:00 2001 From: hmelder Date: Fri, 24 Oct 2025 04:46:53 -0700 Subject: [PATCH 04/10] add blocksruntime phase --- phases/17-blocksruntime.bat | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 phases/17-blocksruntime.bat diff --git a/phases/17-blocksruntime.bat b/phases/17-blocksruntime.bat new file mode 100644 index 0000000..0f30b2b --- /dev/null +++ b/phases/17-blocksruntime.bat @@ -0,0 +1,33 @@ +@echo off +setlocal + +set PROJECT=blocksruntime +set GITHUB_REPO=hmelder/swift-corelibs-blocksruntime +set TAG=blocks-rt-win32 + +:: load environment and prepare project +call "%~dp0\..\scripts\common.bat" prepare_project || exit /b 1 + +set BUILD_DIR="%SRCROOT%\%PROJECT%\build-%ARCH%-%BUILD_TYPE%" +if exist "%BUILD_DIR%" (rmdir /S /Q "%BUILD_DIR%" || exit /b 1) +mkdir "%BUILD_DIR%" || exit /b 1 +cd "%BUILD_DIR%" || exit /b 1 + +echo. +echo ### Running cmake +:: CXX and linker flags below are to produce PDBs for release builds. +cmake .. %CMAKE_OPTIONS% ^ + -D CMAKE_CXX_FLAGS_RELWITHDEBINFO="/Zi" ^ + -D CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO="/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF" ^ + || exit /b 1 + +echo. +echo ### Building +ninja || exit /b 1 + +echo. +echo ### Installing +ninja install || exit /b 1 + +:: install PDB file +xcopy /Y /F BlocksRuntime.pdb "%INSTALL_PREFIX%\bin\" || exit /b 1 From ce56e4de4c76d502001c199e1b5804e07eb42274 Mon Sep 17 00:00:00 2001 From: hmelder Date: Fri, 24 Oct 2025 04:47:33 -0700 Subject: [PATCH 05/10] Define BlocksRuntime_INCLUDE_DIR --- phases/18-libdispatch.bat | 2 +- phases/19-libobjc2.bat | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/phases/18-libdispatch.bat b/phases/18-libdispatch.bat index 1efca48..3827223 100644 --- a/phases/18-libdispatch.bat +++ b/phases/18-libdispatch.bat @@ -22,7 +22,6 @@ cd "%BUILD_DIR%" || exit /b 1 echo. echo ### Running cmake :: CXX and linker flags below are to produce PDBs for release builds. -:: BlocksRuntime parameters provided to use blocks runtime from libobjc2 with libdispatch-own-blocksruntime.patch. :: libdispatch only supports building with clang-cl frontend. cmake .. %CMAKE_OPTIONS% ^ -D BUILD_SHARED_LIBS=YES ^ @@ -31,6 +30,7 @@ cmake .. %CMAKE_OPTIONS% ^ -D CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO="/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF" ^ -D CMAKE_C_COMPILER=clang-cl ^ -D CMAKE_CXX_COMPILER=clang-cl ^ + -D BlocksRuntime_INCLUDE_DIR="%INSTALL_PREFIX%\include\BlocksRuntime" ^ || exit /b 1 echo. diff --git a/phases/19-libobjc2.bat b/phases/19-libobjc2.bat index 1348908..ab31b9e 100644 --- a/phases/19-libobjc2.bat +++ b/phases/19-libobjc2.bat @@ -19,6 +19,7 @@ echo ### Running cmake cmake .. %CMAKE_OPTIONS% ^ -D GNUSTEP_CONFIG= ^ -D EMBEDDED_BLOCKS_RUNTIME=OFF ^ + -D BlocksRuntime_INCLUDE_DIR="%INSTALL_PREFIX%\include\BlocksRuntime" ^ || exit /b 1 echo. From 33afa34e654a2d5faeebdf83cb2e3fbfd8c5ccc5 Mon Sep 17 00:00:00 2001 From: hmelder Date: Fri, 24 Oct 2025 04:47:52 -0700 Subject: [PATCH 06/10] libdispatch: rename blocksruntime patch --- patches/libdispatch-export-blocksrt.patch | 65 --------------------- patches/libdispatch-ext-blocksruntime.patch | 26 +++++++++ 2 files changed, 26 insertions(+), 65 deletions(-) delete mode 100644 patches/libdispatch-export-blocksrt.patch create mode 100644 patches/libdispatch-ext-blocksruntime.patch diff --git a/patches/libdispatch-export-blocksrt.patch b/patches/libdispatch-export-blocksrt.patch deleted file mode 100644 index a95a32d..0000000 --- a/patches/libdispatch-export-blocksrt.patch +++ /dev/null @@ -1,65 +0,0 @@ -diff --git a/src/BlocksRuntime/Block_private.h b/src/BlocksRuntime/Block_private.h -index b2e1512..df6fa19 100644 ---- a/src/BlocksRuntime/Block_private.h -+++ b/src/BlocksRuntime/Block_private.h -@@ -197,9 +197,17 @@ BLOCK_EXPORT bool _Block_tryRetain(const void *aBlock); - // Callable only from the ARR weak subsystem while in exclusion zone - BLOCK_EXPORT bool _Block_isDeallocating(const void *aBlock); - -- - // the raw data space for runtime classes for blocks - // class+meta used for stack, malloc, and collectable based blocks -+#if defined(_WIN32) -+extern void * _NSConcreteMallocBlock[32]; -+extern void * _NSConcreteAutoBlock[32]; -+extern void * _NSConcreteFinalizingBlock[32]; -+extern void * _NSConcreteWeakBlockVariable[32]; -+// declared in Block.h -+// extern void * _NSConcreteGlobalBlock[32]; -+// extern void * _NSConcreteStackBlock[32]; -+#else - BLOCK_EXPORT void * _NSConcreteMallocBlock[32]; - BLOCK_EXPORT void * _NSConcreteAutoBlock[32]; - BLOCK_EXPORT void * _NSConcreteFinalizingBlock[32]; -@@ -207,6 +215,7 @@ BLOCK_EXPORT void * _NSConcreteWeakBlockVariable[32]; - // declared in Block.h - // BLOCK_EXPORT void * _NSConcreteGlobalBlock[32]; - // BLOCK_EXPORT void * _NSConcreteStackBlock[32]; -+#endif - - - // the intercept routines that must be used under GC -diff --git a/src/BlocksRuntime/BlocksRuntime.def b/src/BlocksRuntime/BlocksRuntime.def -index a3b1aab..a4142b2 100644 ---- a/src/BlocksRuntime/BlocksRuntime.def -+++ b/src/BlocksRuntime/BlocksRuntime.def -@@ -2,3 +2,7 @@ LIBRARY BlocksRuntime - EXPORTS - _NSConcreteGlobalBlock CONSTANT - _NSConcreteStackBlock CONSTANT -+ _NSConcreteMallocBlock CONSTANT -+ _NSConcreteAutoBlock CONSTANT -+ _NSConcreteFinalizingBlock CONSTANT -+ _NSConcreteWeakBlockVariable CONSTANT -diff --git a/src/BlocksRuntime/data.c b/src/BlocksRuntime/data.c -index fe4745b..f96ea25 100644 ---- a/src/BlocksRuntime/data.c -+++ b/src/BlocksRuntime/data.c -@@ -19,12 +19,15 @@ We keep these in a separate file so that we can include the runtime code in test - #if defined(_WIN32) - void * _NSConcreteStackBlock[32] = { 0 }; - void * _NSConcreteGlobalBlock[32] = { 0 }; -+void * _NSConcreteMallocBlock[32] = { 0 }; -+void * _NSConcreteAutoBlock[32] = { 0 }; -+void * _NSConcreteFinalizingBlock[32] = { 0 }; -+void * _NSConcreteWeakBlockVariable[32] = { 0 }; - #else - BLOCK_ABI void * _NSConcreteStackBlock[32] = { 0 }; - BLOCK_ABI void * _NSConcreteGlobalBlock[32] = { 0 }; --#endif -- - BLOCK_ABI void * _NSConcreteMallocBlock[32] = { 0 }; - BLOCK_ABI void * _NSConcreteAutoBlock[32] = { 0 }; - BLOCK_ABI void * _NSConcreteFinalizingBlock[32] = { 0 }; - BLOCK_ABI void * _NSConcreteWeakBlockVariable[32] = { 0 }; -+#endif diff --git a/patches/libdispatch-ext-blocksruntime.patch b/patches/libdispatch-ext-blocksruntime.patch new file mode 100644 index 0000000..c941c3a --- /dev/null +++ b/patches/libdispatch-ext-blocksruntime.patch @@ -0,0 +1,26 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 51f1f1b..564ddac 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -333,7 +333,7 @@ add_subdirectory(man) + add_subdirectory(os) + add_subdirectory(private) + if(NOT APPLE) +- add_subdirectory(src/BlocksRuntime) ++ include(cmake/modules/FindBlocksRuntime.cmake) + endif() + add_subdirectory(src) + if(BUILD_TESTING) +diff --git a/cmake/modules/FindBlocksRuntime.cmake b/cmake/modules/FindBlocksRuntime.cmake +index 111a5d6..3310b75 100644 +--- a/cmake/modules/FindBlocksRuntime.cmake ++++ b/cmake/modules/FindBlocksRuntime.cmake +@@ -17,7 +17,7 @@ if(BlocksRuntime_INCLUDE_DIR AND BlocksRuntime_LIBRARIES) + else() + find_path(BlocksRuntime_INCLUDE_DIR + NAMES +- Blocks.h ++ Block.h + HINTS + ${CMAKE_INSTALL_FULL_INCLUDEDIR}) + find_library(BlocksRuntime_LIBRARIES From c110bc0a9b226f721168addb25c54902eb4c14e3 Mon Sep 17 00:00:00 2001 From: hmelder Date: Fri, 24 Oct 2025 04:48:10 -0700 Subject: [PATCH 07/10] gnustep-base: Add blocksruntime patch --- patches/gnustep-base-blocksruntime.patch | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 patches/gnustep-base-blocksruntime.patch diff --git a/patches/gnustep-base-blocksruntime.patch b/patches/gnustep-base-blocksruntime.patch new file mode 100644 index 0000000..0143de4 --- /dev/null +++ b/patches/gnustep-base-blocksruntime.patch @@ -0,0 +1,22 @@ +commit a6f07549b8ea67e107a9a2fb3edadc7412311188 (HEAD -> blocks-rt) +Author: Hugo Melder +Date: Mon Oct 20 13:38:44 2025 +0200 + + Use standard blocks runtime header + +diff --git a/Headers/GNUstepBase/GSBlocks.h b/Headers/GNUstepBase/GSBlocks.h +index 758b21130..bf745cb26 100644 +--- a/Headers/GNUstepBase/GSBlocks.h ++++ b/Headers/GNUstepBase/GSBlocks.h +@@ -112,8 +112,8 @@ typedef retTy(^name)() + #define CALL_BLOCK_NO_ARGS(block) ({if (NULL != block) CALL_NON_NULL_BLOCK_NO_ARGS(block);}) + #define CALL_BLOCK_RET_NO_ARGS(block, rettype) ((NULL != block) ? (rettype)CALL_NON_NULL_BLOCK_NO_ARGS(block) : (rettype)0) + +-#if __has_include() +-# include ++#if __has_include() ++# include + #else + + #ifdef __cplusplus + From 0e08049457ecc4f0ae6a5c7f4d651b35403fb933 Mon Sep 17 00:00:00 2001 From: hmelder Date: Fri, 24 Oct 2025 04:48:50 -0700 Subject: [PATCH 08/10] gnustep-make: Add BlocksRuntime to LDFLAGS --- phases/21-gnustep-make.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phases/21-gnustep-make.sh b/phases/21-gnustep-make.sh index e9d0258..298c5e2 100755 --- a/phases/21-gnustep-make.sh +++ b/phases/21-gnustep-make.sh @@ -32,7 +32,8 @@ fi --prefix="$UNIX_INSTALL_PREFIX" \ --with-library-combo=ng-gnu-gnu \ --with-runtime-abi=gnustep-2.2 \ - CFLAGS="$CFLAGS" \ + CFLAGS="$CFLAGS -I$UNIX_INSTALL_PREFIX/include/BlocksRuntime" \ + LDFLAGS="$LDFLAGS -lBlocksRuntime -L$UNIX_INSTALL_PREFIX/lib" \ $CONFIGURE_OPTS echo From e5d67c3a0819ee389d594b17bd968c8ddb72d98d Mon Sep 17 00:00:00 2001 From: hmelder Date: Fri, 24 Oct 2025 04:50:33 -0700 Subject: [PATCH 09/10] Add BlocksRuntime.lib to example linker invocation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e31070..06fd454 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Alternatively, `clang-cl.exe` can be used to build Objective-C code directly in clang-cl -I C:\GNUstep\x64\Debug\include -fobjc-runtime=gnustep-2.0 -Xclang -fexceptions -Xclang -fobjc-exceptions -fblocks -DGNUSTEP -DGNUSTEP_WITH_DLL -DGNUSTEP_RUNTIME=1 -D_NONFRAGILE_ABI=1 -D_NATIVE_OBJC_EXCEPTIONS /MDd /Z7 /c test.m # link object file into executable using the LLD linker - clang-cl test.obj gnustep-base.lib objc.lib dispatch.lib -fuse-ld=lld /MDd /Z7 -o test.exe /link /LIBPATH:C:\GNUstep\x64\Debug\lib + clang-cl test.obj gnustep-base.lib objc.lib BlocksRuntime.lib dispatch.lib -fuse-ld=lld /MDd /Z7 -o test.exe /link /LIBPATH:C:\GNUstep\x64\Debug\lib Specify `/MDd` for debug builds, and `/MD` for release builds, in order to link against the same runtime libraries as the DLLs in `C:\GNUstep\x64\Debug` and `C:\GNUstep\x64\Release` respectively. Adding `/Z7` [adds full debug symbols](https://learn.microsoft.com/cpp/build/reference/z7-zi-zi-debug-information-format#z7). From e2c6657a0a8c849a6dfc908b2420cec49fd68d12 Mon Sep 17 00:00:00 2001 From: hmelder Date: Mon, 27 Oct 2025 04:04:34 -0700 Subject: [PATCH 10/10] Update libobjc2 patch --- patches/libobjc2-blocksrt-detection.patch | 4219 +++++++++++++++++++-- 1 file changed, 3841 insertions(+), 378 deletions(-) diff --git a/patches/libobjc2-blocksrt-detection.patch b/patches/libobjc2-blocksrt-detection.patch index 690e14b..ed88290 100644 --- a/patches/libobjc2-blocksrt-detection.patch +++ b/patches/libobjc2-blocksrt-detection.patch @@ -1,380 +1,3843 @@ -From d5d32112d701dc8ed63fe7ca337f88372c8444fc Mon Sep 17 00:00:00 2001 -From: hmelder -Date: Thu, 9 Oct 2025 04:34:06 -0700 -Subject: [PATCH 1/6] remove unused CMake directory - ---- - CMake/CMakeLists.txt | 17 ------------ - CMake/typeinfo_test.cc | 62 ------------------------------------------ - 2 files changed, 79 deletions(-) - delete mode 100644 CMake/CMakeLists.txt - delete mode 100644 CMake/typeinfo_test.cc - -diff --git a/CMake/CMakeLists.txt b/CMake/CMakeLists.txt -deleted file mode 100644 -index a16bffff..00000000 ---- a/CMake/CMakeLists.txt -+++ /dev/null -@@ -1,17 +0,0 @@ --cmake_minimum_required(VERSION 3.2) --project(test_cxx_runtime) -- --add_executable(test_cxx_runtime typeinfo_test.cc) --add_executable(test_cxx_stdlib typeinfo_test.cc) --if (CXX_RUNTIME) -- if (CXX_RUNTIME MATCHES ".*libc\\+\\+abi.*") -- find_library(M_LIBRARY m) -- if (M_LIBRARY) -- target_link_libraries(test_cxx_runtime ${M_LIBRARY}) -- endif() -- endif() -- set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") -- target_link_libraries(test_cxx_runtime ${CXX_RUNTIME}) -- set_target_properties(test_cxx_runtime PROPERTIES -- LINKER_LANGUAGE C) --endif() -diff --git a/CMake/typeinfo_test.cc b/CMake/typeinfo_test.cc -deleted file mode 100644 -index 1d5536b2..00000000 ---- a/CMake/typeinfo_test.cc -+++ /dev/null -@@ -1,62 +0,0 @@ --#include -- --namespace __cxxabiv1 --{ -- struct __class_type_info; --} -- --using __cxxabiv1::__class_type_info; -- --namespace std --{ -- /** -- * std::type_info defined with the GCC ABI. This may not be exposed in -- * public headers, but is required for correctly implementing the unified -- * exception model. -- */ -- class type_info -- { -- public: -- virtual ~type_info(); -- bool operator==(const type_info &) const; -- bool operator!=(const type_info &) const; -- bool before(const type_info &) const; -- private: -- type_info(const type_info& rhs); -- type_info& operator= (const type_info& rhs); -- const char *__type_name; -- protected: -- type_info(const char *name): __type_name(name) { } -- public: -- const char* name() const { return __type_name; } -- virtual bool __is_pointer_p() const; -- virtual bool __is_function_p() const; -- virtual bool __do_catch(const type_info *thrown_type, -- void **thrown_object, -- unsigned outer) const; -- virtual bool __do_upcast( -- const __class_type_info *target, -- void **thrown_object) const; -- }; --} -- --class type_info2 : public std::type_info --{ -- public: -- type_info2() : type_info("foo") {} -- virtual bool __is_pointer_p() const; -- virtual bool __is_function_p() const { return true; } -- virtual bool __do_catch(const type_info *thrown_type, -- void **thrown_object, -- unsigned outer) const { return true; } -- virtual bool __do_upcast( -- const __class_type_info *target, -- void **thrown_object) const { return true; }; --}; --bool type_info2::__is_pointer_p() const { return true; } -- --int main() --{ -- type_info2 s; -- return s.__is_pointer_p(); --} - -From 9d8fb81d30bd298cbe06a474ee8d14d4cfb000c9 Mon Sep 17 00:00:00 2001 -From: hmelder -Date: Thu, 9 Oct 2025 04:50:11 -0700 -Subject: [PATCH 2/6] Add FindBlocksRuntime.cmake from the libdispatch project - -This is a slightly modified version of the file found in swift-corelibs-libdispatch. Notabily, the non-existent HINTS are removed. ---- - cmake/FindBlocksRuntime.cmake | 44 +++++++++++++++++++++++++++++++++++ - 1 file changed, 44 insertions(+) - create mode 100644 cmake/FindBlocksRuntime.cmake - -diff --git a/cmake/FindBlocksRuntime.cmake b/cmake/FindBlocksRuntime.cmake -new file mode 100644 -index 00000000..c623065e ---- /dev/null -+++ b/cmake/FindBlocksRuntime.cmake -@@ -0,0 +1,44 @@ -+#.rst: -+# FindBlocksRuntime -+# ----------------- -+# -+# Find libBlocksRuntime library and headers. -+# -+# The module defines the following variables: -+# -+# ## -+# -+# BlocksRuntime_FOUND - true if libBlocksRuntime was found -+# BlocksRuntime_INCLUDE_DIR - include search path -+# BlocksRuntime_LIBRARIES - libraries to link -+ -+if(BlocksRuntime_INCLUDE_DIR AND BlocksRuntime_LIBRARIES) -+ set(BlocksRuntime_FOUND TRUE) -+else() -+ find_path(BlocksRuntime_INCLUDE_DIR -+ NAMES -+ Block.h Block_private.h) -+ find_library(BlocksRuntime_LIBRARIES -+ NAMES -+ BlocksRuntime libBlocksRuntime) -+ -+ include(FindPackageHandleStandardArgs) -+ find_package_handle_standard_args(BlocksRuntime -+ REQUIRED_VARS -+ BlocksRuntime_LIBRARIES -+ BlocksRuntime_INCLUDE_DIR) -+ -+ mark_as_advanced(BlocksRuntime_LIBRARIES BlocksRuntime_INCLUDE_DIR) -+endif() -+ -+if(BlocksRuntime_FOUND) -+ if(NOT TARGET BlocksRuntime::BlocksRuntime) -+ add_library(BlocksRuntime::BlocksRuntime UNKNOWN IMPORTED) -+ set_target_properties(BlocksRuntime::BlocksRuntime -+ PROPERTIES -+ IMPORTED_LOCATION -+ ${BlocksRuntime_LIBRARIES} -+ INTERFACE_INCLUDE_DIRECTORIES -+ ${BlocksRuntime_INCLUDE_DIR}) -+ endif() -+endif() - -From 08acb0aacbdd8afd5f52510d4b3013c004a54b0c Mon Sep 17 00:00:00 2001 -From: hmelder -Date: Thu, 9 Oct 2025 04:34:24 -0700 -Subject: [PATCH 3/6] CMakeLists.txt: Use FindBlocksRuntime + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Cleanup CMake configuration for external blocks runtime support by hmelder · Pull Request #355 · gnustep/libobjc2 · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + +
+ Skip to content + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + +
+ + + + + +
+ + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ + + + / + + libobjc2 + + + Public +
+ + +
+ +
+ + +
+
+ +
+
+ + + + +
+ + + + + + +
+ + + + + + +
+ +
+ + + +
+ + + +
+ + + + +
+ + + + + + + + +
+
+

Conversation

+
+ + + +
+ +
+ + + @hmelder +
+
+
+
+
+ + + + + + + + + + + + Copy link + +
+
+
+
+ +
+ + + + Member + + + + +
+ +

+
+ @hmelder + + + hmelder + + + + + + + commented + + + Oct 20, 2025 + + + +
+ +

+
+ +
+
+ + +
+

This pull request addresses the following issues:

+
    +
  • The check_symbol_exists check fails, when Block.h is located in the CMAKE_PREFIX_PATH.
  • +
  • Internal blocks runtime is always compiled, resulting in duplicate symbol errors on Windows and WebAssembly.
  • +
  • Internal blocks runtime test is always compiled and executed.
  • +
  • External symbols from the blocks runtime are incorrectly imported on Windows
  • +
+
+
+ +
+ +
+ +
+ + +

+ + + + + +

+ + + +
+
+
+ +
+ +
+
+
+ + + + +
+ + +
+ +
+ +
+
@hmelder + hmelder + + + requested a review + from davidchisnall + + + October 20, 2025 10:43 + +
+
+
+ +
+
@hmelder + hmelder + + + force-pushed + the + + + cmake-fix-include-dirs + + + + branch + from + f557cc1 to + 6a18e54 + Compare + + + + + October 20, 2025 10:49 + +
+
+
+
+ +
+ +
+ +
+ This was referenced Oct 20, 2025 +
+ + + + + + +
+
+ + + + + +
+
+ + + +
+ +
+ +
+
+ +
+
hmelder + + + added 6 commits + October 27, 2025 11:36
+
+
+ +
+
+
+
+ +
+
+ + @hmelder +
+
+ + + +
+ + + + + + + + +
+ +
+
+ + + + + + + + +
+ +
+ +
+
+
+ +
+ + 2693fd4 + +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ + @hmelder +
+
+ + + +
+ + + + + + + + +
+ +
+
+ + + + + + + + +
+ +
+ +
+
+
+ +
+ + 708e17f + +
+
+
+
+
This is a slightly modified version of the file found in swift-corelibs-libdispatch. Notabily, the non-existent HINTS are removed.
+
+
+ +
+
+ +
+
+
+
+ +
+
+ + @hmelder +
+
+ +
+ + :STRICT_APPLE_COM - configure_file(objc/objc-config.h.in objc/objc-config.h @ONLY) - include_directories("${PROJECT_BINARY_DIR}/objc/") - -+if (EMBEDDED_BLOCKS_RUNTIME) -+ list(APPEND libobjc_ASM_SRCS block_trampolines.S) -+ list(APPEND libobjc_C_SRCS block_to_imp.c) -+endif() -+ - if (OLDABI_COMPAT) - list(APPEND libobjc_C_SRCS legacy.c abi_version.c statics_loader.c) - add_definitions(-DOLDABI_COMPAT=1) -@@ -242,18 +249,9 @@ if (EMBEDDED_BLOCKS_RUNTIME) - list(APPEND libobjc_HDRS objc/blocks_runtime.h) - add_definitions(-DEMBEDDED_BLOCKS_RUNTIME) - else () -- find_library(BLOCKS_RUNTIME_LIBRARY BlocksRuntime) -- if (BLOCKS_RUNTIME_LIBRARY) -- set(CMAKE_REQUIRED_LIBRARIES ${BLOCKS_RUNTIME_LIBRARY}) -- check_symbol_exists(_Block_use_RR2 "Block_private.h" HAVE_BLOCK_USE_RR2) -- if (HAVE_BLOCK_USE_RR2) -- add_definitions(-DHAVE_BLOCK_USE_RR2) -- else () -- message(FATAL_ERROR "libBlocksRuntime does not contain _Block_use_RR2(). Enable EMBEDDED_BLOCKS_RUNTIME to use the built-in blocks runtime.") -- endif () -- unset(CMAKE_REQUIRED_LIBRARIES) -- else () -- message(FATAL_ERROR "libBlocksRuntime not found. Enable EMBEDDED_BLOCKS_RUNTIME to use the built-in blocks runtime.") -+ find_package(BlocksRuntime) -+ if (NOT BlocksRuntime_FOUND) -+ message(FATAL_ERROR "An external blocks runtime is required when not using the embedded one.") - endif () - endif () - -@@ -270,6 +268,22 @@ if (WIN32 AND NOT MINGW) - target_link_libraries(objc PUBLIC ntdll.dll) - endif() - -+if (NOT EMBEDDED_BLOCKS_RUNTIME) -+ # Check if the blocks runtime exports _Block_use_RR2 -+ set(CMAKE_REQUIRED_LIBRARIES ${BlocksRuntime_LIBRARIES}) -+ set(CMAKE_REQUIRED_INCLUDES ${BlocksRuntime_INCLUDE_DIR}) -+ check_symbol_exists(_Block_use_RR2 "Block_private.h" HAVE_BLOCK_USE_RR2) -+ unset(CMAKE_REQUIRED_LIBRARIES) -+ unset(CMAKE_REQUIRED_INCLUDES) -+ -+ if (NOT HAVE_BLOCK_USE_RR2) -+ message(FATAL_ERROR "The external blocks runtime is not supported. It does not export _Block_use_RR2().") -+ endif() -+ -+ target_compile_definitions(objc PRIVATE HAVE_BLOCK_USE_RR2) -+ target_link_libraries(objc PUBLIC BlocksRuntime::BlocksRuntime) -+endif() -+ - target_link_libraries(objc PRIVATE tsl::robin_map) - - set_target_properties(objc PROPERTIES -@@ -295,10 +309,6 @@ if (M_LIBRARY) - target_link_libraries(objc PUBLIC ${M_LIBRARY}) - endif () - --if (BLOCKS_RUNTIME_LIBRARY) -- target_link_libraries(objc PUBLIC ${BLOCKS_RUNTIME_LIBRARY}) --endif () -- - # Make weak symbols work on OS X - if (APPLE) - set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS - -From 9320daefcaccb0418b535d83e75a8c2017deec50 Mon Sep 17 00:00:00 2001 -From: hmelder -Date: Thu, 9 Oct 2025 04:36:42 -0700 -Subject: [PATCH 4/6] Only call init_trampolines when using the internal blocks - rt - ---- - loader.c | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/loader.c b/loader.c -index 449d7a7c..f4df0471 100644 ---- a/loader.c -+++ b/loader.c -@@ -59,7 +59,9 @@ static void init_runtime(void) - init_alias_table(); - init_early_blocks(); - init_arc(); -+#if defined(EMBEDDED_BLOCKS_RUNTIME) - init_trampolines(); -+#endif - init_builtin_classes(); - first_run = NO; - if (getenv("LIBOBJC_MEMORY_PROFILE")) - -From 5c7378c1ba6809cab4d539531bd0dcff6576dea2 Mon Sep 17 00:00:00 2001 -From: hmelder -Date: Thu, 9 Oct 2025 04:38:11 -0700 -Subject: [PATCH 5/6] Conditionally include BlockImpTest.m - ---- - Test/CMakeLists.txt | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt -index 3e37fb79..3aa27b73 100644 ---- a/Test/CMakeLists.txt -+++ b/Test/CMakeLists.txt -@@ -16,7 +16,6 @@ set(TESTS - AllocatePair.m - AssociatedObject.m - AssociatedObject2.m -- BlockImpTest.m - BlockTest_arc.m - ConstantString.m - Category.m -@@ -54,6 +53,10 @@ set(TESTS - UnexpectedException.m - ) - -+if (EMBEDDED_BLOCKS_RUNTIME) -+ list(APPEND TESTS BlockImpTest.m) -+endif() -+ - set(ENABLE_ALL_OBJC_ARC_TESTS On) - - if (WIN32) - -From 6a18e54a0209051d37db00d76b668d8f3ac23627 Mon Sep 17 00:00:00 2001 -From: hmelder -Date: Thu, 9 Oct 2025 04:39:13 -0700 -Subject: [PATCH 6/6] External symbols should be imported from the DLL - ---- - NSBlocks.m | 12 ++++++++---- - 1 file changed, 8 insertions(+), 4 deletions(-) - -diff --git a/NSBlocks.m b/NSBlocks.m -index 49eee9d9..e5cccbdb 100644 ---- a/NSBlocks.m -+++ b/NSBlocks.m -@@ -7,10 +7,14 @@ - #include - - #ifdef EMBEDDED_BLOCKS_RUNTIME --#define BLOCK_STORAGE OBJC_PUBLIC -+# define BLOCK_STORAGE OBJC_PUBLIC - #else --#define BLOCK_STORAGE extern --#endif -+# if defined(_WIN32) -+# define BLOCK_STORAGE __attribute__((dllimport)) -+# else -+# define BLOCK_STORAGE extern -+# endif // defined(_WIN32) -+#endif // EMBEDDED_BLOCKS_RUNTIME - - BLOCK_STORAGE struct objc_class _NSConcreteGlobalBlock; - BLOCK_STORAGE struct objc_class _NSConcreteStackBlock; -@@ -76,4 +80,4 @@ PRIVATE void init_early_blocks(void) - _NSConcreteMallocBlock.info = objc_class_flag_is_block; - _NSConcreteAutoBlock.info = objc_class_flag_is_block; - _NSConcreteFinalizingBlock.info = objc_class_flag_is_block; --} -\ No newline at end of file -+} +and do not compile the internal one." data-pjax="true" class="Link--secondary markdown-title" href="/gnustep/libobjc2/pull/355/commits/760eb37d839b0799f66a2601de8d19e6bf7c6024">CMakeLists.txt: Use FindBlocksRuntime + + + + +
+ +
+ + + + + + + + +
+ +
+
+ + + + + + + + +
+ +
+ +
+
+
+ +
+ + 760eb37 + +
+
+
+
+
Use cmake/FindBlocksRuntime.cmake to locate the external blocks runtime,
+and do not compile the internal one.
+
+
+ +
+
+ +
+
+
+
+ +
+
+ + @hmelder +
+
+ + + +
+ + + + + + + + +
+ +
+
+ + + + + + + + +
+ +
+ +
+
+
+ +
+ + 2d88c0b + +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ + @hmelder +
+
+ + + +
+ + + + + + + + +
+ +
+
+ + + + + + + + +
+ +
+ +
+
+
+ +
+ + 0708874 + +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ + @hmelder +
+
+ + + +
+ + + + + + + + +
+ +
+
+ + + + + + + + +
+ +
+ +
+
+
+ +
+ + fca3146 + +
+
+
+
+ +
+
+
+ + +
+ +
+ +
+ +
+
@hmelder + hmelder + + + force-pushed + the + + + cmake-fix-include-dirs + + + + branch + from + 6a18e54 to + fca3146 + Compare + + + + + October 27, 2025 10:37 + +
+
+
+ +
+
@hmelder + hmelder + + + requested review from + davidchisnall + + and removed request for + davidchisnall + + + October 27, 2025 10:52 + +
+
+ + +
+ +
+ + +
+ +
+ @hmelder + + +
+ + + +
+ +
+
+
+
+ + + + + + + + + + + + Copy link + +
+
+
+
+ +
+ + + + Member + + + + + Author + + +
+ +

+
+ + + + hmelder + + + + + + + commented + + + Oct 27, 2025 + + + +
+ +

+
+ + +
+ + + + + + + + + +
+

Rebased to latest master

+ +
+
+ + +
+ + + + +
+ +
+
+
+ +
+ + +

+ + + + + +

+ + + +
+
+
+ +
+ + +
+ + + + + + + +
+
+ +
+ + + +
+ +
+ +
+
+ +
+ + Sign up for free + to join this conversation on GitHub. + Already have an account? + Sign in to comment + + + +
+ +
+
+
+ +
+
+
+ + + + + + + + + + +
+ + + +

+ Labels +

+ + +
+ None yet +
+ +
+ + + + + + + + + + +
+
+
+ +
+ +

+ Development +

+ + + + +

Successfully merging this pull request may close these issues.

+ + + + + + + + +
+
+
+
+ +
+ + + + +
+
+

+ 1 participant +

+
+ + @hmelder +
+
+
+ + + + + + + + + + + + +
+ + +
+ +
+
+ + + +
+ + +
+ +
+ + +
+
+ +
+ +
+

Footer

+ + + + +
+
+ + + + + © 2025 GitHub, Inc. + +
+ + +
+
+ + + + + + + + + + + + + + + + + + + + +
+
+
+ + +