Skip to content

Commit b6107b4

Browse files
authored
Merge pull request #38417 from artemcm/NoMorePCMArgTarget
[Dependency Scanning] Do not include `-target` in `extraPCMArgs` when scanning an interface
2 parents d73d8a6 + d6f7a01 commit b6107b4

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ void ClangImporter::recordModuleDependencies(
232232
while(It != allArgs.end()) {
233233
StringRef arg = *It;
234234
// Remove the -target arguments because we should use the target triple
235+
// specified with `-clang-target` on the scanner invocation, or
235236
// from the depending Swift modules.
236237
if (arg == "-target") {
237238
It += 2;
@@ -254,6 +255,16 @@ void ClangImporter::recordModuleDependencies(
254255
swiftArgs.push_back(clangArg);
255256
}
256257

258+
// If the scanner is invoked with '-clang-target', ensure this is the target
259+
// used to build this PCM.
260+
if (Impl.SwiftContext.LangOpts.ClangTarget.hasValue()) {
261+
llvm::Triple triple = Impl.SwiftContext.LangOpts.ClangTarget.getValue();
262+
swiftArgs.push_back("-Xcc");
263+
swiftArgs.push_back("-target");
264+
swiftArgs.push_back("-Xcc");
265+
swiftArgs.push_back(triple.str());
266+
}
267+
257268
// Swift frontend action: -emit-pcm
258269
swiftArgs.push_back("-emit-pcm");
259270
swiftArgs.push_back("-module-name");

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,11 +1049,16 @@ identifyMainModuleDependencies(CompilerInstance &instance) {
10491049
instance.getASTContext()
10501050
.LangOpts.EffectiveLanguageVersion.asAPINotesVersionString())
10511051
.str();
1052+
10521053
// Compute the dependencies of the main module.
1053-
auto mainDependencies = ModuleDependencies::forMainSwiftModule(
1054-
{// ExtraPCMArgs
1055-
"-Xcc", "-target", "-Xcc",
1056-
instance.getASTContext().LangOpts.Target.str(), "-Xcc", apinotesVer});
1054+
std::vector<StringRef> ExtraPCMArgs = {
1055+
"-Xcc", apinotesVer
1056+
};
1057+
if (!instance.getASTContext().LangOpts.ClangTarget.hasValue())
1058+
ExtraPCMArgs.insert(ExtraPCMArgs.begin(),
1059+
{"-Xcc", "-target", "-Xcc",
1060+
instance.getASTContext().LangOpts.Target.str()});
1061+
auto mainDependencies = ModuleDependencies::forMainSwiftModule(ExtraPCMArgs);
10571062

10581063
// Compute Implicit dependencies of the main module
10591064
{

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,15 +1647,20 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
16471647
}
16481648
info.BuildArguments = BuildArgs;
16491649
info.Hash = CacheHash;
1650-
auto target = *(std::find(BuildArgs.rbegin(), BuildArgs.rend(), "-target") - 1);
1650+
auto target = *(std::find(BuildArgs.rbegin(), BuildArgs.rend(), "-target") - 1);
16511651
auto langVersion = *(std::find(BuildArgs.rbegin(), BuildArgs.rend(),
16521652
"-swift-version") - 1);
1653-
std::array<StringRef, 6> ExtraPCMArgs = {
1654-
// PCMs should use the target triple the interface will be using to build
1655-
"-Xcc", "-target", "-Xcc", target,
1653+
1654+
std::vector<StringRef> ExtraPCMArgs = {
16561655
// PCMs should use the effective Swift language version for apinotes.
1657-
"-Xcc", ArgSaver.save((llvm::Twine("-fapinotes-swift-version=") + langVersion).str())
1656+
"-Xcc",
1657+
ArgSaver.save((llvm::Twine("-fapinotes-swift-version=") + langVersion).str())
16581658
};
1659+
if (!subInvocation.getLangOptions().ClangTarget.hasValue()) {
1660+
ExtraPCMArgs.insert(ExtraPCMArgs.begin(), {"-Xcc", "-target",
1661+
"-Xcc", target});
1662+
}
1663+
16591664
info.ExtraPCMArgs = ExtraPCMArgs;
16601665
// Run the action under the sub compiler instance.
16611666
return action(info);

test/ScanDependencies/module_deps.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: %empty-directory(%t)
22
// RUN: mkdir -p %t/clang-module-cache
3-
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4
43

4+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -emit-dependencies -emit-dependencies-path %t/deps.d -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4
55
// Check the contents of the JSON output
6-
// RUN: %FileCheck %s < %t/deps.json
6+
// RUN: %FileCheck -check-prefix CHECK_NO_CLANG_TARGET %s < %t/deps.json
77

88
// Check the contents of the JSON output
99
// RUN: %FileCheck %s -check-prefix CHECK-NO-SEARCH-PATHS < %t/deps.json
@@ -22,7 +22,12 @@
2222

2323
// Ensure that round-trip serialization does not affect result
2424
// RUN: %target-swift-frontend -scan-dependencies -test-dependency-scan-cache-serialization -module-cache-path %t/clang-module-cache %s -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4
25-
// RUN: %FileCheck %s < %t/deps.json
25+
// RUN: %FileCheck -check-prefix CHECK_NO_CLANG_TARGET %s < %t/deps.json
26+
27+
// Ensure that scanning with `-clang-target` makes sure that Swift modules' respecitve PCM-dependency-build-argument sets do not contain target triples.
28+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -o %t/deps_clang_target.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -import-objc-header %S/Inputs/CHeaders/Bridging.h -swift-version 4 -clang-target %target-cpu-apple-macosx10.14
29+
// Check the contents of the JSON output
30+
// RUN: %FileCheck -check-prefix CHECK_CLANG_TARGET %s < %t/deps_clang_target.json
2631

2732
// REQUIRES: executable_test
2833
// REQUIRES: objc_interop
@@ -178,10 +183,13 @@ import SubE
178183
// CHECK: "-swift-version"
179184
// CHECK: "5"
180185
// CHECK: ],
181-
// CHECK" "extraPcmArgs": [
182-
// CHECK" "-target",
183-
// CHECK" "-fapinotes-swift-version=5"
184-
// CHECK" ]
186+
// CHECK_NO_CLANG_TARGET: "extraPcmArgs": [
187+
// CHECK_NO_CLANG_TARGET-NEXT: "-Xcc",
188+
// CHECK_NO_CLANG_TARGET-NEXT: "-target",
189+
// CHECK_CLANG_TARGET: "extraPcmArgs": [
190+
// CHECK_CLANG_TARGET-NEXT: "-Xcc",
191+
// CHECK_CLANG_TARGET-NEXT: "-fapinotes-swift-version={{.*}}"
192+
// CHECK_CLANG_TARGET-NEXT: ]
185193

186194
/// --------Swift module Swift
187195
// CHECK-LABEL: "modulePath": "Swift.swiftmodule",

0 commit comments

Comments
 (0)