Skip to content

Commit a8a83e9

Browse files
Katze719Mqxx
andauthored
Experiment/cpp26 reflection ffi (#20)
* feat(ffi): add C++26 reflection FFI metadata layer and Deno bindgen * feat: add mingw toolchain and preset * feat: implement ABI registry and status code management for serial operations * feat: enhance status code management and introduce new status code descriptors * feat: add strict warning options for GCC and enhance FFI metadata with new ABI function registry and status code descriptors * refactor(cpp-core): remove StatusCodes aliases and tighten header layout * refactor: simplify serial function parameters and improve type definitions * feat: add error callback support and enhance TypeScript wrapper generation * refactor: update README for clarity and structure, enhancing API contract description * feat: add CI workflow for build and testing, and update Doxygen configuration * fix: update CI workflow to use Ubuntu 24.04 and ensure GCC 16 installation * fix: update static assert for reflection implementation version * feat: make glue code more genereic * chore: rename workflow and compile test files * chore: update checkout actions to v6 * remove: codegen * feat: implement GCC reflection support and enhance SerialConfig validation * feat: add GitHub Actions workflow for compile checks * feat: add support for optional FFI AST export with clang++ * feat: add slim JSON output for FFI API metadata and update CMake configuration * refactor: remove GCC version checks from CMakeLists.txt * refactor: standardize JSON key naming in FFI API metadata * docs: update README to reflect current FFI generation workflow with clang++ * Update .github/workflows/compile_checks.yml Co-authored-by: Mqx <62719703+Mqxx@users.noreply.github.com> * Update .github/workflows/doxygen.yml Co-authored-by: Mqx <62719703+Mqxx@users.noreply.github.com> * Update .github/workflows/doxygen.yml Co-authored-by: Mqx <62719703+Mqxx@users.noreply.github.com> * Update .github/workflows/doxygen.yml Co-authored-by: Mqx <62719703+Mqxx@users.noreply.github.com> * refactor: update CI workflows and improve test coverage for reflection and result modules --------- Co-authored-by: Mqx <62719703+Mqxx@users.noreply.github.com>
1 parent 06f1351 commit a8a83e9

58 files changed

Lines changed: 1264 additions & 191 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: 'Compile Checks'
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
compile_checks:
12+
name: 'Compile checks'
13+
runs-on: ubuntu-24.04
14+
15+
steps:
16+
- name: 'Checkout repository'
17+
uses: actions/checkout@v6
18+
19+
- name: 'Install GCC 16.1 toolchain'
20+
run: |
21+
sudo apt-get update -qq
22+
sudo apt-get install -y software-properties-common
23+
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
24+
sudo apt-get update -qq
25+
sudo apt-get install -y gcc-16 g++-16 ninja-build cmake
26+
27+
- name: 'Show toolchain versions'
28+
run: |
29+
cmake --version
30+
ninja --version
31+
gcc-16 --version
32+
g++-16 --version
33+
34+
- name: 'Configure CMAKE'
35+
run: |
36+
cmake -S . -B build/ci -G Ninja \
37+
-DCMAKE_BUILD_TYPE=Debug \
38+
-DCMAKE_C_COMPILER=gcc-16 \
39+
-DCMAKE_CXX_COMPILER=g++-16
40+
41+
- name: 'Build compile checks'
42+
run: |
43+
cmake --build build/ci --target cpp_core_compile_tests
44+
45+
- name: 'Run CTest if registered tests exist'
46+
run: |
47+
ctest --test-dir build/ci --output-on-failure --no-tests=ignore

.github/workflows/doxygen.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,48 @@ on:
66
paths:
77
- 'include/**'
88
- 'Doxyfile'
9+
- 'README.md'
10+
- 'LICENSE'
911
- '.github/workflows/doxygen.yml'
1012
workflow_dispatch:
1113

1214
# Required for GitHub Pages deployment
1315
permissions:
14-
contents: write
15-
pages: write
16-
id-token: write
16+
contents: read
17+
pages: write
18+
id-token: write
1719

1820
jobs:
1921
build-docs:
20-
runs-on: ubuntu-latest
22+
runs-on: ubuntu-24.04
2123
name: 'Build Doxygen HTML'
2224
steps:
23-
- name: Checkout
24-
uses: actions/checkout@v3
25+
- name: 'Checkout repository'
26+
uses: actions/checkout@v6
2527

26-
- name: Install Doxygen + Graphviz
28+
- name: 'Install Doxygen + Graphviz'
2729
run: |
2830
sudo apt-get update -qq
2931
sudo apt-get install -y doxygen graphviz
3032
31-
- name: Generate documentation
33+
- name: 'Generate documentation'
3234
run: |
3335
doxygen -v
3436
doxygen Doxyfile
3537
36-
- name: Upload Pages artifact
37-
uses: actions/upload-pages-artifact@v3
38+
- name: 'Upload Pages artifact'
39+
uses: actions/upload-pages-artifact@v5
3840
with:
3941
path: docs/html
4042

4143
deploy:
4244
needs: build-docs
43-
runs-on: ubuntu-latest
45+
runs-on: ubuntu-24.04
4446
name: 'Deploy to GitHub Pages'
47+
environment:
48+
name: github-pages
49+
url: ${{ steps.deployment.outputs.page_url }}
4550
steps:
46-
- name: Deploy
51+
- name: 'Deploy'
4752
id: deployment
48-
uses: actions/deploy-pages@v4
53+
uses: actions/deploy-pages@v5

CMakeLists.txt

Lines changed: 142 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@ cmake_minimum_required(VERSION 3.30)
33
# Export compile commands to root directory
44
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
55

6+
project(cpp-core LANGUAGES CXX)
7+
8+
set(CMAKE_CXX_STANDARD 26)
9+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
set(CMAKE_CXX_EXTENSIONS OFF)
11+
set(CMAKE_CXX_MODULE_STD 26)
12+
set(CMAKE_CXX_MODULE_EXTENSIONS OFF)
13+
14+
option(CPP_CORE_ENABLE_AST_EXPORT "Enable clang-based JSON AST export for the FFI headers" ON)
15+
set(
16+
CPP_CORE_AST_JSON_OUTPUT
17+
"${CMAKE_BINARY_DIR}/ast/cpp_core_ffi_ast.json"
18+
CACHE FILEPATH
19+
"Output path for the generated FFI AST JSON file"
20+
)
21+
set(
22+
CPP_CORE_AST_CLANGXX
23+
""
24+
CACHE FILEPATH
25+
"Path to the clang++ executable used for AST JSON export"
26+
)
27+
set(
28+
CPP_CORE_AST_SLIM_JSON_OUTPUT
29+
"${CMAKE_BINARY_DIR}/ast/cpp_core_ffi_api.json"
30+
CACHE FILEPATH
31+
"Output path for the reduced FFI API JSON metadata"
32+
)
33+
634
include(cmake/CPM.cmake)
735

836
CPMAddPackage(
@@ -18,17 +46,28 @@ include(${cmake-git-versioning_SOURCE_DIR}/cmake/cmake-git-versioning.cmake)
1846
get_git_version_info()
1947
generate_git_version(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core)
2048

21-
project(
22-
cpp-core
23-
VERSION "${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}.${GIT_VERSION_PATCH}"
24-
DESCRIPTION "Cross-platform helper library shared by cpp-linux-bindings and cpp-windows-bindings"
25-
LANGUAGES CXX
26-
)
49+
set(PROJECT_VERSION "${GIT_VERSION_MAJOR}.${GIT_VERSION_MINOR}.${GIT_VERSION_PATCH}")
50+
set(PROJECT_DESCRIPTION "Cross-platform helper library shared by cpp-linux-bindings and cpp-windows-bindings")
2751

2852
# Header-only library --------------------------------------------------------
2953
add_library(cpp_core INTERFACE)
3054
add_library(cpp_core::cpp_core ALIAS cpp_core)
3155

56+
add_library(cpp_core_strict_warnings INTERFACE)
57+
58+
target_compile_options(
59+
cpp_core_strict_warnings
60+
INTERFACE
61+
-Wall
62+
-Wextra
63+
-Wpedantic
64+
-Wconversion
65+
-Wsign-conversion
66+
-Wshadow
67+
-Wundef
68+
-Werror
69+
)
70+
3271
# Public include directories
3372
target_include_directories(
3473
cpp_core
@@ -37,23 +76,100 @@ target_include_directories(
3776
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
3877
)
3978

40-
# Set C++ standard
41-
set(CMAKE_CXX_STANDARD 23)
42-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
43-
set(CMAKE_CXX_EXTENSIONS OFF)
44-
45-
# Require C++23
46-
target_compile_features(cpp_core INTERFACE cxx_std_23)
79+
target_compile_options(cpp_core INTERFACE -freflection)
4780

48-
# Enable C++23 module support
49-
set(CMAKE_CXX_MODULE_STD 23)
50-
set(CMAKE_CXX_MODULE_EXTENSIONS OFF)
81+
target_compile_features(cpp_core INTERFACE cxx_std_26)
5182

5283
include(CTest)
5384

5485
if(BUILD_TESTING)
55-
add_library(cpp_core_status_code_compile_test OBJECT tests/status_code_compile_test.cpp)
56-
target_link_libraries(cpp_core_status_code_compile_test PRIVATE cpp_core::cpp_core)
86+
file(
87+
GLOB_RECURSE CPP_CORE_COMPILE_TEST_SOURCES
88+
CONFIGURE_DEPENDS
89+
"${CMAKE_CURRENT_SOURCE_DIR}/include/*.test.cpp"
90+
)
91+
add_library(cpp_core_compile_tests OBJECT ${CPP_CORE_COMPILE_TEST_SOURCES})
92+
target_link_libraries(cpp_core_compile_tests PRIVATE cpp_core::cpp_core)
93+
target_link_libraries(cpp_core_compile_tests PRIVATE cpp_core_strict_warnings)
94+
endif()
95+
96+
if(CPP_CORE_ENABLE_AST_EXPORT)
97+
find_package(Python3 COMPONENTS Interpreter REQUIRED)
98+
99+
file(
100+
GLOB _cpp_core_ast_interface_headers
101+
CONFIGURE_DEPENDS
102+
"${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/interface/*.h"
103+
)
104+
105+
set(
106+
_cpp_core_ast_headers
107+
"${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/serial.h"
108+
"${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/error_callback.h"
109+
"${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/module_api.h"
110+
"${CMAKE_CURRENT_SOURCE_DIR}/include/cpp_core/version.hpp"
111+
${_cpp_core_ast_interface_headers}
112+
)
113+
114+
if(CPP_CORE_AST_CLANGXX)
115+
set(_cpp_core_ast_clangxx "${CPP_CORE_AST_CLANGXX}")
116+
else()
117+
find_program(_cpp_core_ast_clangxx NAMES clang++)
118+
endif()
119+
120+
if(NOT _cpp_core_ast_clangxx)
121+
message(
122+
FATAL_ERROR
123+
"CPP_CORE_ENABLE_AST_EXPORT=ON requires clang++. "
124+
"Install clang++ or set CPP_CORE_AST_CLANGXX to an explicit path."
125+
)
126+
endif()
127+
128+
set(_cpp_core_ast_wrapper "${CMAKE_CURRENT_BINARY_DIR}/ast/cpp_core_ffi_ast.cpp")
129+
get_filename_component(_cpp_core_ast_json_dir "${CPP_CORE_AST_JSON_OUTPUT}" DIRECTORY)
130+
get_filename_component(_cpp_core_ast_slim_json_dir "${CPP_CORE_AST_SLIM_JSON_OUTPUT}" DIRECTORY)
131+
132+
file(
133+
GENERATE
134+
OUTPUT "${_cpp_core_ast_wrapper}"
135+
CONTENT "#include <cpp_core/serial.h>\n"
136+
)
137+
138+
add_custom_command(
139+
OUTPUT "${CPP_CORE_AST_JSON_OUTPUT}"
140+
COMMAND ${CMAKE_COMMAND} -E make_directory "${_cpp_core_ast_json_dir}"
141+
COMMAND
142+
${CMAKE_COMMAND}
143+
-DCPP_CORE_AST_CLANGXX=${_cpp_core_ast_clangxx}
144+
-DCPP_CORE_AST_INCLUDE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/include
145+
-DCPP_CORE_AST_OUTPUT=${CPP_CORE_AST_JSON_OUTPUT}
146+
-DCPP_CORE_AST_SOURCE=${_cpp_core_ast_wrapper}
147+
-DCPP_CORE_AST_STANDARD=${CMAKE_CXX_STANDARD}
148+
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/export_ast_json.cmake
149+
DEPENDS "${_cpp_core_ast_wrapper}" ${_cpp_core_ast_headers}
150+
COMMENT "Exporting FFI header AST JSON with clang++"
151+
VERBATIM
152+
)
153+
154+
add_custom_command(
155+
OUTPUT "${CPP_CORE_AST_SLIM_JSON_OUTPUT}"
156+
COMMAND ${CMAKE_COMMAND} -E make_directory "${_cpp_core_ast_slim_json_dir}"
157+
COMMAND
158+
"${Python3_EXECUTABLE}"
159+
"${CMAKE_CURRENT_SOURCE_DIR}/tools/clang_ast_to_ffi_json.py"
160+
--input "${CPP_CORE_AST_JSON_OUTPUT}"
161+
--output "${CPP_CORE_AST_SLIM_JSON_OUTPUT}"
162+
--source-root "${CMAKE_CURRENT_SOURCE_DIR}"
163+
--public-header "cpp_core/serial.h"
164+
DEPENDS
165+
"${CPP_CORE_AST_JSON_OUTPUT}"
166+
"${CMAKE_CURRENT_SOURCE_DIR}/tools/clang_ast_to_ffi_json.py"
167+
COMMENT "Reducing clang AST JSON to compact FFI API metadata"
168+
VERBATIM
169+
)
170+
171+
add_custom_target(cpp_core_ast_raw_json DEPENDS "${CPP_CORE_AST_JSON_OUTPUT}")
172+
add_custom_target(cpp_core_ast_slim_json DEPENDS "${CPP_CORE_AST_SLIM_JSON_OUTPUT}")
57173
endif()
58174

59175
# Install rules --------------------------------------------------------------
@@ -69,6 +185,14 @@ install(
69185
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
70186
)
71187

188+
if(CPP_CORE_ENABLE_AST_EXPORT)
189+
install(
190+
FILES "${CPP_CORE_AST_SLIM_JSON_OUTPUT}"
191+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cpp_core
192+
OPTIONAL
193+
)
194+
endif()
195+
72196
# CMake package configuration ------------------------------------------------
73197
include(CMakePackageConfigHelpers)
74198

CMakePresets.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939
"value": "x64",
4040
"strategy": "external"
4141
}
42+
},
43+
{
44+
"name": "mingw",
45+
"displayName": "MinGW-w64 (cross)",
46+
"description": "Cross-compile for Windows using MinGW-w64",
47+
"generator": "Ninja",
48+
"binaryDir": "${sourceDir}/build/mingw",
49+
"toolchainFile": "${sourceDir}/cmake/mingw-toolchain.cmake",
50+
"cacheVariables": {
51+
"CMAKE_BUILD_TYPE": "Debug"
52+
}
4253
}
4354
],
4455
"buildPresets": [
@@ -77,6 +88,18 @@
7788
"displayName": "MSVC Release",
7889
"configurePreset": "msvc",
7990
"configuration": "Release"
91+
},
92+
{
93+
"name": "mingw-debug",
94+
"displayName": "MinGW Debug",
95+
"configurePreset": "mingw",
96+
"configuration": "Debug"
97+
},
98+
{
99+
"name": "mingw-release",
100+
"displayName": "MinGW Release",
101+
"configurePreset": "mingw",
102+
"configuration": "Release"
80103
}
81104
]
82105
}

Doxyfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
PROJECT_NAME = "cpp-core"
77
PROJECT_BRIEF = "Header-only C++ helper library"
88
PROJECT_NUMBER = "1.0"
9-
OUTPUT_DIRECTORY = docs/html
9+
OUTPUT_DIRECTORY = docs
1010
CREATE_SUBDIRS = NO
1111

1212
# Build options ----------------------------------------------------------
@@ -22,7 +22,7 @@ RECURSIVE = YES
2222

2323
# HTML output ------------------------------------------------------------
2424
GENERATE_HTML = YES
25-
HTML_OUTPUT = .
25+
HTML_OUTPUT = html
2626
HTML_COLORSTYLE_HUE = 220
2727
HTML_COLORSTYLE_SAT = 100
2828
HTML_COLORSTYLE_GAMMA = 80

0 commit comments

Comments
 (0)