Skip to content

Commit bb5e20d

Browse files
committed
[Dependency Scanning] Interface-scanning sub-invocations should not attempt to import CxxShims
Swift interfaces currently aren't meant to expose C++ in their API so we should not also bring in this C++-related module dependency which is not found when the ClangImporter is not configured for C++.
1 parent 9607e9d commit bb5e20d

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@ class FrontendOptions {
336336
/// for testing purposes only.
337337
bool DisableBuildingInterface = false;
338338

339+
/// Is this frontend configuration of an interface dependency scan sub-invocation
340+
bool DependencyScanningSubInvocation = false;
341+
339342
/// When performing a dependency scanning action, only identify and output all imports
340343
/// of the main Swift module's source files.
341344
bool ImportPrescan = false;

lib/Frontend/Frontend.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,9 +1169,14 @@ bool CompilerInstance::canImportCxxShim() const {
11691169
ImportPath::Module::Builder builder(
11701170
getASTContext().getIdentifier(CXX_SHIM_NAME));
11711171
auto modulePath = builder.get();
1172+
// Currently, Swift interfaces are not to expose their
1173+
// C++ dependencies. Which means that when scanning them we should not
1174+
// bring in such dependencies, including CxxShims.
11721175
return getASTContext().testImportModule(modulePath) &&
11731176
!Invocation.getFrontendOptions()
1174-
.InputsAndOutputs.hasModuleInterfaceOutputPath();
1177+
.InputsAndOutputs.hasModuleInterfaceOutputPath() &&
1178+
!Invocation.getFrontendOptions()
1179+
.DependencyScanningSubInvocation;
11751180
}
11761181

11771182
bool CompilerInstance::supportCaching() const {

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,8 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
18031803
// in the Swift compile commands, when different.
18041804
inheritedParentContextClangArgs =
18051805
clangImporterOpts.getReducedExtraArgsForSwiftModuleDependency();
1806+
genericSubInvocation.getFrontendOptions()
1807+
.DependencyScanningSubInvocation = true;
18061808
} else if (LoaderOpts.strictImplicitModuleContext) {
18071809
// If the compiler has been asked to be strict with ensuring downstream
18081810
// dependencies get the parent invocation's context, inherit the extra Clang
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// REQUIRES: OS=macosx
2+
// RUN: %empty-directory(%t)
3+
// RUN: %empty-directory(%t/deps)
4+
// RUN: split-file %s %t
5+
// RUN: mv %t/Foo.swiftinterface %t/deps/
6+
7+
// RUN: %target-swift-frontend -scan-dependencies -o %t/deps.json %t/a.swift -I %t/deps -verify
8+
9+
//--- Foo.swiftinterface
10+
// swift-interface-format-version: 1.0
11+
// swift-module-flags: -module-name Foo -cxx-interoperability-mode=default
12+
public struct S1 {}
13+
14+
//--- a.swift
15+
import Foo
16+
17+
// RUN: cat %t/deps.json | %FileCheck %s
18+
// CHECK-NOT: "CxxShim"

0 commit comments

Comments
 (0)