Skip to content

Commit c1f55a1

Browse files
committed
feat: add C++20 module support and update CMake configuration for NekoLog
1 parent 7e2b233 commit c1f55a1

File tree

8 files changed

+178
-80
lines changed

8 files changed

+178
-80
lines changed

.github/workflows/ci.yml

Lines changed: 68 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,22 @@ jobs:
1717
config:
1818
# Windows builds
1919
- {
20-
name: "Windows MSVC Debug",
20+
name: "Windows MSVC Module Debug",
2121
os: windows-latest,
2222
cc: "cl",
2323
cxx: "cl",
2424
build_type: "Debug",
25-
generators: "Visual Studio 17 2022"
25+
generators: "Visual Studio 17 2022",
26+
enable_module: "ON"
2627
}
2728
- {
28-
name: "Windows MSVC Release",
29+
name: "Windows MSVC Module Release",
2930
os: windows-latest,
3031
cc: "cl",
3132
cxx: "cl",
3233
build_type: "Release",
33-
generators: "Visual Studio 17 2022"
34-
}
35-
- {
36-
name: "Windows Clang Debug",
37-
os: windows-latest,
38-
cc: "clang",
39-
cxx: "clang++",
40-
build_type: "Debug",
41-
generators: "Visual Studio 17 2022"
42-
}
43-
- {
44-
name: "Windows Clang Release",
45-
os: windows-latest,
46-
cc: "clang",
47-
cxx: "clang++",
48-
build_type: "Release",
49-
generators: "Visual Studio 17 2022"
34+
generators: "Visual Studio 17 2022",
35+
enable_module: "ON"
5036
}
5137

5238
# Linux builds
@@ -56,31 +42,53 @@ jobs:
5642
cc: "gcc",
5743
cxx: "g++",
5844
build_type: "Debug",
59-
generators: "Unix Makefiles"
45+
generators: "Unix Makefiles",
46+
enable_module: "OFF"
6047
}
6148
- {
6249
name: "Ubuntu GCC Release",
6350
os: ubuntu-latest,
6451
cc: "gcc",
6552
cxx: "g++",
6653
build_type: "Release",
67-
generators: "Unix Makefiles"
54+
generators: "Unix Makefiles",
55+
enable_module: "OFF"
6856
}
6957
- {
7058
name: "Ubuntu Clang Debug",
7159
os: ubuntu-latest,
7260
cc: "clang",
7361
cxx: "clang++",
7462
build_type: "Debug",
75-
generators: "Unix Makefiles"
63+
generators: "Unix Makefiles",
64+
enable_module: "OFF"
7665
}
7766
- {
7867
name: "Ubuntu Clang Release",
7968
os: ubuntu-latest,
8069
cc: "clang",
8170
cxx: "clang++",
8271
build_type: "Release",
83-
generators: "Unix Makefiles"
72+
generators: "Unix Makefiles",
73+
enable_module: "OFF"
74+
}
75+
- {
76+
name: "Ubuntu Clang-18 Module Debug",
77+
os: ubuntu-latest,
78+
cc: "clang-18",
79+
cxx: "clang++-18",
80+
build_type: "Debug",
81+
generators: "Ninja",
82+
enable_module: "ON"
83+
}
84+
- {
85+
name: "Ubuntu Clang-21 Module Release",
86+
os: ubuntu-latest,
87+
cc: "clang-21",
88+
cxx: "clang++-21",
89+
build_type: "Release",
90+
generators: "Ninja",
91+
enable_module: "ON"
8492
}
8593

8694
# macOS builds
@@ -90,34 +98,37 @@ jobs:
9098
cc: "clang",
9199
cxx: "clang++",
92100
build_type: "Debug",
93-
generators: "Unix Makefiles"
101+
generators: "Unix Makefiles",
102+
enable_module: "OFF"
94103
}
95104
- {
96105
name: "macOS Clang Release",
97106
os: macos-latest,
98107
cc: "clang",
99108
cxx: "clang++",
100109
build_type: "Release",
101-
generators: "Unix Makefiles"
110+
generators: "Unix Makefiles",
111+
enable_module: "OFF"
102112
}
103113
- {
104114
name: "macOS GCC Debug",
105115
os: macos-latest,
106116
cc: "gcc",
107117
cxx: "g++",
108118
build_type: "Debug",
109-
generators: "Unix Makefiles"
119+
generators: "Unix Makefiles",
120+
enable_module: "OFF"
110121
}
111122
- {
112123
name: "macOS GCC Release",
113124
os: macos-latest,
114125
cc: "gcc",
115126
cxx: "g++",
116127
build_type: "Release",
117-
generators: "Unix Makefiles"
128+
generators: "Unix Makefiles",
129+
enable_module: "OFF"
118130
}
119131

