@@ -430,14 +430,10 @@ ClangImporter::~ClangImporter() {
430430
431431#pragma mark Module loading
432432
433- // / Finds the glibc.modulemap file relative to the provided resource dir.
434- // /
435- // / Note that the module map used for Glibc depends on the target we're
436- // / compiling for, and is not included in the resource directory with the other
437- // / implicit module maps. It's at {freebsd|linux}/{arch}/glibc.modulemap.
438- static Optional<StringRef>
439- getGlibcModuleMapPath (SearchPathOptions& Opts, llvm::Triple triple,
440- SmallVectorImpl<char > &buffer) {
433+ static Optional<StringRef> getModuleMapFilePath (StringRef name,
434+ SearchPathOptions &Opts,
435+ llvm::Triple triple,
436+ SmallVectorImpl<char > &buffer) {
441437 StringRef platform = swift::getPlatformNameForTriple (triple);
442438 StringRef arch = swift::getMajorArchitectureName (triple);
443439
@@ -446,7 +442,7 @@ getGlibcModuleMapPath(SearchPathOptions& Opts, llvm::Triple triple,
446442 buffer.clear ();
447443 buffer.append (SDKPath.begin (), SDKPath.end ());
448444 llvm::sys::path::append (buffer, " usr" , " lib" , " swift" );
449- llvm::sys::path::append (buffer, platform, arch, " glibc.modulemap " );
445+ llvm::sys::path::append (buffer, platform, arch, name );
450446
451447 // Only specify the module map if that file actually exists. It may not;
452448 // for example in the case that `swiftc -target x86_64-unknown-linux-gnu
@@ -459,7 +455,7 @@ getGlibcModuleMapPath(SearchPathOptions& Opts, llvm::Triple triple,
459455 buffer.clear ();
460456 buffer.append (Opts.RuntimeResourcePath .begin (),
461457 Opts.RuntimeResourcePath .end ());
462- llvm::sys::path::append (buffer, platform, arch, " glibc.modulemap " );
458+ llvm::sys::path::append (buffer, platform, arch, name );
463459
464460 // Only specify the module map if that file actually exists. It may not;
465461 // for example in the case that `swiftc -target x86_64-unknown-linux-gnu
@@ -471,6 +467,23 @@ getGlibcModuleMapPath(SearchPathOptions& Opts, llvm::Triple triple,
471467 return None;
472468}
473469
470+ // / Finds the glibc.modulemap file relative to the provided resource dir.
471+ // /
472+ // / Note that the module map used for Glibc depends on the target we're
473+ // / compiling for, and is not included in the resource directory with the other
474+ // / implicit module maps. It's at {freebsd|linux}/{arch}/glibc.modulemap.
475+ static Optional<StringRef>
476+ getGlibcModuleMapPath (SearchPathOptions &Opts, llvm::Triple triple,
477+ SmallVectorImpl<char > &buffer) {
478+ return getModuleMapFilePath (" glibc.modulemap" , Opts, triple, buffer);
479+ }
480+
481+ static Optional<StringRef>
482+ getLibStdCxxModuleMapPath (SearchPathOptions &opts, llvm::Triple triple,
483+ SmallVectorImpl<char > &buffer) {
484+ return getModuleMapFilePath (" libstdcxx.modulemap" , opts, triple, buffer);
485+ }
486+
474487static bool clangSupportsPragmaAttributeWithSwiftAttr () {
475488 clang::AttributeCommonInfo swiftAttrInfo (clang::SourceRange (),
476489 clang::AttributeCommonInfo::AT_SwiftAttr,
@@ -680,6 +693,14 @@ importer::getNormalInvocationArguments(
680693 } else {
681694 // FIXME: Emit a warning of some kind.
682695 }
696+
697+ if (EnableCXXInterop) {
698+ if (auto path =
699+ getLibStdCxxModuleMapPath (searchPathOpts, triple, buffer)) {
700+ invocationArgStrs.push_back (
701+ (Twine (" -fmodule-map-file=" ) + *path).str ());
702+ }
703+ }
683704 }
684705
685706 if (searchPathOpts.getSDKPath ().empty ()) {
0 commit comments