Skip to content

Commit e515db9

Browse files
committed
[cxx-interop][SwiftCompilerSources] Include Clang headers
This will allow using Swift headers that include Clang headers from SwiftCompilerSources. For example, some headers in `swift/Basic` include headers from `clang/Basic`. Currently adding those Swift headers to the modulemap causes a build error.
1 parent 486dc27 commit e515db9

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ function(add_swift_compiler_modules_library name)
160160
if (add_to_syntaxparse)
161161
set(syntaxparse_obj_files ${syntaxparse_obj_files} ${module_obj_file})
162162
endif()
163+
set(c_include_paths
164+
# LLVM modules and headers.
165+
"${LLVM_MAIN_INCLUDE_DIR}"
166+
# Generated LLVM headers.
167+
"${LLVM_INCLUDE_DIR}"
168+
# Clang modules and headers.
169+
${CLANG_INCLUDE_DIRS}
170+
# Bridging modules and headers.
171+
"${SWIFT_MAIN_INCLUDE_DIR}"
172+
# Generated C headers.
173+
"${CMAKE_CURRENT_BINARY_DIR}/../include")
174+
set(c_include_paths_args)
175+
foreach(c_include_path ${c_include_paths})
176+
list(APPEND c_include_paths_args "-Xcc" "-I" "-Xcc" "${c_include_path}")
177+
endforeach()
163178

164179
# Compile the module into an object file
165180
add_custom_command_target(dep_target OUTPUT ${module_obj_file}
@@ -173,14 +188,7 @@ function(add_swift_compiler_modules_library name)
173188
"-emit-module-path" "${build_dir}/${module}.swiftmodule"
174189
"-parse-as-library" ${sources}
175190
"-wmo" ${swift_compile_options}
176-
# LLVM modules and headers.
177-
"-Xcc" "-I" "-Xcc" "${LLVM_MAIN_INCLUDE_DIR}"
178-
# Generated LLVM headers.
179-
"-Xcc" "-I" "-Xcc" "${LLVM_INCLUDE_DIR}"
180-
# Bridging modules and headers.
181-
"-Xcc" "-I" "-Xcc" "${SWIFT_SOURCE_DIR}/include"
182-
# Generated C headers.
183-
"-Xcc" "-I" "-Xcc" "${CMAKE_CURRENT_BINARY_DIR}/../include"
191+
${c_include_paths_args}
184192
# Generated swift modules.
185193
"-I" "${build_dir}"
186194
COMMENT "Building swift module ${module}")

SwiftCompilerSources/Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ private extension Target {
2222
"-Xcc", "-I", "-Xcc", "../include",
2323
// LLVM modules and headers
2424
"-Xcc", "-I", "-Xcc", "../../llvm-project/llvm/include",
25+
// Clang modules and headers
26+
"-Xcc", "-I", "-Xcc", "../../llvm-project/clang/include",
2527
"-cross-module-optimization"
2628
]),
2729
]

0 commit comments

Comments
 (0)