Skip to content

Commit 2c34632

Browse files
committed
[C++20] [Modules] [Driver] Support -print-library-module-manifest-path for libstdc++
Given libstdc++ has landed std module, the build systems may need clang to find the configuration file to understand how to build the std module. This patch did this. Tested with locally installed GCC-trunk.
1 parent af656a8 commit 2c34632

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6501,9 +6501,24 @@ std::string Driver::GetStdModuleManifestPath(const Compilation &C,
65016501
return evaluate("libc++.a").value_or(error);
65026502
}
65036503

6504-
case ToolChain::CST_Libstdcxx:
6505-
// libstdc++ does not provide Standard library modules yet.
6506-
return error;
6504+
case ToolChain::CST_Libstdcxx: {
6505+
auto evaluate = [&](const char *library) -> std::optional<std::string> {
6506+
std::string lib = GetFilePath(library, TC);
6507+
6508+
SmallString<128> path(lib.begin(), lib.end());
6509+
llvm::sys::path::remove_filename(path);
6510+
llvm::sys::path::append(path, "libstdc++.modules.json");
6511+
if (TC.getVFS().exists(path))
6512+
return static_cast<std::string>(path);
6513+
6514+
return {};
6515+
};
6516+
6517+
if (std::optional<std::string> result = evaluate("libstdc++.so"); result)
6518+
return *result;
6519+
6520+
return evaluate("libstdc++.a").value_or(error);
6521+
}
65076522
}
65086523

65096524
return error;

clang/test/Driver/modules-print-library-module-manifest-path.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
// RUN: --target=x86_64-linux-gnu 2>&1 \
4949
// RUN: | FileCheck libcxx-no-shared-lib.cpp
5050

51+
// Testing with libstdc++
52+
// RUN: touch %t/Inputs/usr/lib/x86_64-linux-gnu/libstdc++.so
53+
// RUN: touch %t/Inputs/usr/lib/x86_64-linux-gnu/libstdc++.modules.json
5154
// RUN: %clang -print-library-module-manifest-path \
5255
// RUN: -stdlib=libstdc++ \
5356
// RUN: -resource-dir=%t/Inputs/usr/lib/x86_64-linux-gnu \
@@ -74,4 +77,4 @@
7477

7578
//--- libstdcxx.cpp
7679

77-
// CHECK: <NOT PRESENT>
80+
// CHECK: {{.*}}libstdc++.modules.json

0 commit comments

Comments
 (0)