Skip to content

Commit d9c00d8

Browse files
authored
Merge pull request #72668 from artemcm/DepScanBinaryModuleHeaderDepModuleDeps
[Explicit Module Builds] Only specify '-fmodule-map-file' for bridging header Clang module dependencies
2 parents 706f065 + f3816e0 commit d9c00d8

File tree

10 files changed

+85
-10
lines changed

10 files changed

+85
-10
lines changed

include/swift-c/DependencyScan/DependencyScan.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
2626
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
2727
#define SWIFTSCAN_VERSION_MAJOR 0
28-
#define SWIFTSCAN_VERSION_MINOR 7
28+
#define SWIFTSCAN_VERSION_MINOR 8
2929

3030
SWIFTSCAN_BEGIN_DECLS
3131

@@ -206,6 +206,10 @@ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
206206
swiftscan_swift_binary_detail_get_header_dependency(
207207
swiftscan_module_details_t details);
208208

209+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
210+
swiftscan_swift_binary_detail_get_header_dependency_module_dependencies(
211+
swiftscan_module_details_t details);
212+
209213
SWIFTSCAN_PUBLIC bool
210214
swiftscan_swift_binary_detail_get_is_framework(
211215
swiftscan_module_details_t details);

include/swift/AST/SearchPathOptions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ class SearchPathOptions {
476476
std::vector<std::string> CandidateCompiledModules;
477477

478478
/// A map of explicit Swift module information.
479-
std::string ExplicitSwiftModuleMap;
479+
std::string ExplicitSwiftModuleMapPath;
480480

481481
/// Module inputs specified with -swift-module-input,
482482
/// <ModuleName, Path to .swiftmodule file>

include/swift/Frontend/ModuleInterfaceLoader.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,11 @@ struct ExplicitClangModuleInputInfo {
269269
ExplicitClangModuleInputInfo(
270270
std::string moduleMapPath, std::string modulePath,
271271
bool isFramework = false, bool isSystem = false,
272+
bool isBridgingHeaderDependency = true,
272273
std::optional<std::string> moduleCacheKey = std::nullopt)
273274
: moduleMapPath(moduleMapPath), modulePath(modulePath),
274275
isFramework(isFramework), isSystem(isSystem),
276+
isBridgingHeaderDependency(isBridgingHeaderDependency),
275277
moduleCacheKey(moduleCacheKey) {}
276278
// Path of the Clang module map file.
277279
std::string moduleMapPath;
@@ -281,6 +283,8 @@ struct ExplicitClangModuleInputInfo {
281283
bool isFramework = false;
282284
// A flag that indicates whether this module is a system module
283285
bool isSystem = false;
286+
// A flag that indicates whether this is a module dependency of a textual header input
287+
bool isBridgingHeaderDependency = true;
284288
// The cache key for clang module.
285289
std::optional<std::string> moduleCacheKey;
286290
};
@@ -367,7 +371,12 @@ class ExplicitModuleMapParser {
367371
swiftModuleSourceInfoPath, swiftModuleCacheKey, clangModuleCacheKey;
368372
std::optional<std::vector<std::string>> headerDependencyPaths;
369373
std::string clangModuleMapPath = "", clangModulePath = "";
370-
bool isFramework = false, isSystem = false;
374+
bool isFramework = false, isSystem = false,
375+
// The default value is 'true' in case the build system does not yet
376+
// support emitting this field, in which case we must be conservative and
377+
// ensure all dependencies get '-fmodule-map-file', instead of strictly
378+
// module dependencies of textual header inputs.
379+
isBridgingHeaderDependency = true;
371380
for (auto &entry : *mapNode) {
372381
auto key = getScalaNodeText(entry.getKey());
373382
if (key == "prebuiltHeaderDependencyPaths") {
@@ -394,6 +403,8 @@ class ExplicitModuleMapParser {
394403
swiftModuleCacheKey = val.str();
395404
} else if (key == "clangModuleCacheKey") {
396405
clangModuleCacheKey = val.str();
406+
} else if (key == "isBridgingHeaderDependency") {
407+
isBridgingHeaderDependency = parseBoolValue(val);
397408
} else {
398409
// Being forgiving for future fields.
399410
continue;
@@ -423,6 +434,7 @@ class ExplicitModuleMapParser {
423434
clangModulePath,
424435
isFramework,
425436
isSystem,
437+
isBridgingHeaderDependency,
426438
clangModuleCacheKey);
427439
clangModuleMap.try_emplace(moduleName, std::move(entry));
428440
}

lib/Frontend/CompilerInvocation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts,
19821982
Args.hasArg(OPT_disable_modules_validate_system_headers);
19831983

19841984
if (const Arg *A = Args.getLastArg(OPT_explicit_swift_module_map))
1985-
Opts.ExplicitSwiftModuleMap = A->getValue();
1985+
Opts.ExplicitSwiftModuleMapPath = A->getValue();
19861986
for (auto A : Args.getAllArgValues(options::OPT_swift_module_file)) {
19871987
if (validateSwiftModuleFileArgumentAndAdd(A, Diags,
19881988
Opts.ExplicitSwiftModuleInputs))

lib/Frontend/Frontend.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -745,18 +745,18 @@ bool CompilerInstance::setUpModuleLoaders() {
745745
bool ExplicitModuleBuild =
746746
Invocation.getFrontendOptions().DisableImplicitModules;
747747
if (ExplicitModuleBuild ||
748-
!Invocation.getSearchPathOptions().ExplicitSwiftModuleMap.empty() ||
748+
!Invocation.getSearchPathOptions().ExplicitSwiftModuleMapPath.empty() ||
749749
!Invocation.getSearchPathOptions().ExplicitSwiftModuleInputs.empty()) {
750750
if (Invocation.getCASOptions().EnableCaching)
751751
ESML = ExplicitCASModuleLoader::create(
752752
*Context, getObjectStore(), getActionCache(), getDependencyTracker(),
753-
MLM, Invocation.getSearchPathOptions().ExplicitSwiftModuleMap,
753+
MLM, Invocation.getSearchPathOptions().ExplicitSwiftModuleMapPath,
754754
Invocation.getSearchPathOptions().ExplicitSwiftModuleInputs,
755755
IgnoreSourceInfoFile);
756756
else
757757
ESML = ExplicitSwiftModuleLoader::create(
758758
*Context, getDependencyTracker(), MLM,
759-
Invocation.getSearchPathOptions().ExplicitSwiftModuleMap,
759+
Invocation.getSearchPathOptions().ExplicitSwiftModuleMapPath,
760760
Invocation.getSearchPathOptions().ExplicitSwiftModuleInputs,
761761
IgnoreSourceInfoFile);
762762
}

lib/Frontend/ModuleInterfaceLoader.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1847,8 +1847,8 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
18471847
}
18481848

18491849
// Pass down -explicit-swift-module-map-file
1850-
StringRef explicitSwiftModuleMap = searchPathOpts.ExplicitSwiftModuleMap;
1851-
genericSubInvocation.getSearchPathOptions().ExplicitSwiftModuleMap =
1850+
StringRef explicitSwiftModuleMap = searchPathOpts.ExplicitSwiftModuleMapPath;
1851+
genericSubInvocation.getSearchPathOptions().ExplicitSwiftModuleMapPath =
18521852
explicitSwiftModuleMap.str();
18531853

18541854
// Pass down VFSOverlay flags (do not need to inherit the options because
@@ -2198,6 +2198,7 @@ struct ExplicitSwiftModuleLoader::Implementation {
21982198
for (auto &entry : ExplicitClangModuleMap) {
21992199
const auto &moduleMapPath = entry.getValue().moduleMapPath;
22002200
if (!moduleMapPath.empty() &&
2201+
entry.getValue().isBridgingHeaderDependency &&
22012202
moduleMapsSeen.find(moduleMapPath) == moduleMapsSeen.end()) {
22022203
moduleMapsSeen.insert(moduleMapPath);
22032204
extraClangArgs.push_back(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// REQUIRES: objc_interop
2+
// RUN: %empty-directory(%t)
3+
// RUN: %empty-directory(%t/TestInputs)
4+
// RUN: split-file %s %t
5+
6+
// - Fixup the input module file map
7+
// RUN: sed -e "s|INPUTSDIR|%/t/TestInputs|g" %t/map.json.template > %t/map.json.template1
8+
// RUN: sed -e "s|STDLIBMOD|%/stdlib_module|g" %t/map.json.template1 > %t/map.json.template2
9+
// RUN: sed -e "s|ONONEMOD|%/ononesupport_module|g" %t/map.json.template2 > %t/map.json.template3
10+
// RUN: sed -e "s|CHEADERSDIR|%/S/Inputs/CHeaders|g" %t/map.json.template3 > %t/map.json.template4
11+
// RUN: sed -e "s|SWIFTLIBDIR|%swift-lib-dir|g" %t/map.json.template4 > %t/map.json
12+
13+
// - Pre-compile explicit module dependency inputs
14+
// RUN: %target-swift-emit-pcm -module-name A -o %t/TestInputs/A.pcm %S/Inputs/CHeaders/module.modulemap
15+
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift-lib-dir/swift/shims/module.modulemap -o %t/TestInputs/SwiftShims.pcm
16+
17+
// RUN: %target-swift-frontend -c -disable-implicit-swift-modules -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -explicit-swift-module-map-file %t/map.json -primary-file %t/bridging_header_modulemap_only.swift -o %t/bridging_header_modulemap_only.o -dump-clang-diagnostics 2>&1 | %FileCheck %s --check-prefix=CHECK-CLANG-COMMAND
18+
19+
//--- map.json.template
20+
[
21+
{
22+
"moduleName": "Swift",
23+
"modulePath": "STDLIBMOD",
24+
"isFramework": false
25+
},
26+
{
27+
"moduleName": "SwiftOnoneSupport",
28+
"modulePath": "ONONEMOD",
29+
"isFramework": false
30+
},
31+
{
32+
"moduleName": "SwiftShims",
33+
"isFramework": false,
34+
"isBridgingHeaderDependency": false,
35+
"clangModuleMapPath": "SWIFTLIBDIR/swift/shims/module.modulemap",
36+
"clangModulePath": "INPUTSDIR/SwiftShims.pcm"
37+
},
38+
{
39+
"moduleName": "A",
40+
"isFramework": false,
41+
"isBridgingHeaderDependency": true,
42+
"clangModulePath": "INPUTSDIR/A.pcm",
43+
"clangModuleMapPath": "CHEADERSDIR/module.modulemap"
44+
}
45+
]
46+
47+
//--- bridging_header_modulemap_only.swift
48+
import A
49+
50+
// CHECK-CLANG-COMMAND: -fmodule-map-file={{.*}}{{/|\\}}CHeaders{{/|\\}}module.modulemap
51+
// CHECK-CLANG-COMMAND-NOT: -fmodule-map-file={{.*}}{{/|\\}}swift{{/|\\}}shims{{/|\\}}module.modulemap

tools/libSwiftScan/libSwiftScan.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ swiftscan_swift_binary_detail_get_header_dependency(
365365
return details->swift_binary_details.header_dependency;
366366
}
367367

368+
swiftscan_string_set_t *
369+
swiftscan_swift_binary_detail_get_header_dependency_module_dependencies(
370+
swiftscan_module_details_t details) {
371+
return details->swift_binary_details.header_dependencies_module_dependnecies;
372+
}
373+
368374
bool swiftscan_swift_binary_detail_get_is_framework(
369375
swiftscan_module_details_t details) {
370376
return details->swift_binary_details.is_framework;

tools/libSwiftScan/libSwiftScan.exports

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ swiftscan_swift_binary_detail_get_module_doc_path
2525
swiftscan_swift_binary_detail_get_module_source_info_path
2626
swiftscan_swift_binary_detail_get_swift_overlay_dependencies
2727
swiftscan_swift_binary_detail_get_header_dependency
28+
swiftscan_swift_binary_detail_get_header_dependency_module_dependencies
2829
swiftscan_swift_binary_detail_get_is_framework
2930
swiftscan_swift_binary_detail_get_module_cache_key
3031
swiftscan_swift_placeholder_detail_get_compiled_module_path

tools/swift-ide-test/swift-ide-test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4520,7 +4520,7 @@ int main(int argc, char *argv[]) {
45204520
InitInvok.getLangOptions().addCustomConditionalCompilationFlag(ConfigName);
45214521

45224522
if (!options::ExplicitSwiftModuleMap.empty()) {
4523-
InitInvok.getSearchPathOptions().ExplicitSwiftModuleMap =
4523+
InitInvok.getSearchPathOptions().ExplicitSwiftModuleMapPath =
45244524
options::ExplicitSwiftModuleMap;
45254525
InitInvok.getFrontendOptions().DisableImplicitModules = true;
45264526
}

0 commit comments

Comments
 (0)