Skip to content

Commit 6ea6751

Browse files
committed
[cxx-interop] Enable C++ stdlib overlay on Linux
1 parent c70d8fd commit 6ea6751

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ getClangInvocationFileMapping(ASTContext &ctx) {
894894
// If an SDK path was explicitly passed to Swift, make sure to pass it to
895895
// Clang driver as well. It affects the resulting include paths.
896896
auto sdkPath = ctx.SearchPathOpts.getSDKPath();
897+
llvm::errs() << "DIR: " << sdkPath << "\n";
897898
if (!sdkPath.empty()) {
898899
unsigned argIndex = clangDriverArgs.MakeIndex("--sysroot", sdkPath);
899900
clangDriverArgs.append(new llvm::opt::Arg(
@@ -902,6 +903,9 @@ getClangInvocationFileMapping(ASTContext &ctx) {
902903
}
903904
auto cxxStdlibDirs =
904905
clangDriver.getLibStdCxxIncludePaths(clangDriverArgs, triple);
906+
for (auto it : cxxStdlibDirs) {
907+
llvm::errs() << "DIR: " << it << "\n";
908+
}
905909
if (cxxStdlibDirs.empty()) {
906910
ctx.Diags.diagnose(SourceLoc(), diag::libstdcxx_not_found, triple.str());
907911
return {};
@@ -920,6 +924,8 @@ getClangInvocationFileMapping(ASTContext &ctx) {
920924
actualModuleMapPath = path.getValue();
921925
else
922926
return {};
927+
llvm::sys::path::remove_dots(actualModuleMapPath, /*remove_dot_dot=*/true);
928+
llvm::errs() << "actualModuleMapPath: " << actualModuleMapPath << "\n";
923929

924930
// Only inject the module map if it actually exists. It may not, for example
925931
// if `swiftc -target x86_64-unknown-linux-gnu -emit-ir` is invoked using
@@ -928,6 +934,7 @@ getClangInvocationFileMapping(ASTContext &ctx) {
928934
// FIXME: emit a warning of some kind.
929935
return {};
930936

937+
llvm::errs() << "exists: " << actualModuleMapPath << "\n";
931938
// TODO: remove the libstdcxx.h header and reference all libstdc++ headers
932939
// directly from the modulemap.
933940
Path actualHeaderPath = actualModuleMapPath;
@@ -950,6 +957,8 @@ getClangInvocationFileMapping(ASTContext &ctx) {
950957
Path injectedHeaderPath(cxxStdlibDir);
951958
llvm::sys::path::append(injectedHeaderPath, "libstdcxx.h");
952959

960+
llvm::errs() << "injecting \n";
961+
llvm::errs() << injectedModuleMapPath << " to " << actualModuleMapPath << "\n";
953962
return {
954963
{std::string(injectedModuleMapPath), std::string(actualModuleMapPath)},
955964
{std::string(injectedHeaderPath), std::string(actualHeaderPath)},
@@ -1211,7 +1220,7 @@ ClangImporter::create(ASTContext &ctx,
12111220
auto fileMapping = getClangInvocationFileMapping(ctx);
12121221
// Wrap Swift's FS to allow Clang to override the working directory
12131222
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
1214-
llvm::vfs::RedirectingFileSystem::create(fileMapping, true,
1223+
llvm::vfs::RedirectingFileSystem::create(fileMapping, false,
12151224
*ctx.SourceMgr.getFileSystem());
12161225

12171226
// Create a new Clang compiler invocation.

stdlib/public/Cxx/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ add_swift_target_library(swiftstd ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVE
139139
SWIFT_COMPILE_FLAGS ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
140140
-Xfrontend -enable-experimental-cxx-interop
141141
-Xfrontend -module-interface-preserve-types-as-written
142+
-Xcc --gcc-toolchain=/usr
143+
-Xcc -v
142144

143-
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" -lc++
144-
TARGET_SDKS ALL_APPLE_PLATFORMS # TODO: support other platforms as well
145+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
146+
TARGET_SDKS ALL_APPLE_PLATFORMS LINUX # TODO: support other platforms as well
145147
INSTALL_IN_COMPONENT sdk-overlay)

test/Interop/Cxx/stdlib/overlay/string.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-cxx-interop)
22
//
33
// REQUIRES: executable_test
4-
// REQUIRES: OS=macosx
4+
// REQUIRES: OS=macosx || OS=linux-gnu
55

66
import StdlibUnittest
77
import std

0 commit comments

Comments
 (0)