Skip to content

Commit 9e88549

Browse files
committed
ModuleInterface: teach module interface building to use explicitly built PCMs
1 parent 38b3d81 commit 9e88549

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

include/swift/ClangImporter/ClangImporterOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ class ClangImporterOptions {
103103
/// DWARFImporter delegate.
104104
bool DisableSourceImport = false;
105105

106+
/// When set, use ExtraArgs alone to configure clang instance because ExtraArgs
107+
/// contains the full option set.
108+
bool ExtraArgsOnly = false;
109+
106110
/// Return a hash code of any components from these options that should
107111
/// contribute to a Swift Bridging PCH hash.
108112
llvm::hash_code getPCHHashComponents() const {

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,4 +717,6 @@ def target_sdk_version : Separate<["-"], "target-sdk-version">,
717717
def target_variant_sdk_version : Separate<["-"], "target-variant-sdk-version">,
718718
HelpText<"The version of target variant SDK used for compilation">;
719719

720+
def extra_clang_options_only : Flag<["-"], "only-use-extra-clang-opts">,
721+
HelpText<"Options passed via -Xcc are sufficient for Clang configuration">;
720722
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,9 @@ ClangImporter::getOrCreatePCH(const ClangImporterOptions &ImporterOptions,
908908
std::vector<std::string>
909909
ClangImporter::getClangArguments(ASTContext &ctx,
910910
const ClangImporterOptions &importerOpts) {
911+
if (importerOpts.ExtraArgsOnly) {
912+
return importerOpts.ExtraArgs;
913+
}
911914
std::vector<std::string> invocationArgStrs;
912915
// Clang expects this to be like an actual command line. So we need to pass in
913916
// "clang" for argv[0]

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,30 +211,27 @@ void ClangImporter::recordModuleDependencies(
211211
fileDeps.push_back(fileDep.getKey().str());
212212
}
213213
// Inherit all Clang driver args when creating the clang importer.
214-
std::vector<std::string> allArgs = Impl.ClangArgs;
214+
ArrayRef<std::string> allArgs = Impl.ClangArgs;
215215
ClangImporterOptions Opts;
216-
std::vector<std::string> cc1Args;
217216

218-
// Calling this to convert driver args to CC1 args.
219-
createClangInvocation(this, Opts, allArgs, &cc1Args);
217+
// Ensure the arguments we collected is sufficient to create a Clang
218+
// invocation.
219+
assert(createClangInvocation(this, Opts, allArgs));
220+
220221
std::vector<std::string> swiftArgs;
221222
// We are using Swift frontend mode.
222223
swiftArgs.push_back("-frontend");
224+
// We pass the entire argument list via -Xcc, so the invocation should
225+
// use extra clang options alone.
226+
swiftArgs.push_back("-only-use-extra-clang-opts");
223227
auto addClangArg = [&](StringRef arg) {
224-
swiftArgs.push_back("-Xcc");
225-
swiftArgs.push_back("-Xclang");
226228
swiftArgs.push_back("-Xcc");
227229
swiftArgs.push_back(arg.str());
228230
};
229231
// Add all args inheritted from creating the importer.
230-
for (auto arg: cc1Args) {
232+
for (auto arg: allArgs) {
231233
addClangArg(arg);
232234
}
233-
// Add all args reported from the Clang dependencies scanner.
234-
for(auto arg: clangModuleDep.NonPathCommandLine) {
235-
addClangArg(arg);
236-
}
237-
238235
// Swift frontend action: -emit-pcm
239236
swiftArgs.push_back("-emit-pcm");
240237
swiftArgs.push_back("-module-name");

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,8 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
802802

803803
Opts.DisableOverlayModules |= Args.hasArg(OPT_emit_imported_modules);
804804

805+
Opts.ExtraArgsOnly |= Args.hasArg(OPT_extra_clang_options_only);
806+
805807
if (const Arg *A = Args.getLastArg(OPT_pch_output_dir)) {
806808
Opts.PrecompiledHeaderOutputDir = A->getValue();
807809
Opts.PCHDisableValidation |= Args.hasArg(OPT_pch_disable_validation);

test/ScanDependencies/module_deps.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path C.pcm -o %t/clang-module-cache/C.pcm -Xcc -Xclang -Xcc -fmodule-map-file=%S/Inputs/CHeaders/module.modulemap -Xcc -Xclang -Xcc -fmodule-file=%t/clang-module-cache/B.pcm | %S/Inputs/CommandRunner.py
3232
// RUN: ls %t/clang-module-cache/C.pcm
3333

34+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path A.swiftmodule -o %t/clang-module-cache/A.swiftmodule -Xcc -Xclang -Xcc -fmodule-map-file=%S/Inputs/CHeaders/module.modulemap -Xcc -Xclang -Xcc -fmodule-file=%t/clang-module-cache/A.pcm -Xcc -Xclang -Xcc -fmodule-file=%t/clang-module-cache/SwiftShims.pcm | %S/Inputs/CommandRunner.py
35+
// RUN: ls %t/clang-module-cache/A.swiftmodule
36+
37+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path E.swiftmodule -o %t/clang-module-cache/E.swiftmodule -Xcc -Xclang -Xcc -fmodule-map-file=%S/Inputs/CHeaders/module.modulemap -Xcc -Xclang -Xcc -fmodule-file=%t/clang-module-cache/SwiftShims.pcm | %S/Inputs/CommandRunner.py
38+
// RUN: ls %t/clang-module-cache/E.swiftmodule
39+
3440

3541
// REQUIRES: executable_test
3642
// REQUIRES: objc_interop
@@ -100,11 +106,10 @@ import G
100106

101107
// CHECK: "commandLine": [
102108
// CHECK-NEXT: "-frontend"
109+
// CHECK-NEXT: "-only-use-extra-clang-opts"
103110
// CHECK-NEXT: "-Xcc"
104-
// CHECK-NEXT: "-Xclang"
105-
// CHECK-NEXT: "-Xcc"
106-
// CHECK-NEXT: "-cc1"
107-
// CHECK: "-remove-preceeding-explicit-module-build-incompatible-options"
111+
// CHECK-NEXT: "clang"
112+
// CHECK: "-fno-implicit-modules"
108113

109114
/// --------Swift module E
110115
// CHECK: "swift": "E"

0 commit comments

Comments
 (0)