120-
121132
steps:
122133
- name: Checkout
123134
uses: actions/checkout@v4
@@ -148,13 +159,21 @@ jobs:
148159
g++ --version
149160
fi
150161
151-
- name: Check compiler versions
152-
if: startsWith(matrix.config.os, 'ubuntu')
162+
- name: Install Clang 18 (Ubuntu)
163+
if: startsWith(matrix.config.os, 'ubuntu') && matrix.config.cc == 'clang-18'
153164
run: |
154-
echo "=== Compiler Information ==="
155-
${{ matrix.config.cxx }} --version
156-
echo "=== CMake Information ==="
157-
cmake --version
165+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
166+
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main"
167+
sudo apt-get update
168+
sudo apt-get install -y clang-18 clang++-18
169+
170+
- name: Install Clang 21 (Ubuntu)
171+
if: startsWith(matrix.config.os, 'ubuntu') && matrix.config.cc == 'clang-21'
172+
run: |
173+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
174+
sudo add-apt-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-21 main"
175+
sudo apt-get update
176+
sudo apt-get install -y clang-21 clang++-21
158177
159178
- name: Install dependencies (macOS)
160179
if: startsWith(matrix.config.os, 'macos')
@@ -169,19 +188,31 @@ jobs:
169188
# Setup Clang
170189
choco install llvm
171190
}
191+
- name: Check compiler versions (Unix)
192+
if: "!startsWith(matrix.config.os, 'windows')"
193+
run: |
194+
echo "=== Compiler Information ==="
195+
${{ matrix.config.cxx }} --version
196+
echo "=== CMake Information ==="
197+
cmake --version
198+
echo "=== Ninja Information ==="
199+
ninja --version
172200
173201
- name: Set up MSVC environment (Windows)
174202
if: startsWith(matrix.config.os, 'windows') && matrix.config.cc == 'cl'
175203
uses: ilammy/msvc-dev-cmd@v1.13.0
176204

177205
- name: Configure CMake
178206
run: |
207+
echo "=== Configuring NekoFunction (Ubuntu) ==="
208+
echo "Compiler: ${{ matrix.config.cxx }}"
209+
echo "Module support: ${{ matrix.config.enable_module }}"
179210
if [[ "${{ matrix.config.generators }}" == *"Visual Studio"* ]]; then
180211
# For Visual Studio generators, let CMake auto-detect the compiler
181-
cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -G "${{ matrix.config.generators }}" -DNEKO_LOG_BUILD_TESTS=ON -DNEKO_LOG_AUTO_FETCH_DEPS=ON
212+
cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -G "${{ matrix.config.generators }}" -DNEKO_LOG_BUILD_TESTS=ON -DNEKO_LOG_AUTO_FETCH_DEPS=ON -DNEKO_LOG_ENABLE_MODULE=${{ matrix.config.enable_module }}
182213
else
183214
# For other generators, specify the compiler explicitly
184-
cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -G "${{ matrix.config.generators }}" -DNEKO_LOG_BUILD_TESTS=ON -DNEKO_LOG_AUTO_FETCH_DEPS=ON
215+
cmake -B build -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DCMAKE_C_COMPILER=${{ matrix.config.cc }} -DCMAKE_CXX_COMPILER=${{ matrix.config.cxx }} -G "${{ matrix.config.generators }}" -DNEKO_LOG_BUILD_TESTS=ON -DNEKO_LOG_AUTO_FETCH_DEPS=ON -DNEKO_LOG_ENABLE_MODULE=${{ matrix.config.enable_module }}
185216
fi
186217
shell: bash
187218

CMakeLists.txt

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.14)
2-
project(NekoLog VERSION 1.0.5 LANGUAGES CXX)
2+
project(NekoLog VERSION 1.0.6 LANGUAGES CXX)
33

44
# ================
55
# === Config ====
@@ -99,15 +99,6 @@ if(NEKO_LOG_ENABLE_MODULE)
9999

