Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autolink wasi-libc emulation libraries #843

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,25 @@ foreach(version ${_SwiftFoundation_versions})
endforeach()
endforeach()

# wasi-libc emulation feature flags
# wasi-libc emulation feature flags passed to the Swift compiler
set(_SwiftFoundation_wasi_libc_flags)
# wasi-libc emulation libraries to link against when building a shared library
set(_SwiftFoundation_wasi_libc_libraries)
if(CMAKE_SYSTEM_NAME STREQUAL "WASI")
list(APPEND _SwiftFoundation_wasi_libc_flags
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xcc -D_WASI_EMULATED_GETPID>"
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xcc -D_WASI_EMULATED_SIGNAL>"
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xcc -D_WASI_EMULATED_MMAN>")
if(BUILD_SHARED_LIBS)
# Link emulation libraries to the shared library directly when building a shared library
list(APPEND _SwiftFoundation_wasi_libc_libraries wasi-emulated-getpid wasi-emulated-signal wasi-emulated-mman)
else()
# Emit autolink entries to let clients to link against the emulation libraries
list(APPEND _SwiftFoundation_wasi_libc_flags
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend wasi-emulated-getpid>"
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend wasi-emulated-signal>"
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -public-autolink-library -Xfrontend wasi-emulated-mman>")
endif()
endif()

include(GNUInstallDirs)
Expand Down
1 change: 1 addition & 0 deletions Sources/FoundationEssentials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ target_compile_options(FoundationEssentials PRIVATE -package-name "SwiftFoundati
target_link_libraries(FoundationEssentials PUBLIC
_FoundationCShims
_FoundationCollections)
target_link_libraries(FoundationEssentials PUBLIC ${_SwiftFoundation_wasi_libc_libraries})

if(NOT BUILD_SHARED_LIBS)
target_compile_options(FoundationEssentials PRIVATE
Expand Down
1 change: 1 addition & 0 deletions Sources/FoundationInternationalization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ target_link_libraries(FoundationInternationalization PUBLIC
FoundationEssentials
_FoundationCShims
_FoundationICU)
target_link_libraries(FoundationInternationalization PUBLIC ${_SwiftFoundation_wasi_libc_libraries})

if(NOT BUILD_SHARED_LIBS)
target_compile_options(FoundationInternationalization PRIVATE
Expand Down