Skip to content

Commit 247c603

Browse files
Add modules CI for building the modules
1 parent 494d195 commit 247c603

2 files changed

Lines changed: 192 additions & 0 deletions

File tree

.github/workflows/modules-ci.yml

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
name: C++20 Modules CI
2+
on: [push, workflow_dispatch, pull_request]
3+
4+
env:
5+
# Enable verbose output for CMake and tests
6+
VERBOSE: 1
7+
CTEST_OUTPUT_ON_FAILURE: 1
8+
9+
jobs:
10+
ubuntu-clang-modules:
11+
strategy:
12+
matrix:
13+
buildType: [Debug, Release]
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Update package list
17+
run: sudo apt update
18+
- name: Install Dependencies
19+
run: |
20+
sudo apt install -y git libssl-dev build-essential libcurl4-openssl-dev libpsl-dev meson libunistring-dev ninja-build wget
21+
# Install Clang 21+
22+
wget https://apt.llvm.org/llvm.sh
23+
chmod +x llvm.sh
24+
sudo ./llvm.sh 21
25+
sudo apt install -y libc++-21-dev libc++abi-21-dev
26+
env:
27+
DEBIAN_FRONTEND: noninteractive
28+
- name: Install CMake 3.28+
29+
run: |
30+
wget -O cmake.sh https://github.com/Kitware/CMake/releases/download/v3.28.3/cmake-3.28.3-linux-x86_64.sh
31+
sudo sh cmake.sh --prefix=/usr/local --skip-license
32+
cmake --version
33+
- name: Checkout
34+
uses: actions/checkout@v5
35+
- name: Configure
36+
run: |
37+
cmake -S . -B build \
38+
-DCMAKE_BUILD_TYPE=${{ matrix.buildType }} \
39+
-DCMAKE_CXX_COMPILER=clang++-21 \
40+
-DCMAKE_C_COMPILER=clang-21 \
41+
-DCPR_BUILD_MODULES=ON \
42+
-DCPR_BUILD_TESTS=ON \
43+
-DCPR_BUILD_TESTS_SSL=ON \
44+
-DCPR_FORCE_OPENSSL_BACKEND=ON \
45+
-DCPR_USE_SYSTEM_CURL=OFF \
46+
-G Ninja
47+
- name: Build
48+
run: cmake --build build --verbose
49+
- name: Test
50+
run: ctest --test-dir build --output-on-failure --repeat until-pass:5
51+
- name: Verify Module Build
52+
run: |
53+
echo "Contents of build/modules:"
54+
ls -la build/modules/
55+
if [ -f build/modules/libcpr_module.a ] || [ -f build/modules/libcpr_module.so ] || [ -f build/modules/cpr_module.a ] || find build/modules -name "*cpr_module*" -type f | grep -q .; then
56+
echo "Module library built successfully"
57+
else
58+
echo "Error: Module library not found"
59+
exit 1
60+
fi
61+
62+
fedora-gcc-modules:
63+
runs-on: ubuntu-latest
64+
container: "fedora:latest"
65+
steps:
66+
- name: Update package list
67+
run: dnf update -y
68+
- name: Install Dependencies
69+
run: dnf install -y gcc g++ git make openssl-devel libcurl-devel cmake libpsl-devel libunistring-devel meson ninja-build
70+
- name: Checkout
71+
uses: actions/checkout@v5
72+
- name: Configure
73+
run: |
74+
cmake -S . -B build \
75+
-DCMAKE_BUILD_TYPE=Release \
76+
-DCPR_BUILD_MODULES=ON \
77+
-DCPR_BUILD_TESTS=ON \
78+
-DCPR_BUILD_TESTS_SSL=ON \
79+
-DCPR_FORCE_OPENSSL_BACKEND=ON \
80+
-DCPR_USE_SYSTEM_CURL=OFF \
81+
-G Ninja
82+
- name: Build
83+
run: cmake --build build --verbose
84+
- name: Test
85+
run: ctest --test-dir build --output-on-failure --repeat until-pass:5
86+
- name: Verify Module Build
87+
run: |
88+
echo "Searching for module build artifacts:"
89+
find build -name "*cpr_module*" -type f || true
90+
find build -name "cpr.gcm" -type f || true
91+
# GCC stores the compiled module interface (BMI) as cpr.gcm rather than
92+
# a traditional archive when all sources are in FILE_SET CXX_MODULES.
93+
# Also check build/lib/ in case LIBRARY_OUTPUT_PATH redirected the archive.
94+
if find build \( -name "*cpr_module*" -o -name "cpr.gcm" \) -type f | grep -q .; then
95+
echo "Module build artifacts found successfully"
96+
else
97+
echo "Error: No module build artifacts found"
98+
exit 1
99+
fi
100+
101+
windows-msvc-modules:
102+
runs-on: windows-latest
103+
steps:
104+
- uses: actions/setup-python@v6
105+
- name: Install meson
106+
run: pip install meson
107+
- name: Setup MSVC environment
108+
uses: ilammy/msvc-dev-cmd@v1
109+
- name: Checkout
110+
uses: actions/checkout@v5
111+
- name: Install dependencies via vcpkg
112+
run: |
113+
vcpkg install curl zlib openssl --triplet x64-windows
114+
shell: pwsh
115+
- name: Configure
116+
run: |
117+
cmake -S . -B build `
118+
-DCMAKE_BUILD_TYPE=Release `
119+
-DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" `
120+
-DVCPKG_TARGET_TRIPLET=x64-windows `
121+
-DCPR_BUILD_MODULES=ON `
122+
-DCPR_BUILD_TESTS=ON `
123+
-DCPR_BUILD_TESTS_SSL=OFF `
124+
-DCPR_USE_SYSTEM_CURL=ON `
125+
-G "Visual Studio 17 2022"
126+
shell: pwsh
127+
- name: Build
128+
run: cmake --build build --config Release --verbose
129+
- name: Test
130+
run: ctest --test-dir build -C Release --output-on-failure --repeat until-pass:5
131+
- name: Verify Module Build
132+
run: |
133+
Write-Host "Contents of build/modules/Release:"
134+
Get-ChildItem -Path build/modules/Release -Force
135+
if (!(Test-Path "build/modules/Release/cpr_module.lib") -and !(Get-ChildItem -Path build/modules -Recurse -Filter "*cpr_module*")) {
136+
throw "Module library not found"
137+
}
138+
Write-Host "Module library built successfully"
139+
shell: pwsh
140+
141+
macos-clang-modules:
142+
runs-on: macos-latest
143+
steps:
144+
- name: Install Dependencies
145+
run: |
146+
brew install llvm libpsl ninja
147+
- name: Checkout
148+
uses: actions/checkout@v5
149+
- name: Configure
150+
run: |
151+
cmake -S . -B build \
152+
-DCMAKE_BUILD_TYPE=Release \
153+
-DCMAKE_CXX_COMPILER=$(brew --prefix llvm)/bin/clang++ \
154+
-DCMAKE_C_COMPILER=$(brew --prefix llvm)/bin/clang \
155+
-DCPR_BUILD_MODULES=ON \
156+
-DCPR_BUILD_TESTS=ON \
157+
-DCPR_BUILD_TESTS_SSL=OFF \
158+
-DCPR_USE_SYSTEM_LIB_PSL=ON \
159+
-G Ninja
160+
- name: Build
161+
run: cmake --build build --verbose
162+
- name: Test
163+
run: ctest --test-dir build --output-on-failure --repeat until-pass:5
164+
- name: Verify Module Build
165+
run: |
166+
echo "Contents of build/modules:"
167+
ls -la build/modules/
168+
if [ -f build/modules/libcpr_module.a ] || [ -f build/modules/libcpr_module.dylib ] || [ -f build/modules/cpr_module.a ] || find build/modules -name "*cpr_module*" -type f | grep -q .; then
169+
echo "Module library built successfully"
170+
else
171+
echo "Error: Module library not found"
172+
exit 1
173+
fi

modules/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
cmake_minimum_required(VERSION 3.28)
22

3+
# Apple Clang does not ship clang-scan-deps, which CMake requires for module
4+
# dependency scanning. Use LLVM clang (e.g. from Homebrew) instead.
5+
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
6+
message(FATAL_ERROR
7+
"Apple Clang does not support C++20 module dependency scanning.\n"
8+
"Use LLVM clang (e.g. 'brew install llvm') and pass "
9+
"-DCMAKE_CXX_COMPILER=$(brew --prefix llvm)/bin/clang++ to CMake.")
10+
endif()
11+
12+
# GCC gained module scanning support in version 14.
13+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
14+
CMAKE_CXX_COMPILER_VERSION VERSION_LESS "14")
15+
message(FATAL_ERROR
16+
"C++20 module scanning requires GCC 14 or later "
17+
"(found ${CMAKE_CXX_COMPILER_VERSION}).")
18+
endif()
19+
20+
set(CMAKE_CXX_SCAN_FOR_MODULES ON)
21+
322
add_library(cpr_module)
423

524
target_sources(cpr_module

0 commit comments

Comments
 (0)