[clang] 2c34632 - [C++20] [Modules] [Driver] Support -print-library-module-manifest-path for libstdc++

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 15 01:01:54 PST 2025


Author: Chuanqi Xu
Date: 2025-01-15T17:01:18+08:00
New Revision: 2c34632a9977a82ce6262d95f07addb772ba7014

URL: https://github.com/llvm/llvm-project/commit/2c34632a9977a82ce6262d95f07addb772ba7014
DIFF: https://github.com/llvm/llvm-project/commit/2c34632a9977a82ce6262d95f07addb772ba7014.diff

LOG: [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.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9a947f32283c3a..eefbdca805739e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -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;

diff  --git a/clang/test/Driver/modules-print-library-module-manifest-path.cpp b/clang/test/Driver/modules-print-library-module-manifest-path.cpp
index 8d17fe1549e34b..7606713bfa22a5 100644
--- a/clang/test/Driver/modules-print-library-module-manifest-path.cpp
+++ b/clang/test/Driver/modules-print-library-module-manifest-path.cpp
@@ -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
\ No newline at end of file


        


More information about the cfe-commits mailing list