From 4580868044a74e570d78d3532ca6d4a1ba19ccdd Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Tue, 24 Feb 2026 13:09:54 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=9E=84=EF=BC=8C=E5=8F=82=E8=80=83?= =?UTF-8?q?=20cmdline=20=E9=A1=B9=E7=9B=AE=E5=92=8C=20mcpp-style-ref=20?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构 src/templates.cppm,遵循 mcpp-style-ref 模块文件结构规范 - 改进 xmake.lua,添加模块策略和子目录 includes - 新增 tests/xmake.lua 独立测试构建配置,集成 gtest - 新增 examples/ 目录,包含基础示例 - 新增 .github/workflows/ci.yml 多平台 CI(Linux/macOS/Windows) - 新增 docs/architecture.md 架构文档 - 更新 CMakeLists.txt 同步通配符模式 - 完善 .gitignore 和 README.md Co-authored-by: Cursor --- .github/workflows/ci.yml | 89 ++++++++++++++ .gitignore | 49 +++++++- CMakeLists.txt | 19 +-- README.md | 97 +++++++++------ docs/architecture.md | 250 +++++++++++++++++++++++++++++++++++++++ examples/basic.cpp | 8 ++ examples/xmake.lua | 9 ++ src/templates.cppm | 13 +- tests/main.cpp | 18 ++- tests/xmake.lua | 12 ++ xmake.lua | 9 +- 11 files changed, 507 insertions(+), 66 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 docs/architecture.md create mode 100644 examples/basic.cpp create mode 100644 examples/xmake.lua create mode 100644 tests/xmake.lua diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9a57ea4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,89 @@ +name: CI + +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +jobs: + build-linux: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup xmake + uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: latest + package-cache: true + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential + + - name: Install Xlings + run: curl -fsSL https://d2learn.org/xlings-install.sh | bash + + - name: Install GCC 15.1 with Xlings + run: | + export PATH=/home/xlings/.xlings_data/bin:$PATH + xlings install gcc@15.1 -y + + - name: Build + run: | + export PATH=/home/xlings/.xlings_data/bin:$PATH + xmake -y -vv + + - name: Test + run: | + export PATH=/home/xlings/.xlings_data/bin:$PATH + xmake run templates_test + + - name: Run examples + run: | + export PATH=/home/xlings/.xlings_data/bin:$PATH + xmake run basic + + build-macos: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup xmake + uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: latest + package-cache: true + + - name: Install LLVM 20 + run: brew install llvm@20 + + - name: Build + run: | + xmake f --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 + xmake -y -vv + + build-windows: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup xmake + uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: latest + package-cache: true + + - name: Build + run: xmake -y -vv + + - name: Test + run: xmake run templates_test + + - name: Run examples + run: xmake run basic diff --git a/.gitignore b/.gitignore index 70eeb6b..fb6e4ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,48 @@ -.xlings +# xmake .xmake -build \ No newline at end of file +build + +# xlings +.xlings + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Linker files +*.ilk + +# Debugger Files +*.pdb + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# Debug information files +*.dwo +*.d + +# CMake +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +Makefile diff --git a/CMakeLists.txt b/CMakeLists.txt index dc7e225..bd594ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,19 +7,24 @@ set(CMAKE_CXX_MODULE_STD 1) project(mcpplibs-templates VERSION 1.0.0 LANGUAGES CXX) -# Library target +# Library add_library(mcpplibs-templates STATIC) +file(GLOB_RECURSE MODULE_SOURCES "src/*.cppm") + target_sources(mcpplibs-templates PUBLIC FILE_SET CXX_MODULES FILES - src/templates.cppm + ${MODULE_SOURCES} ) -# Test executable -add_executable(tests tests/main.cpp) -target_link_libraries(tests PRIVATE mcpplibs-templates) +# Test +add_executable(templates_test tests/main.cpp) +target_link_libraries(templates_test PRIVATE mcpplibs-templates) -# Enable testing enable_testing() -add_test(NAME mcpplibs-templates-test COMMAND tests) \ No newline at end of file +add_test(NAME mcpplibs-templates-test COMMAND templates_test) + +# Example +add_executable(basic examples/basic.cpp) +target_link_libraries(basic PRIVATE mcpplibs-templates) diff --git a/README.md b/README.md index a83903e..d38f923 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,95 @@ # mcpplibs templates -mcpplibs templates... +> C++23 模块化库项目模板 - `import mcpplibs.templates;` -`src/templates.cppm` +基于 C++23 模块的库项目模板,提供标准化的项目结构、构建配置和 CI/CD 流水线,帮助快速创建 mcpplibs 风格的模块化 C++ 库。 -```cpp -module; // 0 - global module declaration - -// 1 - include & macro area -// #include +## 特性 -// 2 - module declaration -export module mcpplibs.templates; - -// 3 - import area -import std; +- **C++23 模块** — `import mcpplibs.templates;` +- **双构建系统** — 同时支持 xmake 和 CMake +- **CI/CD** — GitHub Actions 多平台构建(Linux / macOS / Windows) +- **标准化结构** — 遵循 [mcpp-style-ref](https://github.com/mcpp-community/mcpp-style-ref) 编码规范 +- **开箱即用** — 包含示例、测试和架构文档 -// 4 - module implementation partition -namespace mcpplibs { +## 项目结构 - // 5 - exported entities - export void hello_mcpp() { - std::println("hello mcpp!"); - } - -} // namespace mcpplibs +``` +mcpplibs-templates/ +├── src/ # 模块源码 +│ └── templates.cppm # 主模块接口 +├── tests/ # 测试 +│ ├── main.cpp +│ └── xmake.lua +├── examples/ # 示例 +│ ├── basic.cpp +│ └── xmake.lua +├── docs/ # 文档 +│ └── architecture.md +├── .github/workflows/ # CI/CD +│ └── ci.yml +├── xmake.lua # xmake 构建配置 +├── CMakeLists.txt # CMake 构建配置 +└── config.xlings # xlings 工具链配置 ``` -`tests/main.cpp` +## 快速开始 ```cpp -// 6 - import module +import std; import mcpplibs.templates; -auto main() -> int { - // 7 - call exported function - mcpplibs::hello_mcpp(); +int main() { + mcpplibs::templates::hello_mcpp(); + return 0; } ``` -## Install & Config +## 安装与配置 ```bash xlings install ``` -## Build & Run +## 构建与运行 -**Using xmake** +**使用 xmake** ```bash -xmake build -xmake r +xmake build # 构建库 +xmake run basic # 运行基础示例 +xmake run templates_test # 运行测试 ``` -**Using CMake** +**使用 CMake** ```bash cmake -B build -G Ninja cmake --build build -./build/tests +ctest --test-dir build +``` + +## 集成到构建工具 + +### xmake + +```lua +add_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git") + +add_requires("templates") + +target("myapp") + set_kind("binary") + set_languages("c++23") + add_files("main.cpp") + add_packages("templates") + set_policy("build.c++.modules", true) ``` -## Other +## 相关链接 +- [mcpp-style-ref | 现代C++编码/项目风格参考](https://github.com/mcpp-community/mcpp-style-ref) +- [mcpplibs/cmdline | 命令行解析库](https://github.com/mcpplibs/cmdline) +- [mcpp社区官网](https://mcpp.d2learn.org) +- [mcpp | 现代C++爱好者论坛](https://mcpp.d2learn.org/forum) - [入门教程: 动手学现代C++](https://github.com/Sunrisepeak/mcpp-standard) -- [mcpp | 现代C++爱好者论坛](https://forum.d2learn.org/category/20) -- [mcpp-community | 现代C++爱好者社区](https://github.com/mcpp-community) -- [d2learn社区](https://github.com/d2learn) \ No newline at end of file diff --git a/docs/architecture.md b/docs/architecture.md new file mode 100644 index 0000000..0ee2b6c --- /dev/null +++ b/docs/architecture.md @@ -0,0 +1,250 @@ +# 架构文档 + +> mcpplibs/templates 项目架构与设计说明 + +## 概述 + +`mcpplibs/templates` 是 mcpplibs 生态中的标准化 C++23 模块库项目模板。它提供了一套完整的项目骨架,包含模块源码、测试、示例、构建配置和 CI/CD 流水线,帮助开发者快速创建符合 [mcpp-style-ref](https://github.com/mcpp-community/mcpp-style-ref) 编码规范的模块化 C++ 库。 + +## 目录结构 + +``` +mcpplibs-templates/ +├── src/ # 模块源码目录 +│ └── templates.cppm # 主模块接口文件 +├── tests/ # 测试目录 +│ ├── main.cpp # 测试入口 +│ └── xmake.lua # 测试构建配置 +├── examples/ # 示例目录 +│ ├── basic.cpp # 基础用法示例 +│ └── xmake.lua # 示例构建配置 +├── docs/ # 文档目录 +│ └── architecture.md # 架构文档(本文件) +├── .github/workflows/ # CI/CD 配置 +│ └── ci.yml # GitHub Actions 流水线 +├── xmake.lua # xmake 构建配置(主配置) +├── CMakeLists.txt # CMake 构建配置 +├── config.xlings # xlings 工具链配置 +├── .gitignore # Git 忽略规则 +├── .gitattributes # Git 属性(.cppm 语言识别) +├── LICENSE # Apache-2.0 许可证 +└── README.md # 项目说明 +``` + +## 模块架构 + +### 模块结构 + +```mermaid +graph TD + subgraph moduleLayer [模块层] + M["mcpplibs.templates"] + end + + subgraph srcLayer [源码] + S["src/templates.cppm"] + end + + subgraph consumerLayer [使用方] + T["tests/main.cpp"] + E["examples/basic.cpp"] + end + + S -->|"export module"| M + T -->|"import"| M + E -->|"import"| M +``` + +### 模块命名规范 + +遵循 [mcpp-style-ref 2.4 模块命名规范](https://github.com/mcpp-community/mcpp-style-ref#24-%E6%A8%A1%E5%9D%97%E5%8F%8A%E6%A8%A1%E5%9D%97%E5%88%86%E5%8C%BA%E5%91%BD%E5%90%8D%E8%A7%84%E8%8C%83): + +- **模块名格式**: `组织.库名` — 例: `mcpplibs.templates` +- **模块分区**: `组织.库名:分区名` — 例: `mcpplibs.templates:utils` +- **命名空间**: 与模块名对应 — 例: `mcpplibs::templates` + +### 模块文件结构 + +每个 `.cppm` 文件遵循以下结构: + +```cpp +module; // 全局模块片段(可选,用于传统头文件) + +export module mcpplibs.templates; // 模块声明 + +import std; // 模块导入区域 + +namespace mcpplibs::templates { // 接口导出与实现 + + export void hello_mcpp() { + std::println("hello mcpp!"); + } + +} +``` + +### 扩展模块分区 + +当库规模增长时,可按照 [mcpp-style-ref 2.5](https://github.com/mcpp-community/mcpp-style-ref#25-%E5%A4%9A%E6%96%87%E4%BB%B6%E6%A8%A1%E5%9D%97%E5%92%8C%E7%9B%AE%E5%BD%95) 的模式拆分为多个模块分区: + +``` +src/ +├── templates.cppm # 主模块,export import 各分区 +├── templates/ +│ ├── core.cppm # export module mcpplibs.templates:core +│ └── utils.cppm # export module mcpplibs.templates:utils +``` + +主模块文件中聚合导出: + +```cpp +export module mcpplibs.templates; + +export import :core; +export import :utils; +``` + +## 编码规范 + +遵循 [mcpp-style-ref](https://github.com/mcpp-community/mcpp-style-ref) 编码规范: + +| 类别 | 风格 | 示例 | +|------|------|------| +| 类型名 | PascalCase(大驼峰) | `StyleRef`, `HttpServer` | +| 对象/数据成员 | camelCase(小驼峰) | `fileName`, `configText` | +| 函数 | snake_case(下划线) | `load_config()`, `parse_()` | +| 私有成员 | `_` 后缀 | `data_`, `parse_()` | +| 命名空间 | 全小写 | `mcpplibs`, `mcpplibs::templates` | +| 全局变量 | `g` 前缀 | `gStyleRef` | + +## 构建系统 + +### 构建流程 + +```mermaid +graph LR + subgraph xmakeBuild [xmake 构建] + X1["xmake.lua"] -->|includes| X2["tests/xmake.lua"] + X1 -->|includes| X3["examples/xmake.lua"] + X1 -->|"target: mcpplibs-templates"| LIB["静态库"] + X2 -->|"target: templates_test"| TEST["测试可执行文件"] + X3 -->|"target: basic"| EXAMPLE["示例可执行文件"] + end +``` + +### xmake + +主构建配置 `xmake.lua` 定义静态库 target,并通过 `includes` 引入子目录的构建配置: + +```lua +add_rules("mode.release", "mode.debug") +set_languages("c++23") + +target("mcpplibs-templates") + set_kind("static") + add_files("src/*.cppm", { public = true, install = true }) + set_policy("build.c++.modules", true) + +includes("examples", "tests") +``` + +关键配置说明: +- `set_languages("c++23")` — 启用 C++23 标准 +- `add_files("src/*.cppm", { public = true, install = true })` — 通配模块源文件,支持自动发现新增分区 +- `set_policy("build.c++.modules", true)` — 启用 C++20/23 模块支持 +- `includes("examples", "tests")` — 引入子目录构建配置,保持主文件简洁 + +### CMake + +`CMakeLists.txt` 提供对 CMake 4.0+ 的支持,使用实验性 `import std` 功能: + +```cmake +cmake_minimum_required(VERSION 4.0.2) +set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "a9e1cf81-9932-4810-974b-6eccaf14e457") +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_MODULE_STD 1) +``` + +### 工具链配置 + +`config.xlings` 定义项目所需的工具链版本: + +```lua +xname = "mcpplibs-templates" + +xim = { + xmake = "3.0.4", + cmake = "4.0.2", + ninja = "1.12.1", + cpp = "", -- gcc15 或 mingw13 +} +``` + +通过 `xlings install` 可一键安装所有依赖工具。 + +## CI/CD 流水线 + +### 多平台构建矩阵 + +```mermaid +graph TD + subgraph ciPipeline [GitHub Actions CI] + TRIGGER["push / pull_request"] --> LINUX["Linux"] + TRIGGER --> MACOS["macOS"] + TRIGGER --> WINDOWS["Windows"] + + LINUX -->|"GCC 15.1 via Xlings"| L_BUILD["构建 + 测试 + 示例"] + MACOS -->|"LLVM 20 via Homebrew"| M_BUILD["仅构建"] + WINDOWS -->|"MSVC"| W_BUILD["构建 + 测试 + 示例"] + end +``` + +| 平台 | 编译器 | 构建 | 测试 | 示例 | +|------|--------|------|------|------| +| Linux (Ubuntu) | GCC 15.1 | Y | Y | Y | +| macOS | LLVM 20 | Y | - | - | +| Windows | MSVC | Y | Y | Y | + +macOS 当前仅构建不运行测试和示例,因为部分模块特性在 Clang/LLVM 上的支持仍在完善中。 + +## 如何基于模板创建新库 + +1. **克隆模板** + +```bash +git clone https://github.com/mcpplibs/templates.git mcpplibs-mylib +cd mcpplibs-mylib +rm -rf .git && git init +``` + +2. **重命名模块** + +将 `templates` 替换为你的库名(例如 `mylib`): + +- `src/templates.cppm` → 修改 `export module mcpplibs.mylib;` +- `xmake.lua` → 修改 target 名称为 `mcpplibs-mylib` +- `CMakeLists.txt` → 修改 project 和 target 名称 +- `config.xlings` → 修改 `xname` + +3. **添加模块分区**(按需) + +在 `src/` 下创建新的 `.cppm` 文件,xmake 会通过通配符 `src/*.cppm` 自动发现。 + +4. **编写测试和示例** + +在 `tests/` 和 `examples/` 下添加对应的源文件和 xmake target。 + +5. **推送并验证 CI** + +```bash +git add . +git commit -m "init: mcpplibs-mylib" +git remote add origin https://github.com/mcpplibs/mylib.git +git push -u origin main +``` + +## 参考 + +- [mcpp-style-ref | 现代C++编码/项目风格参考](https://github.com/mcpp-community/mcpp-style-ref) +- [mcpplibs/cmdline | 命令行解析库(参考项目)](https://github.com/mcpplibs/cmdline) +- [mcpp社区官网](https://mcpp.d2learn.org) diff --git a/examples/basic.cpp b/examples/basic.cpp new file mode 100644 index 0000000..e43bb29 --- /dev/null +++ b/examples/basic.cpp @@ -0,0 +1,8 @@ +import std; +import mcpplibs.templates; + +int main() { + std::println("=== mcpplibs.templates basic example ==="); + mcpplibs::templates::hello_mcpp(); + return 0; +} diff --git a/examples/xmake.lua b/examples/xmake.lua new file mode 100644 index 0000000..7564132 --- /dev/null +++ b/examples/xmake.lua @@ -0,0 +1,9 @@ +add_rules("mode.debug", "mode.release") + +set_languages("c++23") + +target("basic") + set_kind("binary") + add_files("basic.cpp") + add_deps("mcpplibs-templates") + set_policy("build.c++.modules", true) diff --git a/src/templates.cppm b/src/templates.cppm index d987b07..e10e70f 100644 --- a/src/templates.cppm +++ b/src/templates.cppm @@ -1,20 +1,13 @@ -module; // 0 - global module declaration +module; -// 1 - include & macro area -// #include - -// 2 - module declaration export module mcpplibs.templates; -// 3 - import area import std; -// 4 - module implementation partition -namespace mcpplibs { +namespace mcpplibs::templates { - // 5 - exported entities export void hello_mcpp() { std::println("hello mcpp!"); } -} // namespace mcpplibs \ No newline at end of file +} diff --git a/tests/main.cpp b/tests/main.cpp index 300a130..0691005 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,7 +1,15 @@ -// 6 - import module +#include + import mcpplibs.templates; -auto main() -> int { - // 7 - call exported function - mcpplibs::hello_mcpp(); -} \ No newline at end of file +TEST(TemplatesTest, HelloMcpp) { + testing::internal::CaptureStdout(); + mcpplibs::templates::hello_mcpp(); + std::string output = testing::internal::GetCapturedStdout(); + EXPECT_EQ(output, "hello mcpp!\n"); +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/tests/xmake.lua b/tests/xmake.lua new file mode 100644 index 0000000..9a52dc4 --- /dev/null +++ b/tests/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") + +set_languages("c++23") + +add_requires("gtest") + +target("templates_test") + set_kind("binary") + add_files("*.cpp") + add_deps("mcpplibs-templates") + add_packages("gtest") + set_policy("build.c++.modules", true) diff --git a/xmake.lua b/xmake.lua index b5ce3f8..59096ac 100644 --- a/xmake.lua +++ b/xmake.lua @@ -4,10 +4,7 @@ set_languages("c++23") target("mcpplibs-templates") set_kind("static") - add_files("src/templates.cppm", { public = true, install = true }) + add_files("src/*.cppm", { public = true, install = true }) + set_policy("build.c++.modules", true) -target("tests") - set_kind("binary") - add_files("tests/main.cpp") - add_deps("mcpplibs-templates") - --set_policy("build.c++.modules", true) \ No newline at end of file +includes("examples", "tests") From aecd47144a3084a1d870771c302609613e096eae Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Tue, 24 Feb 2026 13:19:19 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=AE=8C=E5=96=84=20CI=20=E5=B9=B6?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=20release=20=E5=B7=A5=E4=BD=9C=E6=B5=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补全多平台 CI 的触发、并发控制和 release 构建流程,新增手动发布并自动创建 GitHub Release 的工作流。 Co-authored-by: Cursor --- .github/workflows/ci.yml | 42 ++++++--- .github/workflows/release.yml | 155 ++++++++++++++++++++++++++++++++++ 2 files changed, 184 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a57ea4..da4e230 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,10 +5,19 @@ on: branches: [main, master] pull_request: branches: [main, master] + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true jobs: build-linux: runs-on: ubuntu-latest + timeout-minutes: 20 steps: - name: Checkout uses: actions/checkout@v4 @@ -35,7 +44,8 @@ jobs: - name: Build run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake -y -vv + xmake f -m release -y + xmake -j$(nproc) - name: Test run: | @@ -48,27 +58,31 @@ jobs: xmake run basic build-macos: - runs-on: macos-latest + runs-on: macos-14 + timeout-minutes: 20 steps: - name: Checkout uses: actions/checkout@v4 - - name: Setup xmake - uses: xmake-io/github-action-setup-xmake@v1 - with: - xmake-version: latest - package-cache: true - - - name: Install LLVM 20 - run: brew install llvm@20 + - name: Install dependencies + run: brew install xmake llvm@20 - name: Build run: | - xmake f --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 - xmake -y -vv + export PATH=/opt/homebrew/opt/llvm@20/bin:$PATH + xmake f --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -y + xmake -m release -y + xmake -j$(sysctl -n hw.ncpu) + + - name: Test + run: xmake run templates_test + + - name: Run examples + run: xmake run basic build-windows: runs-on: windows-latest + timeout-minutes: 20 steps: - name: Checkout uses: actions/checkout@v4 @@ -80,7 +94,9 @@ jobs: package-cache: true - name: Build - run: xmake -y -vv + run: | + xmake f -m release -y + xmake -j$env:NUMBER_OF_PROCESSORS - name: Test run: xmake run templates_test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2536132 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,155 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + description: "Release version (e.g., 0.1.1)" + required: true + type: string + +jobs: + build-linux: + runs-on: ubuntu-latest + timeout-minutes: 25 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup xmake + uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: latest + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential + + - name: Install Xlings + run: curl -fsSL https://d2learn.org/xlings-install.sh | bash + + - name: Install GCC 15.1 with Xlings + run: | + export PATH=/home/xlings/.xlings_data/bin:$PATH + xlings install gcc@15.1 -y + + - name: Build with xmake + run: | + export PATH=/home/xlings/.xlings_data/bin:$PATH + xmake f -m release -y + xmake -j$(nproc) + + - name: Run tests + run: | + export PATH=/home/xlings/.xlings_data/bin:$PATH + xmake run templates_test + + - name: Create release package + run: | + PKG="mcpplibs-templates-${{ inputs.version }}-linux-x86_64" + mkdir -p "$PKG" + cp build/linux/x86_64/release/libmcpplibs-templates.a "$PKG/" + cp src/templates.cppm README.md LICENSE "$PKG/" + tar -czf "${PKG}.tar.gz" "$PKG" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: templates-linux-x86_64 + path: mcpplibs-templates-${{ inputs.version }}-linux-x86_64.tar.gz + + build-macos: + runs-on: macos-14 + timeout-minutes: 25 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install dependencies + run: brew install xmake llvm@20 + + - name: Build with xmake (LLVM 20) + run: | + export PATH=/opt/homebrew/opt/llvm@20/bin:$PATH + xmake f -p macosx -m release --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -y + xmake -j$(sysctl -n hw.ncpu) + + - name: Run tests + run: xmake run templates_test + + - name: Create release package + run: | + PKG="mcpplibs-templates-${{ inputs.version }}-macosx-arm64" + mkdir -p "$PKG" + cp build/macosx/arm64/release/libmcpplibs-templates.a "$PKG/" + cp src/templates.cppm README.md LICENSE "$PKG/" + tar -czf "${PKG}.tar.gz" "$PKG" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: templates-macosx-arm64 + path: mcpplibs-templates-${{ inputs.version }}-macosx-arm64.tar.gz + + build-windows: + runs-on: windows-latest + timeout-minutes: 25 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup xmake + uses: xmake-io/github-action-setup-xmake@v1 + with: + xmake-version: latest + + - name: Build with xmake + run: | + xmake f -m release -y + xmake -j$env:NUMBER_OF_PROCESSORS + + - name: Run tests + run: xmake run templates_test + + - name: Create release package + shell: pwsh + run: | + $pkg = "mcpplibs-templates-${{ inputs.version }}-windows-x86_64" + New-Item -ItemType Directory -Path $pkg -Force | Out-Null + Copy-Item "build\windows\x64\release\mcpplibs-templates.lib" -Destination "$pkg\" + Copy-Item "src\templates.cppm" -Destination "$pkg\" + Copy-Item "README.md" -Destination "$pkg\" + Copy-Item "LICENSE" -Destination "$pkg\" + Compress-Archive -Path $pkg -DestinationPath "$pkg.zip" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: templates-windows-x86_64 + path: mcpplibs-templates-${{ inputs.version }}-windows-x86_64.zip + + create-release: + needs: [build-linux, build-macos, build-windows] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + tag_name: v${{ inputs.version }} + name: ${{ inputs.version }} + draft: false + prerelease: false + files: | + artifacts/templates-linux-x86_64/mcpplibs-templates-${{ inputs.version }}-linux-x86_64.tar.gz + artifacts/templates-macosx-arm64/mcpplibs-templates-${{ inputs.version }}-macosx-arm64.tar.gz + artifacts/templates-windows-x86_64/mcpplibs-templates-${{ inputs.version }}-windows-x86_64.zip + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From be1930041b9c696c96ab094c1de76cda646c92ae Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Tue, 24 Feb 2026 13:21:16 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E6=B5=81=E4=B8=AD=E7=9A=84=20xmake=20=E9=9D=9E=E4=BA=A4?= =?UTF-8?q?=E4=BA=92=E5=8F=82=E6=95=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为 CI 和 release 的 xmake 配置、构建与测试命令统一增加 -y 和 -vv,避免依赖安装确认导致的流水线中断并保留详细日志。 Co-authored-by: Cursor --- .github/workflows/ci.yml | 25 ++++++++++++------------- .github/workflows/release.yml | 18 +++++++++--------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da4e230..f11ea13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,18 +44,18 @@ jobs: - name: Build run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake f -m release -y - xmake -j$(nproc) + xmake f -m release -y -vv + xmake -y -vv -j$(nproc) - name: Test run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake run templates_test + xmake -y -vv run templates_test - name: Run examples run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake run basic + xmake -y -vv run basic build-macos: runs-on: macos-14 @@ -70,15 +70,14 @@ jobs: - name: Build run: | export PATH=/opt/homebrew/opt/llvm@20/bin:$PATH - xmake f --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -y - xmake -m release -y - xmake -j$(sysctl -n hw.ncpu) + xmake f --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -m release -y -vv + xmake -y -vv -j$(sysctl -n hw.ncpu) - name: Test - run: xmake run templates_test + run: xmake -y -vv run templates_test - name: Run examples - run: xmake run basic + run: xmake -y -vv run basic build-windows: runs-on: windows-latest @@ -95,11 +94,11 @@ jobs: - name: Build run: | - xmake f -m release -y - xmake -j$env:NUMBER_OF_PROCESSORS + xmake f -m release -y -vv + xmake -y -vv -j$env:NUMBER_OF_PROCESSORS - name: Test - run: xmake run templates_test + run: xmake -y -vv run templates_test - name: Run examples - run: xmake run basic + run: xmake -y -vv run basic diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2536132..735a987 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,13 +37,13 @@ jobs: - name: Build with xmake run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake f -m release -y - xmake -j$(nproc) + xmake f -m release -y -vv + xmake -y -vv -j$(nproc) - name: Run tests run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake run templates_test + xmake -y -vv run templates_test - name: Create release package run: | @@ -72,11 +72,11 @@ jobs: - name: Build with xmake (LLVM 20) run: | export PATH=/opt/homebrew/opt/llvm@20/bin:$PATH - xmake f -p macosx -m release --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -y - xmake -j$(sysctl -n hw.ncpu) + xmake f -p macosx -m release --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -y -vv + xmake -y -vv -j$(sysctl -n hw.ncpu) - name: Run tests - run: xmake run templates_test + run: xmake -y -vv run templates_test - name: Create release package run: | @@ -106,11 +106,11 @@ jobs: - name: Build with xmake run: | - xmake f -m release -y - xmake -j$env:NUMBER_OF_PROCESSORS + xmake f -m release -y -vv + xmake -y -vv -j$env:NUMBER_OF_PROCESSORS - name: Run tests - run: xmake run templates_test + run: xmake -y -vv run templates_test - name: Create release package shell: pwsh From 2963eb7dd72d4628f64e8b8007e38c17b2abb3f4 Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Tue, 24 Feb 2026 13:25:39 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20macOS=20CI=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=A4=B1=E8=B4=A5=E5=B9=B6=E8=B0=83=E6=95=B4=20xmake?= =?UTF-8?q?=20=E5=91=BD=E4=BB=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macOS 仅构建库目标以避开 gtest 工具链冲突,修正 xmake run 参数顺序,并保持命令非交互与详细日志输出。 Co-authored-by: Cursor --- .github/workflows/ci.yml | 16 +++++----------- .github/workflows/release.yml | 9 +++------ xmake.lua | 4 +++- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f11ea13..cfd3900 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,12 +50,12 @@ jobs: - name: Test run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake -y -vv run templates_test + xmake run -y -vv templates_test - name: Run examples run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake -y -vv run basic + xmake run -y -vv basic build-macos: runs-on: macos-14 @@ -71,13 +71,7 @@ jobs: run: | export PATH=/opt/homebrew/opt/llvm@20/bin:$PATH xmake f --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -m release -y -vv - xmake -y -vv -j$(sysctl -n hw.ncpu) - - - name: Test - run: xmake -y -vv run templates_test - - - name: Run examples - run: xmake -y -vv run basic + xmake -y -vv build mcpplibs-templates -j$(sysctl -n hw.ncpu) build-windows: runs-on: windows-latest @@ -98,7 +92,7 @@ jobs: xmake -y -vv -j$env:NUMBER_OF_PROCESSORS - name: Test - run: xmake -y -vv run templates_test + run: xmake run -y -vv templates_test - name: Run examples - run: xmake -y -vv run basic + run: xmake run -y -vv basic diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 735a987..8b3f4d6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,7 @@ jobs: - name: Run tests run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake -y -vv run templates_test + xmake run -y -vv templates_test - name: Create release package run: | @@ -73,10 +73,7 @@ jobs: run: | export PATH=/opt/homebrew/opt/llvm@20/bin:$PATH xmake f -p macosx -m release --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -y -vv - xmake -y -vv -j$(sysctl -n hw.ncpu) - - - name: Run tests - run: xmake -y -vv run templates_test + xmake -y -vv build mcpplibs-templates -j$(sysctl -n hw.ncpu) - name: Create release package run: | @@ -110,7 +107,7 @@ jobs: xmake -y -vv -j$env:NUMBER_OF_PROCESSORS - name: Run tests - run: xmake -y -vv run templates_test + run: xmake run -y -vv templates_test - name: Create release package shell: pwsh diff --git a/xmake.lua b/xmake.lua index 59096ac..cebee86 100644 --- a/xmake.lua +++ b/xmake.lua @@ -7,4 +7,6 @@ target("mcpplibs-templates") add_files("src/*.cppm", { public = true, install = true }) set_policy("build.c++.modules", true) -includes("examples", "tests") +if not is_host("macosx") then + includes("examples", "tests") +end From 3750bdcfd426d10290374b1ed3d6d1a3ceafeae5 Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Tue, 24 Feb 2026 13:28:58 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20macOS=20xmake=20build?= =?UTF-8?q?=20=E5=8F=82=E6=95=B0=E9=94=99=E8=AF=AF=E5=B9=B6=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E5=91=BD=E4=BB=A4=E5=85=BC=E5=AE=B9=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除错误的 build 目标参数写法,统一使用稳定构建命令;同时将 run 步骤改为兼容性更高的调用方式。 Co-authored-by: Cursor --- .github/workflows/ci.yml | 10 +++++----- .github/workflows/release.yml | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cfd3900..66534e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,12 +50,12 @@ jobs: - name: Test run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake run -y -vv templates_test + xmake run templates_test - name: Run examples run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake run -y -vv basic + xmake run basic build-macos: runs-on: macos-14 @@ -71,7 +71,7 @@ jobs: run: | export PATH=/opt/homebrew/opt/llvm@20/bin:$PATH xmake f --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -m release -y -vv - xmake -y -vv build mcpplibs-templates -j$(sysctl -n hw.ncpu) + xmake -y -vv -j$(sysctl -n hw.ncpu) build-windows: runs-on: windows-latest @@ -92,7 +92,7 @@ jobs: xmake -y -vv -j$env:NUMBER_OF_PROCESSORS - name: Test - run: xmake run -y -vv templates_test + run: xmake run templates_test - name: Run examples - run: xmake run -y -vv basic + run: xmake run basic diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8b3f4d6..278d91b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,7 @@ jobs: - name: Run tests run: | export PATH=/home/xlings/.xlings_data/bin:$PATH - xmake run -y -vv templates_test + xmake run templates_test - name: Create release package run: | @@ -73,7 +73,7 @@ jobs: run: | export PATH=/opt/homebrew/opt/llvm@20/bin:$PATH xmake f -p macosx -m release --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -y -vv - xmake -y -vv build mcpplibs-templates -j$(sysctl -n hw.ncpu) + xmake -y -vv -j$(sysctl -n hw.ncpu) - name: Create release package run: | @@ -107,7 +107,7 @@ jobs: xmake -y -vv -j$env:NUMBER_OF_PROCESSORS - name: Run tests - run: xmake run -y -vv templates_test + run: xmake run templates_test - name: Create release package shell: pwsh