[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.
This commit is contained in:
Chuanqi Xu
2025-01-15 16:59:40 +08:00
parent af656a8d42
commit 2c34632a99
2 changed files with 22 additions and 4 deletions

View File

@@ -6501,9 +6501,24 @@ std::string Driver::GetStdModuleManifestPath(const Compilation &C,
return evaluate("libc++.a").value_or(error);
}
case ToolChain::CST_Libstdcxx:
// libstdc++ does not provide Standard library modules yet.
return error;
case ToolChain::CST_Libstdcxx: {
auto evaluate = [&](const char *library) -> std::optional<std::string> {
std::string lib = GetFilePath(library, TC);
SmallString<128> path(lib.begin(), lib.end());
llvm::sys::path::remove_filename(path);
llvm::sys::path::append(path, "libstdc++.modules.json");
if (TC.getVFS().exists(path))
return static_cast<std::string>(path);
return {};
};
if (std::optional<std::string> result = evaluate("libstdc++.so"); result)
return *result;
return evaluate("libstdc++.a").value_or(error);
}
}
return error;

View File

@@ -48,6 +48,9 @@
// RUN: --target=x86_64-linux-gnu 2>&1 \
// RUN: | FileCheck libcxx-no-shared-lib.cpp
// Testing with libstdc++
// RUN: touch %t/Inputs/usr/lib/x86_64-linux-gnu/libstdc++.so
// RUN: touch %t/Inputs/usr/lib/x86_64-linux-gnu/libstdc++.modules.json
// RUN: %clang -print-library-module-manifest-path \
// RUN: -stdlib=libstdc++ \
// RUN: -resource-dir=%t/Inputs/usr/lib/x86_64-linux-gnu \
@@ -74,4 +77,4 @@
//--- libstdcxx.cpp
// CHECK: <NOT PRESENT>
// CHECK: {{.*}}libstdc++.modules.json