Skip to content

Commit 27efb0c

Browse files
[wasm] Build the vendored version of BlocksRuntime on WASI
We had been using the vendored BlocksRuntime on WASI, but the build configuration was removed during the recore. This change restores the vendored BlocksRuntime build configuration on WASI.
1 parent f91a759 commit 27efb0c

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
##===----------------------------------------------------------------------===##
2+
##
3+
## This source file is part of the Swift open source project
4+
##
5+
## Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
## Licensed under Apache License v2.0
7+
##
8+
## See LICENSE.txt for license information
9+
## See CONTRIBUTORS.md for the list of Swift project authors
10+
##
11+
## SPDX-License-Identifier: Apache-2.0
12+
##
13+
##===----------------------------------------------------------------------===##
14+
15+
# Build the vendored version of the BlocksRuntime library, which is used by
16+
# platforms that don't support libdispatch.
17+
18+
add_library(BlocksRuntime
19+
data.c
20+
runtime.c)
21+
22+
target_include_directories(BlocksRuntime PUBLIC
23+
${CMAKE_CURRENT_SOURCE_DIR}/include
24+
# For CFTargetConditionals.h
25+
${CMAKE_CURRENT_SOURCE_DIR}/../include)
26+
27+
set_target_properties(BlocksRuntime PROPERTIES
28+
POSITION_INDEPENDENT_CODE FALSE)
29+
30+
add_library(BlocksRuntime::BlocksRuntime ALIAS BlocksRuntime)
31+
32+
if(NOT BUILD_SHARED_LIBS)
33+
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS BlocksRuntime)
34+
install(TARGETS BlocksRuntime
35+
ARCHIVE DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${SWIFT_SYSTEM_NAME}
36+
LIBRARY DESTINATION lib/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>/${SWIFT_SYSTEM_NAME})
37+
endif()

Sources/CoreFoundation/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ target_link_libraries(CoreFoundation
118118
_FoundationICU
119119
dispatch)
120120

121+
if(CMAKE_SYSTEM_NAME STREQUAL WASI)
122+
# On WASI, we use vendored BlocksRuntime instead of the one from libdispatch
123+
add_subdirectory(BlockRuntime)
124+
target_link_libraries(CoreFoundation PRIVATE BlocksRuntime)
125+
endif()
126+
121127
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS CoreFoundation)
122128

123129
# Copy Headers to known directory for direct client (XCTest) test builds

Sources/_CFXMLInterface/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ target_link_libraries(_CFXMLInterface PRIVATE
3333
dispatch
3434
LibXml2::LibXml2)
3535

36+
if(CMAKE_SYSTEM_NAME STREQUAL WASI)
37+
target_link_libraries(_CFXMLInterface PRIVATE BlocksRuntime)
38+
endif()
39+
3640
if(NOT BUILD_SHARED_LIBS)
3741
set_property(GLOBAL APPEND PROPERTY Foundation_EXPORTS _CFXMLInterface)
3842
install(TARGETS _CFXMLInterface

0 commit comments

Comments
 (0)