100100
target_link_libraries(NekoLog_module PUBLIC Neko::Schema::Module)
101101
target_compile_features(NekoLog_module PUBLIC cxx_std_20)
102-
103-
# Compiler-specific module flags
104-
if(MSVC)
105-
target_compile_options(NekoLog_module PUBLIC /experimental:module)
106-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
107-
target_compile_options(NekoLog_module PUBLIC -fmodules-ts)
108-
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
109-
target_compile_options(NekoLog_module PUBLIC -fmodules)
110-
endif()
111102

112103
target_include_directories(NekoLog_module PUBLIC
113104
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@@ -139,11 +130,17 @@ if(NEKO_LOG_BUILD_TESTS)
139130
gtest_discover_tests(nlog_test)
140131

141132
# Module test (if modules are enabled)
142-
if(NEKO_LOG_ENABLE_MODULES)
143-
add_executable(nlog_module_test tests/nlog_module_test.cpp)
144-
target_link_libraries(nlog_module_test PRIVATE NekoLog_module GTest::gtest GTest::gtest_main)
145-
target_compile_features(nlog_module_test PRIVATE cxx_std_20)
146-
gtest_discover_tests(nlog_module_test)
133+
if(NEKO_LOG_ENABLE_MODULE)
134+
if (MSVC)
135+
message(STATUS "NekoLog module tests enabled (MSVC only)")
136+
137+
add_executable(nlog_module_test tests/nlog_module_test.cpp)
138+
target_link_libraries(nlog_module_test PRIVATE NekoLog_module GTest::gtest GTest::gtest_main)
139+
target_compile_features(nlog_module_test PRIVATE cxx_std_20)
140+
gtest_discover_tests(nlog_module_test)
141+
else()
142+
message(STATUS "Skipping NekoLog module tests on non-MSVC toolchains")
143+
endif()
147144
endif()
148145

149146
else()

cmake/NekoLogConfig.cmake.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ find_dependency(NekoSchema REQUIRED)
77
# Include the targets file
88
include("${CMAKE_CURRENT_LIST_DIR}/NekoLogTargets.cmake")
99

10-
# Recreate the Neko::Log alias for consumers
10+
# Recreate alias for consumers
1111
if(TARGET NekoLog AND NOT TARGET Neko::Log)
1212
add_library(Neko::Log ALIAS NekoLog)
1313
endif()
14+
if (TARGET NekoLog_module AND NOT TARGET Neko::Log::Module)
15+
add_library(Neko::Log::Module ALIAS NekoLog_module)
16+
endif()
1417

1518
check_required_components(NekoLog)

examples/example_module.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
* cmake --build build
88
*/
99

10-
// Use C++20 module instead of header
11-
import neko.log;
12-
1310
#include <thread>
1411
#include <chrono>
1512

13+
// Use C++20 module instead of header
14+
import neko.log;
15+
1616
int main() {
1717
using namespace neko;
1818

include/neko/log/neko.log.cppm

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
/**
2-
* @file neko.log.cppm
3-
* @brief C++20 module interface for NekoLog
4-
* @details This module exports all NekoLog functionality by wrapping the header files.
5-
* The original headers are still available for traditional include-based usage.
6-
*/
1+
// =====================
2+
// === Global Module ===
3+
// =====================
74

85
module;
96

10-
#if defined(__cpp_lib_modules) && (__cpp_lib_modules >= 202207L)
11-
import std;
12-
#else
13-
// Global module fragment - include headers that should not be exported
7+
// ====================
8+
// = Standard Library =
9+
// ====================
10+
1411
#include <format>
1512

1613
#include <chrono>
@@ -32,12 +29,15 @@ import std;
3229
#include <queue>
3330
#include <unordered_map>
3431
#include <vector>
35-
#endif
3632

37-
import neko.schema;
33+
// =====================
34+
// = Module Interface ==
35+
// =====================
3836

3937
export module neko.log;
4038

39+
import neko.schema;
40+
4141
// Control header files to not import dependencies (dependencies are declared and imported by the cppm)
4242
#define NEKO_LOG_ENABLE_MODULE true
4343

include/neko/log/nlog.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#error "Neko logging Cannot find header <format>"
2020
#endif
2121

22+
#include <version>
2223
#include <format>
2324

2425
#if !defined(__cpp_lib_format) || __cpp_lib_format < 201907L

0 commit comments

Comments
 (0)