Skip to content

Commit b3c60b5

Browse files
committed
Propagate vfs overlays and sdk to subinvocations
This fixes explicit module builds for a hello world program on Windows as well as the ucrt import build failure as in the included test.
1 parent 71dfdcf commit b3c60b5

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,11 @@ ClangImporter::create(ASTContext &ctx,
14111411
importer->Impl.getBufferImporterForDiagnostics(),
14121412
importer->Impl.platformAvailability));
14131413

1414+
// Pass along the VFS overlays
1415+
for (auto &File : ctx.SearchPathOpts.VFSOverlayFiles) {
1416+
importer->Impl.Invocation->getHeaderSearchOpts().VFSOverlayFiles.push_back(File);
1417+
}
1418+
14141419
// Create a compiler instance.
14151420
{
14161421
// The Clang modules produced by ClangImporter are always embedded in an

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ static std::vector<std::string> getClangDepScanningInvocationArguments(
112112
commandLineArgs.push_back("-Xclang");
113113
commandLineArgs.push_back("-finclude-tree-preserve-pch-path");
114114

115+
// Handle VFSOverlay. If include tree is used, there is no need for overlay.
116+
if (!ctx.ClangImporterOpts.UseClangIncludeTree) {
117+
for (auto &overlay : ctx.SearchPathOpts.VFSOverlayFiles) {
118+
commandLineArgs.push_back("-vfsoverlay");
119+
commandLineArgs.push_back(overlay);
120+
}
121+
}
122+
115123
return commandLineArgs;
116124
}
117125

@@ -185,6 +193,13 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
185193
swiftArgs.push_back("-vfsoverlay");
186194
swiftArgs.push_back(remapPath(overlay));
187195
}
196+
197+
// Pass along the SDK path
198+
StringRef SDKPath = ctx.SearchPathOpts.getSDKPath();
199+
if (!SDKPath.empty()) {
200+
swiftArgs.push_back("-sdk");
201+
swiftArgs.push_back(SDKPath.str());
202+
}
188203
}
189204

190205
// Add args reported by the scanner.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-run-simple-swift | %FileCheck %s
2+
3+
// REQUIRES: executable_test
4+
5+
print("Hello, Explicit Module Build!")
6+
7+
// CHECK: Hello, Explicit Module Build!

test/ScanDependencies/win-crt.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -scan-dependencies -Xcc -v %s -o - | %validate-json | %FileCheck %s
3+
4+
// We want to explicitly import WinSDK's CRT.
5+
// REQUIRES: OS=windows-msvc
6+
7+
import CRT
8+
9+
// CHECK: "modulePath": "{{.*}}\\ucrt-{{.*}}.pcm",
10+
// CHECK-NEXT: "sourceFiles": [
11+
// CHECK-NEXT: "{{.*}}\\ucrt\\module.modulemap"

0 commit comments

Comments
 (0)