LLVM Discussion Forums Libc++ C++23 module installation support

I finally found time to look into this. The following script should do the building and testing in the current directory. You need to adjust clang and install to the build installation paths.

#!/bin/bash

# The clang++ compiler to use for testing
export clang=/usr/bin/clang++-19
# The installation path of libc++
export install=/usr/lib/llvm-19

# Generates test application
cat << EOF > main.cpp
import std; // When importing std.compat it's not needed to import std.
import std.compat;

int main() {
  std::cout << "Hello modular world\n";
  ::printf("Hello compat modular world\n");
}
EOF

# Builds the std module
$clang -std=c++20 \
	-nostdinc++ \
	-isystem $install/include/c++/v1/ \
	-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal \
	--precompile -o std.pcm \
	-c $install/share/libc++/v1/std.cppm

# Builds the std.compat module
$clang -std=c++20 \
	-nostdinc++ \
	-isystem $install/include/c++/v1/ \
	-Wno-reserved-module-identifier -Wno-reserved-user-defined-literal \
	--precompile -o std.compat.pcm \
	-fmodule-file=std=std.pcm \
	-c $install/share/libc++/v1/std.compat.cppm

# Builds the test application
$clang -std=c++20 \
	-nostdinc++ \
	-isystem $install/include/c++/v1/ \
	-L $install/lib \
	-fmodule-file=std=std.pcm \
	-fmodule-file=std.compat=std.compat.pcm \
	std.pcm \
	std.compat.pcm \
	-lc++ \
	main.cpp

# Runs the test application
# The output should be
#   Hello modular world
#   Hello compat modular world
./a.out