Skip to content

Commit b2e5d86

Browse files
authored
[lit] Use CMAKE_C_FLAGS and CMAKE_EXE_LINKER_FLAGS when compiling test plugin (#70136)
In cases where the swift-plugin-server is built with specialized `CMAKE_C_FLAGS` and/or `CMAKE_EXE_LINKER_FLAGS`, if one wants to load a plugin in it, one needs to build with a compatible set of flags, or the plugin will not be able to be loaded. Most of the time the tests can build against the `/` sysroot and be fine, but in the case of these test plugins, since they have to be loaded into the swift-plugin-server process, they need to compiled and linked in a compatible way. Using `CMAKE_C_FLAGS` and `CMAKE_EXE_LINKER_FLAGS` uses the same set of flags in both cases, and allow loading these test plugins during testing and avoid failures. The change in `lit.site.cfg.in` embeds the values of `CMAKE_C_FLAGS` and `CMAKE_EXE_LINKER_FLAGS` from CMake into the Lit configuration. The usage of raw triple quoted strings allow single and double quoted arguments to survive the interpolation. The change in `lit.local.cfg` creates two substitutions for them, and uses those substitutions in `swift-build-cxx-plugin`.
1 parent ea62bcc commit b2e5d86

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

test/Macros/lit.local.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ else:
2525
0,
2626
(
2727
'%swift-build-cxx-plugin',
28-
'%clang -isysroot %host_sdk -I %swift_src_root/include -L %swift-lib-dir -l_swiftMockPlugin -Xlinker -rpath -Xlinker %swift-lib-dir'
28+
'%clang %c-flags %exe-linker-flags -isysroot %host_sdk -I %swift_src_root/include -L %swift-lib-dir -l_swiftMockPlugin -Xlinker -rpath -Xlinker %swift-lib-dir'
2929
)
3030
)
31+
config.substitutions.append(('%c-flags', config.c_flags))
32+
config.substitutions.append(('%exe-linker-flags', config.exe_linker_flags))

test/lit.site.cfg.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ config.swift_driver_test_options = "@SWIFT_DRIVER_TEST_OPTIONS@"
4444
config.swift_frontend_test_options = "@SWIFT_FRONTEND_TEST_OPTIONS@"
4545
config.swift_ide_test_test_options = "@SWIFT_IDE_TEST_TEST_OPTIONS@"
4646

47+
config.c_flags = r'''@CMAKE_C_FLAGS@'''
48+
config.exe_linker_flags = r'''@CMAKE_EXE_LINKER_FLAGS@'''
49+
4750
# --- Darwin ---
4851
config.darwin_xcrun_toolchain = "@SWIFT_DARWIN_XCRUN_TOOLCHAIN@"
4952

0 commit comments

Comments
 (0)