Skip to content

Commit 70341f4

Browse files
authored
Merge pull request #84942 from artemcm/DowngradeIncompatBinModDepToWarning
[Dependency Scanning] Warn, instead of fail, when a Swift dependency query only finds modules built for incompatible target
2 parents cc3951e + d699e2f commit 70341f4

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

include/swift/Serialization/ScanningLoaders.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ namespace swift {
2222
/// Result of looking up a Swift module on the current filesystem
2323
/// search paths.
2424
struct SwiftModuleScannerQueryResult {
25+
// Checked for by the scanner as a special case
26+
// for downgrading imcompatible-candidate-only lookup result
27+
// to a warning.
28+
static constexpr const char *BUILT_FOR_INCOMPATIBLE_TARGET =
29+
"built for incompatible target";
2530
struct IncompatibleCandidate {
2631
std::string path;
2732
std::string incompatibilityReason;

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,19 @@ void ModuleDependencyIssueReporter::diagnoseFailureOnOnlyIncompatibleCandidates(
21022102
if (candidates.empty())
21032103
return;
21042104

2105+
// FIXME: There are known cases where clients are relying on
2106+
// loading the underlying Clang module in the presence of a Swift
2107+
// module which is lacking the required target-specific variant,
2108+
// such as MacCatalyst. Eventually, we should pursue making this
2109+
// an error as well.
2110+
if (llvm::all_of(candidates, [](auto &incompatibleCandidate) {
2111+
return incompatibleCandidate.incompatibilityReason ==
2112+
SwiftModuleScannerQueryResult::BUILT_FOR_INCOMPATIBLE_TARGET;
2113+
})) {
2114+
warnOnIncompatibleCandidates(moduleImport.importIdentifier, candidates);
2115+
return;
2116+
}
2117+
21052118
diagnoseModuleNotFoundFailure(moduleImport, cache, dependencyOf,
21062119
/* resolvingSerializedSearchPath */ std::nullopt,
21072120
candidates);

lib/Serialization/ScanningLoaders.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ bool SwiftModuleScanner::handlePossibleTargetMismatch(
117117

118118
for (const auto &modulePath : foundIncompatibleArchModules)
119119
incompatibleCandidates.push_back({modulePath,
120-
"invalid architecture"});
120+
SwiftModuleScannerQueryResult::BUILT_FOR_INCOMPATIBLE_TARGET});
121121

122122
return false;
123123
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/deps)
3+
// RUN: %empty-directory(%t/module-cache)
4+
// RUN: %empty-directory(%t/inputs/Foo.swiftmodule)
5+
// RUN: touch %t/inputs/Foo.swiftmodule/i387.swiftmodule
6+
// RUN: touch %t/inputs/Foo.swiftmodule/ppc65.swiftmodule
7+
// RUN: split-file %s %t
8+
9+
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/module-cache %t/client.swift -o %t/deps.json -I %t/inputs -I %t/deps -diagnostic-style llvm -scanner-module-validation 2>&1 | %FileCheck %s
10+
11+
// CHECK-DAG: warning: module file '{{.*}}Foo.swiftmodule{{/|\\}}ppc65.swiftmodule' is incompatible with this Swift compiler: built for incompatible target
12+
// CHECK-DAG: warning: module file '{{.*}}Foo.swiftmodule{{/|\\}}i387.swiftmodule' is incompatible with this Swift compiler: built for incompatible target
13+
// CHECK-NOT: error
14+
15+
//--- deps/foo.h
16+
void foo(void);
17+
18+
//--- deps/module.modulemap
19+
module Foo {
20+
header "foo.h"
21+
export *
22+
}
23+
24+
//--- client.swift
25+
import Foo

test/ScanDependencies/incompatible-arch.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/module-cache %s -o %t/deps.json -I %t/inputs -diagnostic-style llvm -scanner-module-validation 2>&1 | %FileCheck %s
88

9-
// CHECK: error: unable to resolve Swift module dependency to a compatible module: 'Foo'
10-
// CHECK-DAG: note: found incompatible module '{{.*}}Foo.swiftmodule{{/|\\}}ppc65.swiftmodule': invalid architecture
11-
// CHECK-DAG: note: found incompatible module '{{.*}}Foo.swiftmodule{{/|\\}}i387.swiftmodule': invalid architecture
9+
// CHECK-DAG: warning: module file '{{.*}}Foo.swiftmodule{{/|\\}}ppc65.swiftmodule' is incompatible with this Swift compiler: built for incompatible target
10+
// CHECK-DAG: warning: module file '{{.*}}Foo.swiftmodule{{/|\\}}i387.swiftmodule' is incompatible with this Swift compiler: built for incompatible target
11+
// CHECK: error: unable to resolve module dependency: 'Foo'
12+
1213
import Foo

0 commit comments

Comments
 (0)