Skip to content
Merged
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 include/swift/Serialization/ScanningLoaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ namespace swift {
/// Result of looking up a Swift module on the current filesystem
/// search paths.
struct SwiftModuleScannerQueryResult {
// Checked for by the scanner as a special case
// for downgrading imcompatible-candidate-only lookup result
// to a warning.
static constexpr const char *BUILT_FOR_INCOMPATIBLE_TARGET =
"built for incompatible target";
struct IncompatibleCandidate {
std::string path;
std::string incompatibilityReason;
Expand Down
13 changes: 13 additions & 0 deletions lib/DependencyScan/ModuleDependencyScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,19 @@ void ModuleDependencyIssueReporter::diagnoseFailureOnOnlyIncompatibleCandidates(
if (candidates.empty())
return;

// FIXME: There are known cases where clients are relying on
// loading the underlying Clang module in the presence of a Swift
// module which is lacking the required target-specific variant,
// such as MacCatalyst. Eventually, we should pursue making this
// an error as well.
if (llvm::all_of(candidates, [](auto &incompatibleCandidate) {
return incompatibleCandidate.incompatibilityReason ==
SwiftModuleScannerQueryResult::BUILT_FOR_INCOMPATIBLE_TARGET;
})) {
warnOnIncompatibleCandidates(moduleImport.importIdentifier, candidates);
return;
}

diagnoseModuleNotFoundFailure(moduleImport, cache, dependencyOf,
/* resolvingSerializedSearchPath */ std::nullopt,
candidates);
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/ScanningLoaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool SwiftModuleScanner::handlePossibleTargetMismatch(

for (const auto &modulePath : foundIncompatibleArchModules)
incompatibleCandidates.push_back({modulePath,
"invalid architecture"});
SwiftModuleScannerQueryResult::BUILT_FOR_INCOMPATIBLE_TARGET});

return false;
}
Expand Down
25 changes: 25 additions & 0 deletions test/ScanDependencies/incompatible-arch-underlying-clang.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/deps)
// RUN: %empty-directory(%t/module-cache)
// RUN: %empty-directory(%t/inputs/Foo.swiftmodule)
// RUN: touch %t/inputs/Foo.swiftmodule/i387.swiftmodule
// RUN: touch %t/inputs/Foo.swiftmodule/ppc65.swiftmodule
// RUN: split-file %s %t

// 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

// CHECK-DAG: warning: module file '{{.*}}Foo.swiftmodule{{/|\\}}ppc65.swiftmodule' is incompatible with this Swift compiler: built for incompatible target
// CHECK-DAG: warning: module file '{{.*}}Foo.swiftmodule{{/|\\}}i387.swiftmodule' is incompatible with this Swift compiler: built for incompatible target
// CHECK-NOT: error

//--- deps/foo.h
void foo(void);

//--- deps/module.modulemap
module Foo {
header "foo.h"
export *
}

//--- client.swift
import Foo
7 changes: 4 additions & 3 deletions test/ScanDependencies/incompatible-arch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

// 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

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

import Foo