Skip to content

Commit 752cb36

Browse files
authored
Merge pull request #78014 from swiftlang/egorzhdan/libcxx-overlay-linux
[cxx-interop] Support CxxStdlib overlay for libc++ on Linux
2 parents d314541 + 282f3b1 commit 752cb36

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

lib/AST/ModuleLoader.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,6 @@ void ModuleLoader::findOverlayFiles(SourceLoc diagLoc, ModuleDecl *module,
172172
using namespace llvm::sys;
173173
using namespace file_types;
174174

175-
// If an overlay for CxxStdlib was requested, only proceed if compiling with
176-
// the platform-default C++ stdlib.
177-
if (module->getName() == module->getASTContext().Id_CxxStdlib &&
178-
!module->getASTContext().LangOpts.isUsingPlatformDefaultCXXStdlib())
179-
return;
180-
181175
// If cross import information is passed on command-line, prefer use that.
182176
auto &crossImports = module->getASTContext().SearchPathOpts.CrossImportInfo;
183177
auto overlays = crossImports.find(module->getNameStr());

lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4365,10 +4365,8 @@ ModuleDecl *ClangModuleUnit::getOverlayModule() const {
43654365
}
43664366
// If this Clang module is a part of the C++ stdlib, and we haven't loaded
43674367
// the overlay for it so far, it is a split libc++ module (e.g. std_vector).
4368-
// Load the CxxStdlib overlay explicitly, if building with the
4369-
// platform-default C++ stdlib.
4370-
if (!overlay && importer::isCxxStdModule(clangModule) &&
4371-
Ctx.LangOpts.isUsingPlatformDefaultCXXStdlib()) {
4368+
// Load the CxxStdlib overlay explicitly.
4369+
if (!overlay && importer::isCxxStdModule(clangModule)) {
43724370
ImportPath::Module::Builder builder(Ctx.Id_CxxStdlib);
43734371
overlay = owner.loadModule(SourceLoc(), std::move(builder).get());
43744372
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,15 @@ void CompilerInvocation::computeCXXStdlibOptions() {
384384
LangOpts.CXXStdlib = toCXXStdlibKind(cxxStdlibKind);
385385
LangOpts.PlatformDefaultCXXStdlib = toCXXStdlibKind(cxxDefaultStdlibKind);
386386
}
387+
388+
if (!LangOpts.isUsingPlatformDefaultCXXStdlib()) {
389+
// The CxxStdlib overlay was built for the platform default C++ stdlib, and
390+
// its .swiftmodule file refers to implementation-specific symbols (such as
391+
// namespace __1 in libc++, or namespace __cxx11 in libstdc++). Let's
392+
// proactively rebuild the CxxStdlib module from its .swiftinterface if a
393+
// non-default C++ stdlib is used.
394+
FrontendOpts.PreferInterfaceForModules.push_back("CxxStdlib");
395+
}
387396
}
388397

389398
void CompilerInvocation::setRuntimeResourcePath(StringRef Path) {

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,15 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
20322032

20332033
GenericArgs.push_back(
20342034
ArgSaver.save("-cxx-interoperability-mode=" + compatVersion));
2035+
2036+
if (!langOpts.isUsingPlatformDefaultCXXStdlib() &&
2037+
langOpts.CXXStdlib == CXXStdlibKind::Libcxx) {
2038+
genericSubInvocation.getLangOptions().CXXStdlib = CXXStdlibKind::Libcxx;
2039+
genericSubInvocation.getClangImporterOptions().ExtraArgs.push_back(
2040+
"-stdlib=libc++");
2041+
GenericArgs.push_back("-Xcc");
2042+
GenericArgs.push_back("-stdlib=libc++");
2043+
}
20352044
}
20362045
}
20372046

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This test runs another test, use-std-chrono.swift, with libc++ explicitly specified as the C++ stdlib.
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-build-swift %S/use-std-chrono.swift -I %S/Inputs -o %t/exe -cxx-interoperability-mode=upcoming-swift -Xcc -stdlib=libc++
5+
// RUN: %target-codesign %t/exe
6+
// RUN: %target-run %t/exe
7+
8+
// REQUIRES: executable_test
9+
// REQUIRES: OS=linux-gnu
10+
// REQUIRES: system_wide_libcxx
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This test runs another test, use-std-string-view.swift, with libc++ explicitly specified as the C++ stdlib.
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-build-swift %S/use-std-string-view.swift -I %S/Inputs -o %t/exe -cxx-interoperability-mode=upcoming-swift -Xcc -stdlib=libc++
5+
// RUN: %target-codesign %t/exe
6+
// RUN: %target-run %t/exe
7+
8+
// REQUIRES: executable_test
9+
// REQUIRES: OS=linux-gnu
10+
// REQUIRES: system_wide_libcxx

0 commit comments

Comments
 (0)