diff options
author | Evan Wilde <etceterawilde@gmail.com> | 2024-03-24 02:02:55 (GMT) |
---|---|---|
committer | Evan Wilde <etceterawilde@gmail.com> | 2024-04-15 15:23:39 (GMT) |
commit | 56e5cea6008397f83479952d4c59964c32bc35fd (patch) | |
tree | b7fc9b925f9a9967c55f8189d964149bfcfbde69 /Tests/SwiftOnly | |
parent | 6e545349143ee7ce14cfa213e5ae41586836b2c6 (diff) | |
download | CMake-56e5cea6008397f83479952d4c59964c32bc35fd.zip CMake-56e5cea6008397f83479952d4c59964c32bc35fd.tar.gz CMake-56e5cea6008397f83479952d4c59964c32bc35fd.tar.bz2 |
Swift: Support module libraries with command-line build systems
Wire up the flags needed to support module libraries built and used with
Swift. We need to pass `-bundle` to the linker when linking module
libraries on Darwin, and we need to pass `-export-dynamic` to the linker
when emitting an executable that exports symbols on Linux. This patch
wires up `CMAKE_SHARED_MODULE_CREATE_Swift_FLAGS` and
`CMAKE_SHARED_MODULE_LOADER_Swift_FLAG` on Darwin, and hooks up
`CMAKE_EXE_EXPORTS_Swift_FLAG` on Linux in order to support passing
things correctly.
We can't expose `CMAKE_EXE_LINKER_FLAGS` to Swift, as it contains flags
that the Swift compiler doesn't recognize, but the other
language-specific variables are safe to expose.
Diffstat (limited to 'Tests/SwiftOnly')
-rw-r--r-- | Tests/SwiftOnly/CMakeLists.txt | 11 | ||||
-rw-r--r-- | Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/SwiftOnly/SwiftPlugin/main.swift | 3 | ||||
-rw-r--r-- | Tests/SwiftOnly/SwiftPlugin/plugin.swift | 2 |
4 files changed, 4 insertions, 14 deletions
diff --git a/Tests/SwiftOnly/CMakeLists.txt b/Tests/SwiftOnly/CMakeLists.txt index 3d2fe73..4754711 100644 --- a/Tests/SwiftOnly/CMakeLists.txt +++ b/Tests/SwiftOnly/CMakeLists.txt @@ -54,16 +54,7 @@ endif() add_library(SwiftIface INTERFACE) target_link_libraries(SwiftOnly PRIVATE SwiftIface) -# @_alwaysEmitIntoClient ensures that the function body is inserted into the -# swiftmodule instead of as a symbol in the binary itself. I'm doing this to -# avoid having to link the executable. There are some flags required in order to -# link an executable into a library that I didn't see CMake emitting for Swift -# on macOS. AEIC is the easiest workaround that still tests this functionality. -# Unfortunately, AEIC was only added recently (~Swift 5.2), so we need to check -# that it is available before using it. -if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.2) - add_subdirectory("SwiftPlugin") -endif() +add_subdirectory("SwiftPlugin") function(test_cmp0157_default mode) if(POLICY CMP0157) diff --git a/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt b/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt index 4069f16..2bfbc8a 100644 --- a/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt +++ b/Tests/SwiftOnly/SwiftPlugin/CMakeLists.txt @@ -1,5 +1,5 @@ add_executable(main main.swift) set_target_properties(main PROPERTIES ENABLE_EXPORTS TRUE) -add_library(plugin plugin.swift) +add_library(plugin MODULE plugin.swift) target_link_libraries(plugin PRIVATE main) diff --git a/Tests/SwiftOnly/SwiftPlugin/main.swift b/Tests/SwiftOnly/SwiftPlugin/main.swift index f5aac51..caba1fb 100644 --- a/Tests/SwiftOnly/SwiftPlugin/main.swift +++ b/Tests/SwiftOnly/SwiftPlugin/main.swift @@ -1,4 +1,3 @@ -@_alwaysEmitIntoClient -public func exported() -> Int { 32 } +public func exported() -> Int { return 32 } print(exported()) diff --git a/Tests/SwiftOnly/SwiftPlugin/plugin.swift b/Tests/SwiftOnly/SwiftPlugin/plugin.swift index e84f248..d00ca33 100644 --- a/Tests/SwiftOnly/SwiftPlugin/plugin.swift +++ b/Tests/SwiftOnly/SwiftPlugin/plugin.swift @@ -1,3 +1,3 @@ import main -public func importing() -> Int { main.exported() + 1 } +public func importing() -> Int { return main.exported() + 1 } |