Skip to content

Commit cd70802

Browse files
billhoffmantru
authored andcommitted
Fix print module manifest file for macos (#122370)
This commit fixes -print-library-module-manifest-path on macos. Currently, this only works on linux systems. This is because on macos systems the library and header files are installed in a different location. The module manifest is next to the libraries and the search function was not looking in both places. There is also a test included. (cherry picked from commit acbd822)
1 parent 37aaa06 commit cd70802

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

clang/lib/Driver/Driver.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -6189,6 +6189,11 @@ std::string Driver::GetFilePath(StringRef Name, const ToolChain &TC) const {
61896189
if (auto P = SearchPaths(TC.getFilePaths()))
61906190
return *P;
61916191

6192+
SmallString<128> R2(ResourceDir);
6193+
llvm::sys::path::append(R2, "..", "..", Name);
6194+
if (llvm::sys::fs::exists(Twine(R2)))
6195+
return std::string(R2);
6196+
61926197
return std::string(Name);
61936198
}
61946199

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

+26
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,28 @@
1818
// RUN: --target=x86_64-linux-gnu 2>&1 \
1919
// RUN: | FileCheck libcxx.cpp
2020

21+
// for macos there is a different directory structure
22+
// where the library and libc++.modules.json file are in lib
23+
// directly but headers are in clang/ver directory which
24+
// is the resource directory
25+
// RUN: mkdir -p %t/Inputs/usr/lib/clang/20
26+
// RUN: touch %t/Inputs/usr/lib/libc++.so
27+
// RUN: touch %t/Inputs/usr/lib/libc++.modules.json
28+
// RUN: %clang -print-library-module-manifest-path \
29+
// RUN: -stdlib=libc++ \
30+
// RUN: -resource-dir=%t/Inputs/usr/lib/clang/20 \
31+
// RUN: --target=arm64-apple-darwin24.1.0 2>&1 \
32+
// RUN: | FileCheck libcxx.cpp.macos
33+
34+
// RUN: rm %t/Inputs/usr/lib/libc++.so
35+
// RUN: touch %t/Inputs/usr/lib/libc++.a
36+
// RUN: touch %t/Inputs/usr/lib/libc++.modules.json
37+
// RUN: %clang -print-library-module-manifest-path \
38+
// RUN: -stdlib=libc++ \
39+
// RUN: -resource-dir=%t/Inputs/usr/lib/clang/20 \
40+
// RUN: --target=arm64-apple-darwin24.1.0 2>&1 \
41+
// RUN: | FileCheck libcxx.cpp.macos
42+
2143
// RUN: rm %t/Inputs/usr/lib/x86_64-linux-gnu/libc++.so
2244
// RUN: touch %t/Inputs/usr/lib/x86_64-linux-gnu/libc++.a
2345
// RUN: %clang -print-library-module-manifest-path \
@@ -40,6 +62,10 @@
4062

4163
// CHECK: {{.*}}/Inputs/usr/lib/x86_64-linux-gnu{{/|\\}}libc++.modules.json
4264

65+
//--- libcxx.cpp.macos
66+
67+
// CHECK: {{.*}}libc++.modules.json
68+
4369
//--- libcxx-no-shared-lib.cpp
4470

4571
// Note this might find a different path depending whether search path

0 commit comments

Comments
 (0)