Skip to content

Commit 4a2b178

Browse files
authored
Merge pull request #72599 from artemcm/NoModuleMapsOnSwiftDepsExplicit
[Dependency Scanning] By-default do not specify '-fmodule-map-file' inputs on Swift interface dependency compilation jobs
2 parents d9c00d8 + e489a1e commit 4a2b178

File tree

3 files changed

+131
-9
lines changed

3 files changed

+131
-9
lines changed

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,20 @@ static llvm::Error resolveExplicitModuleInputs(
264264
: binaryDepDetails->moduleCacheKey;
265265
commandLine.push_back("-swift-module-file=" + depModuleID.ModuleName + "=" +
266266
path);
267+
// If this binary module was built with a header, the header's module
268+
// dependencies must also specify a .modulemap to the compilation, in
269+
// order to resolve the header's own header include directives.
270+
for (const auto &bridgingHeaderDepName :
271+
binaryDepDetails->headerModuleDependencies) {
272+
auto optionalBridgingHeaderDepModuleInfo = cache.findDependency(
273+
{bridgingHeaderDepName, ModuleDependencyKind::Clang});
274+
assert(optionalDepInfo.has_value());
275+
const auto bridgingHeaderDepModuleDetails =
276+
optionalBridgingHeaderDepModuleInfo.value()->getAsClangModule();
277+
commandLine.push_back(
278+
"-fmodule-map-file=" +
279+
remapPath(bridgingHeaderDepModuleDetails->moduleMapFile));
280+
}
267281
} break;
268282
case swift::ModuleDependencyKind::SwiftPlaceholder: {
269283
auto placeholderDetails = depInfo->getAsPlaceholderDependencyModule();
@@ -278,13 +292,6 @@ static llvm::Error resolveExplicitModuleInputs(
278292
commandLine.push_back("-Xcc");
279293
commandLine.push_back("-fmodule-file=" + depModuleID.ModuleName + "=" +
280294
clangDepDetails->mappedPCMPath);
281-
if (!instance.getInvocation()
282-
.getClangImporterOptions()
283-
.UseClangIncludeTree) {
284-
commandLine.push_back("-Xcc");
285-
commandLine.push_back("-fmodule-map-file=" +
286-
remapPath(clangDepDetails->moduleMapFile));
287-
}
288295
}
289296
if (!clangDepDetails->moduleCacheKey.empty()) {
290297
commandLine.push_back("-Xcc");
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// REQUIRES: objc_interop
2+
// RUN: %empty-directory(%t)
3+
// RUN: %empty-directory(%t/FooInputs)
4+
// RUN: %empty-directory(%t/BridgingHeaderDir)
5+
// RUN: %empty-directory(%t/TestCHeaders)
6+
// RUN: %empty-directory(%t/TestSwiftInterfaces)
7+
// RUN: %empty-directory(%t/FooModuleDir)
8+
// RUN: split-file %s %t
9+
10+
// - Fixup the input module file map
11+
// RUN: sed -e "s|INPUTSDIR|%/t/FooInputs|g" %t/map.json.template > %t/map.json.template1
12+
// RUN: sed -e "s|STDLIBMOD|%/stdlib_module|g" %t/map.json.template1 > %t/map.json.template2
13+
// RUN: sed -e "s|ONONEMOD|%/ononesupport_module|g" %t/map.json.template2 > %t/map.json.template3
14+
// RUN: sed -e "s|SWIFTLIBDIR|%swift-lib-dir|g" %t/map.json.template3 > %t/map.json
15+
16+
// - Set up explicit dependencies for Foo
17+
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift-lib-dir/swift/shims/module.modulemap -o %t/FooInputs/SwiftShims.pcm
18+
// - Build Foo module dependency, explicitly, non-resiliently
19+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/FooModuleDir/Foo.swiftmodule %t/foo.swift -module-name Foo -import-objc-header %t/BridgingHeaderDir/foo.h -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -disable-implicit-swift-modules -explicit-swift-module-map-file %t/map.json -I %S/Inputs/CHeaders
20+
21+
// - Scan main module and ensure that the "FooClient" recipe includes the modulemap for Foo's briding header's module dependencies
22+
// but not other dependencies
23+
// RUN: %target-swift-frontend -scan-dependencies %t/bridging_header_dep_module_map.swift -I %t/FooModuleDir -I %t/TestSwiftInterfaces -I %t/TestCHeaders -I %S/Inputs/CHeaders -o %t/deps.json
24+
// RUN: %validate-json %t/deps.json | %FileCheck %s
25+
26+
// Given the following dependency graph:
27+
//
28+
// main
29+
// |
30+
// FooClient (.swiftinterface)
31+
// | \
32+
// Foo(.swiftmodule) Dart (.pcm)
33+
//
34+
// Given that 'Foo.swiftmodule' is built with a bridging header which imports 'X.h' ('X' clang module)
35+
// We expect that 'Foo' will have a dependency on module 'X', and the scanner will ensure that 'FooClient' is built
36+
// with the modulemap file for 'X' as an explicit input. 'Dart' Clang module however, must not result in an
37+
// explicitly-specified modulemap file because no headers of this module will be ingested into the Swift
38+
// compiler.
39+
40+
// Dependency of the main module
41+
// CHECK: "swift": "FooClient"
42+
43+
// Definition of 'FooClient' in the dependency graph
44+
// CHECK: "swift": "FooClient"
45+
// CHECK: "modulePath": "{{.*}}FooClient-{{.*}}.swiftmodule",
46+
// CHECK: "directDependencies": [
47+
// CHECK-DAG: "swiftPrebuiltExternal": "Foo"
48+
// CHECK-DAG: "swift": "SwiftOnoneSupport"
49+
// CHECK-DAG: "clang": "Dart"
50+
// CHECK: ],
51+
// CHECK: "commandLine": [
52+
// CHECK: "-fmodule-map-file={{.*}}{{/|\\}}CHeaders{{/|\\}}module.modulemap"
53+
// CHECK-NOT: "-fmodule-map-file={{.*}}{{/|\\}}TestCHeaders{{/|\\}}module.modulemap"
54+
// CHECK: ]
55+
56+
// Definition of 'Foo' in the dependency graph
57+
// CHECK: "swiftPrebuiltExternal": "Foo"
58+
// CHECK: "modulePath": "{{.*}}Foo.swiftmodule",
59+
// CHECK-NEXT: "directDependencies": [
60+
// CHECK-DAG: "swift": "Swift"
61+
// CHECK-DAG: "swift": "SwiftOnoneSupport"
62+
// CHECK-DAG: "clang": "X"
63+
// CHECK: ],
64+
// CHECK: "headerDependency": "{{.*}}{{/|\\}}BridgingHeaderDir{{/|\\}}foo.h"
65+
// CHECK: "headerModuleDependencies": [
66+
// CHECK-NEXT: "X"
67+
// CHECK-NEXT: ],
68+
// CHECK: "headerDependenciesSourceFiles": [
69+
// CHECK-NEXT: "{{.*}}{{/|\\}}BridgingHeaderDir{{/|\\}}foo.h"
70+
// CHECK-NEXT: ],
71+
72+
//--- foo.swift
73+
extension Profiler {
74+
public static let count: Int = 42
75+
}
76+
77+
//--- BridgingHeaderDir/foo.h
78+
#include "X.h"
79+
struct Profiler { void* ptr; };
80+
81+
//--- TestCHeaders/Dart.h
82+
struct Dart { void* ptr; };
83+
//--- TestCHeaders/module.modulemap
84+
module Dart {
85+
header "Dart.h"
86+
export *
87+
}
88+
89+
//--- TestSwiftInterfaces/FooClient.swiftinterface
90+
// swift-interface-format-version: 1.0
91+
// swift-module-flags: -module-name FooClient
92+
import Foo
93+
import Dart
94+
95+
//--- map.json.template
96+
[
97+
{
98+
"moduleName": "Swift",
99+
"modulePath": "STDLIBMOD",
100+
"isFramework": false
101+
},
102+
{
103+
"moduleName": "SwiftOnoneSupport",
104+
"modulePath": "ONONEMOD",
105+
"isFramework": false
106+
},
107+
{
108+
"moduleName": "SwiftShims",
109+
"isFramework": false,
110+
"clangModuleMapPath": "SWIFTLIBDIR/swift/shims/module.modulemap",
111+
"clangModulePath": "INPUTSDIR/SwiftShims.pcm"
112+
}]
113+
114+
//--- bridging_header_dep_module_map.swift
115+
import FooClient

test/ScanDependencies/explicit-swift-dependencies.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ import F
5151
// CHECK-NEXT: "{{.*}}{{/|\\}}F-{{.*}}.swiftmodule"
5252
// CHECK-DAG: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-{{.*}}.swiftmodule"
5353
// CHECK-DAG: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-{{.*}}.swiftmodule"
54-
// CHECK-DAG: "-fmodule-file=F={{.*}}{{/|\\}}F-{{.*}}.pcm",
55-
// CHECK-DAG: "-fmodule-file=SwiftShims={{.*}}{{/|\\}}SwiftShims-{{.*}}.pcm",
54+
// CHECK-DAG: "-fmodule-file=F={{.*}}{{/|\\}}F-{{.*}}.pcm"
55+
// CHECK-DAG: "-fmodule-file=SwiftShims={{.*}}{{/|\\}}SwiftShims-{{.*}}.pcm"

0 commit comments

Comments
 (0)