Skip to content

Commit 29c7216

Browse files
committed
DependenciesScanner: include search path options in PCM building commands
Unlike Swift modules, building Clang PCMs requires search path options like -F and -I to look for transitive header includes because in module maps, we can only find top-level headers. rdar://67589328
1 parent 59fe82a commit 29c7216

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@ void ClangImporter::recordModuleDependencies(
254254
swiftArgs.push_back("-module-name");
255255
swiftArgs.push_back(clangModuleDep.ModuleName);
256256

257+
// Pass down search paths to the -emit-module action.
258+
// Unlike building Swift modules, we need to include all search paths to
259+
// the clang invocation to build PCMs because transitive headers can only
260+
// be found via search paths. Passing these headers as explicit inputs can
261+
// be quite challenging.
262+
for (auto &path: Impl.SwiftContext.SearchPathOpts.ImportSearchPaths) {
263+
swiftArgs.push_back("-I");
264+
swiftArgs.push_back(path);
265+
}
266+
for (auto &path: Impl.SwiftContext.SearchPathOpts.FrameworkSearchPaths) {
267+
swiftArgs.push_back(path.IsSystem ? "-Fsystem": "-F");
268+
swiftArgs.push_back(path.Path);
269+
}
270+
257271
// Swift frontend option for input file path (Foo.modulemap).
258272
swiftArgs.push_back(clangModuleDep.ClangModuleMapFile);
259273
// Module-level dependencies.

test/ScanDependencies/batch_module_scan.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
// CHECK-PCM-NEXT: },
2929
// CHECK-PCM-NEXT: {
3030
// CHECK-PCM-NEXT: "modulePath": "F.pcm",
31+
// CHECK-PCM: "-I"
3132

3233
// CHECK-SWIFT: {
3334
// CHECK-SWIFT-NEXT: "mainModuleName": "F",

test/ScanDependencies/module_deps.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ import SubE
195195
/// --------Clang module SwiftShims
196196
// CHECK-LABEL: "modulePath": "SwiftShims.pcm",
197197

198-
// CHECK-NO-SEARCH-PATHS-NOT: "-I"
199198
// CHECK-NO-SEARCH-PATHS-NOT: "-sdk"
200-
// CHECK-NO-SEARCH-PATHS-NOT: "-F"
201199
// CHECK-NO-SEARCH-PATHS-NOT: "-prebuilt-module-cache-path"
202200

203201
// Check make-style dependencies

0 commit comments

Comments
 (0)