From 542f3e5ccaa969aa17a297cf231d62914a7a6751 Mon Sep 17 00:00:00 2001 From: Undefine Date: Fri, 24 Apr 2026 20:30:59 +0200 Subject: [PATCH] AK+Meta: Make AK / ObjC interop MacOS only This is entirely unused but still could be useful in the AppKit port. Originally this was meant for Swift interop which is why it had support for other platforms, but now it's causing issues on systems like FreeBSD, so lets just gate it behind the only platform it's useful for. We also assume that Objective C blocks and Arc are supported for the AppKit port to build so no need to check for that in CMake. --- AK/Platform.h | 4 ++-- Meta/CMake/FindBlocksRuntime.cmake | 17 ----------------- Meta/CMake/cmake_options.cmake | 20 -------------------- Tests/AK/CMakeLists.txt | 7 ++----- 4 files changed, 4 insertions(+), 44 deletions(-) delete mode 100644 Meta/CMake/FindBlocksRuntime.cmake diff --git a/AK/Platform.h b/AK/Platform.h index ac6b7d8ea0..a95420d53f 100644 --- a/AK/Platform.h +++ b/AK/Platform.h @@ -263,11 +263,11 @@ # define LSAN_IGNORE_OBJECT(base) #endif -#if __has_feature(blocks) +#if __has_feature(blocks) && defined(AK_OS_MACOS) # define AK_HAS_BLOCKS #endif -#if __has_feature(objc_arc) +#if __has_feature(objc_arc) && defined(AK_OS_MACOS) # define AK_HAS_OBJC_ARC #endif diff --git a/Meta/CMake/FindBlocksRuntime.cmake b/Meta/CMake/FindBlocksRuntime.cmake deleted file mode 100644 index b11bc57808..0000000000 --- a/Meta/CMake/FindBlocksRuntime.cmake +++ /dev/null @@ -1,17 +0,0 @@ -# Finds the BlocksRuntime library -# On Apple platforms, this does not exist and is folded into other System libraries - -find_library(BLOCKS_RUNTIME NAMES BlocksRuntime) -if (BLOCKS_RUNTIME) - if (NOT TARGET BlocksRuntime::BlocksRuntime) - add_library(BlocksRuntime::BlocksRuntime IMPORTED UNKNOWN) - message(STATUS "Found BlocksRuntime: ${BLOCKS_RUNTIME}") - cmake_path(GET BLOCKS_RUNTIME PARENT_PATH _BLOCKS_RUNTIME_DIR) - set_target_properties(BlocksRuntime::BlocksRuntime PROPERTIES - IMPORTED_LOCATION "${BLOCKS_RUNTIME}" - INTERFACE_LINK_DIRECTORIES "${_BLOCKS_RUNTIME_DIR}" - INTERFACE_COMPILE_OPTIONS "$<$:-fblocks>" - ) - endif() - set(BlocksRuntime_FOUND TRUE) -endif() diff --git a/Meta/CMake/cmake_options.cmake b/Meta/CMake/cmake_options.cmake index 3b27f78c06..ef1326eeac 100644 --- a/Meta/CMake/cmake_options.cmake +++ b/Meta/CMake/cmake_options.cmake @@ -52,24 +52,4 @@ if (ENABLE_FUZZERS_LIBFUZZER) set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE STRING "Type of target to use for try_compile()" FORCE) endif() -include(CheckCXXSourceCompiles) -set(BLOCKS_REQUIRED_LIBRARIES "") -if (NOT APPLE) - find_package(BlocksRuntime) - if (BlocksRuntime_FOUND) - set(BLOCKS_REQUIRED_LIBRARIES BlocksRuntime::BlocksRuntime) - set(CMAKE_REQUIRED_LIBRARIES BlocksRuntime::BlocksRuntime) - endif() -endif() -check_cxx_source_compiles([=[ - int main() { __block int x = 0; auto b = ^{++x;}; b(); } -]=] CXX_COMPILER_SUPPORTS_BLOCKS) - -set(CMAKE_REQUIRED_FLAGS "-fobjc-arc") -check_cxx_source_compiles([=[ - int main() { auto b = ^{}; auto __weak w = b; w(); } -]=] CXX_COMPILER_SUPPORTS_OBJC_ARC) -unset(CMAKE_REQUIRED_FLAGS) -unset(CMAKE_REQUIRED_LIBRARIES) - include(${CMAKE_CURRENT_LIST_DIR}/lagom_install_options.cmake) diff --git a/Tests/AK/CMakeLists.txt b/Tests/AK/CMakeLists.txt index a85bbb4f45..7fa461fbaa 100644 --- a/Tests/AK/CMakeLists.txt +++ b/Tests/AK/CMakeLists.txt @@ -103,14 +103,11 @@ if (WIN32) target_link_libraries(TestUFixedBigInt PRIVATE clang_rt.builtins-x86_64.lib) endif() -if (CXX_COMPILER_SUPPORTS_BLOCKS) +if (APPLE) ladybird_test(TestFunctionObjC.mm AK NAME TestFunctionObjC) - target_link_libraries(TestFunctionObjC PRIVATE ${BLOCKS_REQUIRED_LIBRARIES}) -endif() -if (CXX_COMPILER_SUPPORTS_OBJC_ARC) + ladybird_test(TestFunctionObjC.mm AK NAME TestFunctionObjCArc) target_compile_options(TestFunctionObjCArc PRIVATE -fobjc-arc) - target_link_libraries(TestFunctionObjCArc PRIVATE ${BLOCKS_REQUIRED_LIBRARIES}) endif() target_link_libraries(TestString PRIVATE LibUnicode)