Skip to content

Commit 5dd9daf

Browse files
committed
clang import std
llvm/llvm-project#75741
1 parent a9c0587 commit 5dd9daf

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

import-std/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,23 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
3535
BASE_DIRS ${modules}
3636
FILES ${modules}/std.ixx
3737
)
38+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
39+
include(CheckCXXSymbolExists)
40+
check_cxx_symbol_exists(_LIBCPP_VERSION version libcxx)
41+
if(libcxx)
42+
find_path(modules REQUIRED
43+
NAMES
44+
std.cppm
45+
PATH_SUFFIXES
46+
share/libc++/v1
47+
PATHS
48+
"${CMAKE_CXX_COMPILER}/../.."
49+
NO_DEFAULT_PATH
50+
)
51+
target_sources(${PROJECT_NAME} PUBLIC FILE_SET CXX_MODULES
52+
BASE_DIRS ${modules}
53+
FILES ${modules}/std.cppm
54+
)
55+
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-reserved-module-identifier)
56+
endif()
3857
endif()

import-std/Makefile.clang

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CLANG_DIR_CMD = $(PREFIX)clang++ -print-resource-dir
2+
STD_CPPM_LOC = /../../../share/libc++/v1/std.cppm
3+
4+
hello.exe: main.cpp std.o std.pcm
5+
$(PREFIX)clang++ -stdlib=libc++ -std=c++23 -fprebuilt-module-path=. main.cpp std.o -o hello.exe
6+
7+
std.o std.pcm: std.cppm.o
8+
$(PREFIX)clang++ -stdlib=libc++ -std=c++23 -fmodule-output=std.pcm -c @std.cppm.o -Wno-reserved-module-identifier
9+
10+
std.cppm.o:
11+
-FOR /F "delims=" %%i IN ('$(CLANG_DIR_CMD)') DO @echo %%i$(STD_CPPM_LOC) >> std.cppm.o
12+
-printf `$(CLANG_DIR_CMD)`$(STD_CPPM_LOC) >> std.cppm.o
13+
14+
clean:
15+
-rm *.pcm *.o *.exe
16+
-del *.pcm *.o *.exe

import-std/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
#include <version>
2+
3+
// https://github.com/llvm/llvm-project/issues/89579
4+
#ifdef _LIBCPP_VERSION
5+
#define __cpp_lib_modules 202207L
6+
#endif
7+
8+
#ifdef __cpp_lib_modules
19
import std;
10+
#endif
211

312
int main()
413
{
14+
#ifdef __cpp_lib_modules
515
std::println("{}", "Hello, World!");
16+
#endif
617
}

0 commit comments

Comments
 (0)