@@ -1159,6 +1159,14 @@ static std::string GetPluginServerForSDK(llvm::StringRef sdk_path) {
1159
1159
return server_or_err->str ();
1160
1160
}
1161
1161
1162
+ namespace {
1163
+ constexpr std::array<std::string_view, 4 > g_known_eplicit_module_prefixes =
1164
+ {" -fmodule-map-file=" ,
1165
+ " -fmodule-file=" ,
1166
+ " -fno-implicit-modules" ,
1167
+ " -fno-implicit-module-maps" };
1168
+ }
1169
+
1162
1170
// / Retrieve the serialized AST data blobs and initialize the compiler
1163
1171
// / invocation with the concatenated search paths from the blobs.
1164
1172
// / \returns true if an error was encountered.
@@ -1300,6 +1308,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
1300
1308
<< getImportFailureString (result) << " \n " ;
1301
1309
return false ;
1302
1310
}
1311
+
1303
1312
if (discover_implicit_search_paths) {
1304
1313
for (auto &searchPath : searchPaths) {
1305
1314
std::string path = remap (searchPath.Path );
@@ -1482,8 +1491,8 @@ bool ConsumeIncludeOption(StringRef &arg, StringRef &prefix) {
1482
1491
}
1483
1492
1484
1493
std::array<StringRef, 2 > macro_flags = { " -D" , " -U" };
1485
- std::array<StringRef, 5 > multi_arg_flags =
1486
- { " -D" , " -U" , " -I" , " -F" , " -working-directory" };
1494
+ std::array<StringRef, 6 > multi_arg_flags = {
1495
+ " -D" , " -U" , " -I" , " -F" , " -working-directory" , " -triple " };
1487
1496
std::array<StringRef, 6 > args_to_unique = {
1488
1497
" -D" , " -U" , " -I" , " -F" , " -fmodule-file=" , " -fmodule-map-file=" };
1489
1498
@@ -1518,7 +1527,25 @@ void SwiftASTContext::AddExtraClangArgs(const std::vector<std::string> &source,
1518
1527
1519
1528
llvm::SmallString<128 > cur_working_dir;
1520
1529
llvm::SmallString<128 > clang_argument;
1530
+
1531
+ auto match_explicit_build_option = [](StringRef arg) {
1532
+ for (const auto &option : g_known_eplicit_module_prefixes)
1533
+ if (arg.starts_with (option))
1534
+ return true ;
1535
+ return false ;
1536
+ };
1537
+ bool has_explicit_builds_enabled =
1538
+ llvm::find (source, " -fno-implicit-modules" ) != source.end ();
1539
+
1521
1540
for (const std::string &arg : source) {
1541
+ // Ignore the `-triple` flag. First, this is not a driver flag, and second,
1542
+ // lldb has its own logic to determine the target. Ignore now, before
1543
+ // appending the argument.
1544
+ if (clang_argument == " -triple" ) {
1545
+ clang_argument.clear ();
1546
+ continue ;
1547
+ }
1548
+
1522
1549
// Join multi-arg options for uniquing.
1523
1550
clang_argument += arg;
1524
1551
if (IsMultiArgClangFlag (clang_argument))
@@ -1548,6 +1575,14 @@ void SwiftASTContext::AddExtraClangArgs(const std::vector<std::string> &source,
1548
1575
if (clang_argument.empty ())
1549
1576
continue ;
1550
1577
1578
+ // In case of explicit modules, for now fallback to implicit
1579
+ // module loading.
1580
+ // TODO: Incorporate loading explicit module dependencies to
1581
+ // speedup dependency resolution.
1582
+ if (has_explicit_builds_enabled &&
1583
+ match_explicit_build_option (clang_argument))
1584
+ continue ;
1585
+
1551
1586
// Otherwise add the argument to the list.
1552
1587
if (!IsMacroDefinition (clang_argument))
1553
1588
ApplyWorkingDir (clang_argument, cur_working_dir);
0 commit comments