Skip to content

Commit e2ea6cb

Browse files
committed
[Explicit Module Builds] Add 'ClangImporter' setting for explicitly-built modules
This will mean that '-disable-implicit-swift-modules' also automatically implies two things: 1. Clang modules must also be explicit, and the importer's clang instance will get '-fno-implicit-modules' and '-fno-implicit-module-maps' 2. The importer's clang instance will no longer get a '-fmodules-cache-path=', since it is not needed in explicit builds
1 parent 1426980 commit e2ea6cb

9 files changed

+90
-5
lines changed

include/swift/Basic/LangOptions.h

+4
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,10 @@ namespace swift {
878878
/// and completely bypass the Clang driver.
879879
bool DirectClangCC1ModuleBuild = false;
880880

881+
/// Disable implicitly-built Clang modules because they are explicitly
882+
/// built and provided to the compiler invocation.
883+
bool DisableImplicitClangModules = false;
884+
881885
/// Return a hash code of any components from these options that should
882886
/// contribute to a Swift Bridging PCH hash.
883887
llvm::hash_code getPCHHashComponents() const {

include/swift/Frontend/FrontendOptions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ class FrontendOptions {
322322
/// By default, we include ImplicitObjCHeaderPath directly.
323323
llvm::Optional<std::string> BridgingHeaderDirForPrint;
324324

325-
/// Disable implicitly built Swift modules because they are explicitly
326-
/// built and given to the compiler invocation.
325+
/// Disable implicitly-built Swift modules because they are explicitly
326+
/// built and provided to the compiler invocation.
327327
bool DisableImplicitModules = false;
328328

329329
/// Disable building Swift modules from textual interfaces. This should be

lib/ClangImporter/ClangImporter.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,16 @@ importer::getNormalInvocationArguments(
669669
}
670670

671671
const std::string &moduleCachePath = importerOpts.ModuleCachePath;
672-
if (!moduleCachePath.empty()) {
672+
if (!moduleCachePath.empty() && !importerOpts.DisableImplicitClangModules) {
673673
invocationArgStrs.push_back("-fmodules-cache-path=");
674674
invocationArgStrs.back().append(moduleCachePath);
675675
}
676676

677+
if (importerOpts.DisableImplicitClangModules) {
678+
invocationArgStrs.push_back("-fno-implicit-modules");
679+
invocationArgStrs.push_back("-fno-implicit-module-maps");
680+
}
681+
677682
if (ctx.SearchPathOpts.DisableModulesValidateSystemDependencies) {
678683
invocationArgStrs.push_back("-fno-modules-validate-system-headers");
679684
} else {

lib/Frontend/CompilerInvocation.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,9 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
14601460
Opts.PCHDisableValidation |= Args.hasArg(OPT_pch_disable_validation);
14611461
}
14621462

1463+
if (FrontendOpts.DisableImplicitModules)
1464+
Opts.DisableImplicitClangModules = true;
1465+
14631466
Opts.ValidateModulesOnce |= Args.hasArg(OPT_validate_clang_modules_once);
14641467
if (auto *A = Args.getLastArg(OPT_clang_build_session_file))
14651468
Opts.BuildSessionFilePath = A->getValue();

test/Concurrency/fail_implicit_concurrency_load.swift

+15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
// This test ensures that if implicit import of the Concurrency module is enabled,
22
// but no such module can be located (here verified by forcing explicit modules),
33
// a warning diagnostic is emitted.
4+
// UNSUPPORTED: OS=windows-msvc
45
// REQUIRES: concurrency
56
// RUN: %empty-directory(%t)
67
// RUN: mkdir -p %t/inputs
8+
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift_obj_root/lib/swift/shims/module.modulemap -o %t/inputs/SwiftShims.pcm
9+
// RUN: %target-swift-emit-pcm -module-name _SwiftConcurrencyShims %swift_obj_root/lib/swift/shims/module.modulemap -o %t/inputs/_SwiftConcurrencyShims.pcm
710

811
// RUN: echo "[{" > %/t/inputs/map.json
912
// RUN: echo "\"moduleName\": \"Swift\"," >> %/t/inputs/map.json
1013
// RUN: echo "\"modulePath\": \"%/stdlib_module\"," >> %/t/inputs/map.json
1114
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
1215
// RUN: echo "}," >> %/t/inputs/map.json
1316
// RUN: echo "{" >> %/t/inputs/map.json
17+
// RUN: echo "\"moduleName\": \"SwiftShims\"," >> %/t/inputs/map.json
18+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
19+
// RUN: echo "\"clangModuleMapPath\": \"%swift_obj_root/lib/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
20+
// RUN: echo "\"clangModulePath\": \"%t/inputs/SwiftShims.pcm\"" >> %/t/inputs/map.json
21+
// RUN: echo "}," >> %/t/inputs/map.json
22+
// RUN: echo "{" >> %/t/inputs/map.json
23+
// RUN: echo "\"moduleName\": \"_SwiftConcurrencyShims\"," >> %/t/inputs/map.json
24+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
25+
// RUN: echo "\"clangModuleMapPath\": \"%swift_obj_root/lib/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
26+
// RUN: echo "\"clangModulePath\": \"%t/inputs/_SwiftConcurrencyShims.pcm\"" >> %/t/inputs/map.json
27+
// RUN: echo "}," >> %/t/inputs/map.json
28+
// RUN: echo "{" >> %/t/inputs/map.json
1429
// RUN: echo "\"moduleName\": \"SwiftOnoneSupport\"," >> %/t/inputs/map.json
1530
// RUN: echo "\"modulePath\": \"%/ononesupport_module\"," >> %/t/inputs/map.json
1631
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json

test/Frontend/module-alias-explicit-build.swift

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/// Test the -module-alias flag with an explicit module loader.
2-
2+
// UNSUPPORTED: OS=windows-msvc
33
// RUN: %empty-directory(%t)
44
// RUN: mkdir -p %t/inputs
55
// RUN: mkdir -p %t/outputs
66

77
/// Create a module Bar
88
// RUN: echo 'public func bar() {}' > %t/inputs/FileBar.swift
99
// RUN: %target-swift-frontend -module-name Bar %t/inputs/FileBar.swift -emit-module -emit-module-path %t/inputs/Bar.swiftmodule
10+
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift_obj_root/lib/swift/shims/module.modulemap -o %t/inputs/SwiftShims.pcm
11+
// RUN: %target-swift-emit-pcm -module-name _SwiftConcurrencyShims %swift_obj_root/lib/swift/shims/module.modulemap -o %t/inputs/_SwiftConcurrencyShims.pcm
1012

1113
/// Check Bar.swiftmodule is created
1214
// RUN: test -f %t/inputs/Bar.swiftmodule
@@ -35,6 +37,18 @@
3537
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
3638
// RUN: echo "}," >> %/t/inputs/map.json
3739
// RUN: echo "{" >> %/t/inputs/map.json
40+
// RUN: echo "\"moduleName\": \"SwiftShims\"," >> %/t/inputs/map.json
41+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
42+
// RUN: echo "\"clangModuleMapPath\": \"%swift_obj_root/lib/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
43+
// RUN: echo "\"clangModulePath\": \"%t/inputs/SwiftShims.pcm\"" >> %/t/inputs/map.json
44+
// RUN: echo "}," >> %/t/inputs/map.json
45+
// RUN: echo "{" >> %/t/inputs/map.json
46+
// RUN: echo "\"moduleName\": \"_SwiftConcurrencyShims\"," >> %/t/inputs/map.json
47+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
48+
// RUN: echo "\"clangModuleMapPath\": \"%swift_obj_root/lib/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
49+
// RUN: echo "\"clangModulePath\": \"%t/inputs/_SwiftConcurrencyShims.pcm\"" >> %/t/inputs/map.json
50+
// RUN: echo "}," >> %/t/inputs/map.json
51+
// RUN: echo "{" >> %/t/inputs/map.json
3852
// RUN: echo "\"moduleName\": \"_StringProcessing\"," >> %/t/inputs/map.json
3953
// RUN: echo "\"modulePath\": \"%/string_processing_module\"," >> %/t/inputs/map.json
4054
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json

test/ScanDependencies/can_import_with_map.swift

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
// UNSUPPORTED: OS=windows-msvc
12
// RUN: %empty-directory(%t)
23
// RUN: mkdir -p %t/clang-module-cache
34
// RUN: mkdir -p %t/inputs
45
// RUN: echo "public func foo() {}" >> %t/foo.swift
56
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/inputs/Foo.swiftmodule -emit-module-doc-path %t/inputs/Foo.swiftdoc -emit-module-source-info -emit-module-source-info-path %t/inputs/Foo.swiftsourceinfo -module-cache-path %t.module-cache %t/foo.swift -module-name Foo
7+
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift_obj_root/lib/swift/shims/module.modulemap -o %t/inputs/SwiftShims.pcm
8+
// RUN: %target-swift-emit-pcm -module-name _SwiftConcurrencyShims %swift_obj_root/lib/swift/shims/module.modulemap -o %t/inputs/_SwiftConcurrencyShims.pcm
69

710
// RUN: echo "[{" > %/t/inputs/map.json
811
// RUN: echo "\"moduleName\": \"Foo\"," >> %/t/inputs/map.json
@@ -32,12 +35,24 @@
3235
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
3336
// RUN: echo "}," >> %/t/inputs/map.json
3437
// RUN: echo "{" >> %/t/inputs/map.json
38+
// RUN: echo "\"moduleName\": \"SwiftShims\"," >> %/t/inputs/map.json
39+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
40+
// RUN: echo "\"clangModuleMapPath\": \"%swift_obj_root/lib/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
41+
// RUN: echo "\"clangModulePath\": \"%t/inputs/SwiftShims.pcm\"" >> %/t/inputs/map.json
42+
// RUN: echo "}," >> %/t/inputs/map.json
43+
// RUN: echo "{" >> %/t/inputs/map.json
44+
// RUN: echo "\"moduleName\": \"_SwiftConcurrencyShims\"," >> %/t/inputs/map.json
45+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
46+
// RUN: echo "\"clangModuleMapPath\": \"%swift_obj_root/lib/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
47+
// RUN: echo "\"clangModulePath\": \"%t/inputs/_SwiftConcurrencyShims.pcm\"" >> %/t/inputs/map.json
48+
// RUN: echo "}," >> %/t/inputs/map.json
49+
// RUN: echo "{" >> %/t/inputs/map.json
3550
// RUN: echo "\"moduleName\": \"Distributed\"," >> %/t/inputs/map.json
3651
// RUN: echo "\"modulePath\": \"%/distributed_module\"," >> %/t/inputs/map.json
3752
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
3853
// RUN: echo "}]" >> %/t/inputs/map.json
3954

40-
// RUN: %target-swift-frontend -typecheck %s -explicit-swift-module-map-file %t/inputs/map.json -disable-implicit-swift-modules
55+
// RUN: %target-swift-frontend -typecheck %s -explicit-swift-module-map-file %t/inputs/map.json -disable-implicit-swift-modules -disable-implicit-concurrency-module-import
4156
#if canImport(Foo)
4257
import Foo
4358
#endif

test/ScanDependencies/explicit-framework-irgen.swift

+14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// RUN: echo "/// Some cool comments" > %t/foo.swift
55
// RUN: echo "public func foo() {}" >> %t/foo.swift
66
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/inputs/Foo.swiftmodule -emit-module-doc-path %t/inputs/Foo.swiftdoc -emit-module-source-info -emit-module-source-info-path %t/inputs/Foo.swiftsourceinfo -module-cache-path %t.module-cache %t/foo.swift -module-name Foo
7+
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift_obj_root/lib/swift/shims/module.modulemap -o %t/inputs/SwiftShims.pcm
8+
// RUN: %target-swift-emit-pcm -module-name _SwiftConcurrencyShims %swift_obj_root/lib/swift/shims/module.modulemap -o %t/inputs/_SwiftConcurrencyShims.pcm
79

810
// RUN: echo "[{" > %/t/inputs/map.json
911
// RUN: echo "\"moduleName\": \"Foo\"," >> %/t/inputs/map.json
@@ -33,6 +35,18 @@
3335
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
3436
// RUN: echo "}," >> %/t/inputs/map.json
3537
// RUN: echo "{" >> %/t/inputs/map.json
38+
// RUN: echo "\"moduleName\": \"SwiftShims\"," >> %/t/inputs/map.json
39+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
40+
// RUN: echo "\"clangModuleMapPath\": \"%swift_obj_root/lib/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
41+
// RUN: echo "\"clangModulePath\": \"%t/inputs/SwiftShims.pcm\"" >> %/t/inputs/map.json
42+
// RUN: echo "}," >> %/t/inputs/map.json
43+
// RUN: echo "{" >> %/t/inputs/map.json
44+
// RUN: echo "\"moduleName\": \"_SwiftConcurrencyShims\"," >> %/t/inputs/map.json
45+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
46+
// RUN: echo "\"clangModuleMapPath\": \"%swift_obj_root/lib/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
47+
// RUN: echo "\"clangModulePath\": \"%t/inputs/_SwiftConcurrencyShims.pcm\"" >> %/t/inputs/map.json
48+
// RUN: echo "}," >> %/t/inputs/map.json
49+
// RUN: echo "{" >> %/t/inputs/map.json
3650
// RUN: echo "\"moduleName\": \"Distributed\"," >> %/t/inputs/map.json
3751
// RUN: echo "\"modulePath\": \"%/distributed_module\"," >> %/t/inputs/map.json
3852
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json

test/ScanDependencies/explicit-module-map-clang-and-swift.swift

+15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
// UNSUPPORTED: OS=windows-msvc
12
// RUN: %empty-directory(%t)
23
// RUN: mkdir -p %t/clang-module-cache
34
// RUN: mkdir -p %t/inputs
45
// RUN: echo "public func anotherFuncA() {}" > %t/A.swift
56
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/inputs/A.swiftmodule -emit-module-doc-path %t/inputs/A.swiftdoc -emit-module-source-info -emit-module-source-info-path %t/inputs/A.swiftsourceinfo -import-underlying-module -I%S/Inputs/CHeaders -module-cache-path %t.module-cache %t/A.swift -module-name A
67
// RUN: %target-swift-emit-pcm -module-name A -o %t/inputs/A.pcm %S/Inputs/CHeaders/module.modulemap
8+
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift_obj_root/lib/swift/shims/module.modulemap -o %t/inputs/SwiftShims.pcm
9+
// RUN: %target-swift-emit-pcm -module-name _SwiftConcurrencyShims %swift_obj_root/lib/swift/shims/module.modulemap -o %t/inputs/_SwiftConcurrencyShims.pcm
710

811
// RUN: echo "[{" > %/t/inputs/map.json
912
// RUN: echo "\"moduleName\": \"A\"," >> %/t/inputs/map.json
@@ -33,6 +36,18 @@
3336
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
3437
// RUN: echo "}," >> %/t/inputs/map.json
3538
// RUN: echo "{" >> %/t/inputs/map.json
39+
// RUN: echo "\"moduleName\": \"SwiftShims\"," >> %/t/inputs/map.json
40+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
41+
// RUN: echo "\"clangModuleMapPath\": \"%swift_obj_root/lib/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
42+
// RUN: echo "\"clangModulePath\": \"%t/inputs/SwiftShims.pcm\"" >> %/t/inputs/map.json
43+
// RUN: echo "}," >> %/t/inputs/map.json
44+
// RUN: echo "{" >> %/t/inputs/map.json
45+
// RUN: echo "\"moduleName\": \"_SwiftConcurrencyShims\"," >> %/t/inputs/map.json
46+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
47+
// RUN: echo "\"clangModuleMapPath\": \"%swift_obj_root/lib/swift/shims/module.modulemap\"," >> %/t/inputs/map.json
48+
// RUN: echo "\"clangModulePath\": \"%t/inputs/_SwiftConcurrencyShims.pcm\"" >> %/t/inputs/map.json
49+
// RUN: echo "}," >> %/t/inputs/map.json
50+
// RUN: echo "{" >> %/t/inputs/map.json
3651
// RUN: echo "\"moduleName\": \"_StringProcessing\"," >> %/t/inputs/map.json
3752
// RUN: echo "\"modulePath\": \"%/string_processing_module\"," >> %/t/inputs/map.json
3853
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json

0 commit comments

Comments
 (0)