Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate vfs overlays and sdk to subinvocations #79926

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,11 @@ ClangImporter::create(ASTContext &ctx,
importer->Impl.getBufferImporterForDiagnostics(),
importer->Impl.platformAvailability, &importer->Impl));

// Pass along the VFS overlays
for (auto &File : ctx.SearchPathOpts.VFSOverlayFiles) {
importer->Impl.Invocation->getHeaderSearchOpts().VFSOverlayFiles.push_back(File);
}

// Create a compiler instance.
{
// The Clang modules produced by ClangImporter are always embedded in an
Expand Down
15 changes: 15 additions & 0 deletions lib/ClangImporter/ClangModuleDependencyScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ static std::vector<std::string> getClangDepScanningInvocationArguments(
commandLineArgs.push_back("-Xclang");
commandLineArgs.push_back("-finclude-tree-preserve-pch-path");

// Handle VFSOverlay. If include tree is used, there is no need for overlay.
if (!ctx.ClangImporterOpts.UseClangIncludeTree) {
for (auto &overlay : ctx.SearchPathOpts.VFSOverlayFiles) {
commandLineArgs.push_back("-vfsoverlay");
commandLineArgs.push_back(overlay);
}
}

return commandLineArgs;
}

Expand Down Expand Up @@ -185,6 +193,13 @@ ModuleDependencyVector ClangImporter::bridgeClangModuleDependencies(
swiftArgs.push_back("-vfsoverlay");
swiftArgs.push_back(remapPath(overlay));
}

// Pass along the SDK path
StringRef SDKPath = ctx.SearchPathOpts.getSDKPath();
if (!SDKPath.empty()) {
swiftArgs.push_back("-sdk");
swiftArgs.push_back(SDKPath.str());
}
}

// Add args reported by the scanner.
Expand Down
7 changes: 7 additions & 0 deletions test/ScanDependencies/hello-explicit-module-build.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-run-simple-swift | %FileCheck %s

// REQUIRES: executable_test

print("Hello, Explicit Module Build!")

// CHECK: Hello, Explicit Module Build!
11 changes: 11 additions & 0 deletions test/ScanDependencies/win-crt.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -scan-dependencies -Xcc -v %s -o - | %validate-json | %FileCheck %s

// We want to explicitly import WinSDK's CRT.
// REQUIRES: OS=windows-msvc

import CRT

// CHECK: "modulePath": "{{.*}}\\ucrt-{{.*}}.pcm",
// CHECK-NEXT: "sourceFiles": [
// CHECK-NEXT: "{{.*}}\\ucrt\\module.modulemap"