Skip to content

Commit 99a7a4e

Browse files
优化模板项目结构,参考 cmdline 项目和 mcpp-style-ref 编码规范 (#1)
* 优化模板项目结构,参考 cmdline 项目和 mcpp-style-ref 编码规范 - 重构 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 <cursoragent@cursor.com> * 完善 CI 并新增 release 工作流。 补全多平台 CI 的触发、并发控制和 release 构建流程,新增手动发布并自动创建 GitHub Release 的工作流。 Co-authored-by: Cursor <cursoragent@cursor.com> * 修复工作流中的 xmake 非交互参数。 为 CI 和 release 的 xmake 配置、构建与测试命令统一增加 -y 和 -vv,避免依赖安装确认导致的流水线中断并保留详细日志。 Co-authored-by: Cursor <cursoragent@cursor.com> * 修复 macOS CI 构建失败并调整 xmake 命令。 macOS 仅构建库目标以避开 gtest 工具链冲突,修正 xmake run 参数顺序,并保持命令非交互与详细日志输出。 Co-authored-by: Cursor <cursoragent@cursor.com> * 修复 macOS xmake build 参数错误并提升命令兼容性。 移除错误的 build 目标参数写法,统一使用稳定构建命令;同时将 run 步骤改为兼容性更高的调用方式。 Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 199066e commit 99a7a4e

File tree

12 files changed

+670
-66
lines changed

12 files changed

+670
-66
lines changed

.github/workflows/ci.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: ci-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build-linux:
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 20
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Setup xmake
26+
uses: xmake-io/github-action-setup-xmake@v1
27+
with:
28+
xmake-version: latest
29+
package-cache: true
30+
31+
- name: Install dependencies
32+
run: |
33+
sudo apt-get update
34+
sudo apt-get install -y build-essential
35+
36+
- name: Install Xlings
37+
run: curl -fsSL https://d2learn.org/xlings-install.sh | bash
38+
39+
- name: Install GCC 15.1 with Xlings
40+
run: |
41+
export PATH=/home/xlings/.xlings_data/bin:$PATH
42+
xlings install gcc@15.1 -y
43+
44+
- name: Build
45+
run: |
46+
export PATH=/home/xlings/.xlings_data/bin:$PATH
47+
xmake f -m release -y -vv
48+
xmake -y -vv -j$(nproc)
49+
50+
- name: Test
51+
run: |
52+
export PATH=/home/xlings/.xlings_data/bin:$PATH
53+
xmake run templates_test
54+
55+
- name: Run examples
56+
run: |
57+
export PATH=/home/xlings/.xlings_data/bin:$PATH
58+
xmake run basic
59+
60+
build-macos:
61+
runs-on: macos-14
62+
timeout-minutes: 20
63+
steps:
64+
- name: Checkout
65+
uses: actions/checkout@v4
66+
67+
- name: Install dependencies
68+
run: brew install xmake llvm@20
69+
70+
- name: Build
71+
run: |
72+
export PATH=/opt/homebrew/opt/llvm@20/bin:$PATH
73+
xmake f --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -m release -y -vv
74+
xmake -y -vv -j$(sysctl -n hw.ncpu)
75+
76+
build-windows:
77+
runs-on: windows-latest
78+
timeout-minutes: 20
79+
steps:
80+
- name: Checkout
81+
uses: actions/checkout@v4
82+
83+
- name: Setup xmake
84+
uses: xmake-io/github-action-setup-xmake@v1
85+
with:
86+
xmake-version: latest
87+
package-cache: true
88+
89+
- name: Build
90+
run: |
91+
xmake f -m release -y -vv
92+
xmake -y -vv -j$env:NUMBER_OF_PROCESSORS
93+
94+
- name: Test
95+
run: xmake run templates_test
96+
97+
- name: Run examples
98+
run: xmake run basic

.github/workflows/release.yml

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "Release version (e.g., 0.1.1)"
8+
required: true
9+
type: string
10+
11+
jobs:
12+
build-linux:
13+
runs-on: ubuntu-latest
14+
timeout-minutes: 25
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Setup xmake
20+
uses: xmake-io/github-action-setup-xmake@v1
21+
with:
22+
xmake-version: latest
23+
24+
- name: Install dependencies
25+
run: |
26+
sudo apt-get update
27+
sudo apt-get install -y build-essential
28+
29+
- name: Install Xlings
30+
run: curl -fsSL https://d2learn.org/xlings-install.sh | bash
31+
32+
- name: Install GCC 15.1 with Xlings
33+
run: |
34+
export PATH=/home/xlings/.xlings_data/bin:$PATH
35+
xlings install gcc@15.1 -y
36+
37+
- name: Build with xmake
38+
run: |
39+
export PATH=/home/xlings/.xlings_data/bin:$PATH
40+
xmake f -m release -y -vv
41+
xmake -y -vv -j$(nproc)
42+
43+
- name: Run tests
44+
run: |
45+
export PATH=/home/xlings/.xlings_data/bin:$PATH
46+
xmake run templates_test
47+
48+
- name: Create release package
49+
run: |
50+
PKG="mcpplibs-templates-${{ inputs.version }}-linux-x86_64"
51+
mkdir -p "$PKG"
52+
cp build/linux/x86_64/release/libmcpplibs-templates.a "$PKG/"
53+
cp src/templates.cppm README.md LICENSE "$PKG/"
54+
tar -czf "${PKG}.tar.gz" "$PKG"
55+
56+
- name: Upload artifact
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: templates-linux-x86_64
60+
path: mcpplibs-templates-${{ inputs.version }}-linux-x86_64.tar.gz
61+
62+
build-macos:
63+
runs-on: macos-14
64+
timeout-minutes: 25
65+
steps:
66+
- name: Checkout
67+
uses: actions/checkout@v4
68+
69+
- name: Install dependencies
70+
run: brew install xmake llvm@20
71+
72+
- name: Build with xmake (LLVM 20)
73+
run: |
74+
export PATH=/opt/homebrew/opt/llvm@20/bin:$PATH
75+
xmake f -p macosx -m release --toolchain=llvm --sdk=/opt/homebrew/opt/llvm@20 -y -vv
76+
xmake -y -vv -j$(sysctl -n hw.ncpu)
77+
78+
- name: Create release package
79+
run: |
80+
PKG="mcpplibs-templates-${{ inputs.version }}-macosx-arm64"
81+
mkdir -p "$PKG"
82+
cp build/macosx/arm64/release/libmcpplibs-templates.a "$PKG/"
83+
cp src/templates.cppm README.md LICENSE "$PKG/"
84+
tar -czf "${PKG}.tar.gz" "$PKG"
85+
86+
- name: Upload artifact
87+
uses: actions/upload-artifact@v4
88+
with:
89+
name: templates-macosx-arm64
90+
path: mcpplibs-templates-${{ inputs.version }}-macosx-arm64.tar.gz
91+
92+
build-windows:
93+
runs-on: windows-latest
94+
timeout-minutes: 25
95+
steps:
96+
- name: Checkout
97+
uses: actions/checkout@v4
98+
99+
- name: Setup xmake
100+
uses: xmake-io/github-action-setup-xmake@v1
101+
with:
102+
xmake-version: latest
103+
104+
- name: Build with xmake
105+
run: |
106+
xmake f -m release -y -vv
107+
xmake -y -vv -j$env:NUMBER_OF_PROCESSORS
108+
109+
- name: Run tests
110+
run: xmake run templates_test
111+
112+
- name: Create release package
113+
shell: pwsh
114+
run: |
115+
$pkg = "mcpplibs-templates-${{ inputs.version }}-windows-x86_64"
116+
New-Item -ItemType Directory -Path $pkg -Force | Out-Null
117+
Copy-Item "build\windows\x64\release\mcpplibs-templates.lib" -Destination "$pkg\"
118+
Copy-Item "src\templates.cppm" -Destination "$pkg\"
119+
Copy-Item "README.md" -Destination "$pkg\"
120+
Copy-Item "LICENSE" -Destination "$pkg\"
121+
Compress-Archive -Path $pkg -DestinationPath "$pkg.zip"
122+
123+
- name: Upload artifact
124+
uses: actions/upload-artifact@v4
125+
with:
126+
name: templates-windows-x86_64
127+
path: mcpplibs-templates-${{ inputs.version }}-windows-x86_64.zip
128+
129+
create-release:
130+
needs: [build-linux, build-macos, build-windows]
131+
runs-on: ubuntu-latest
132+
permissions:
133+
contents: write
134+
steps:
135+
- name: Download all artifacts
136+
uses: actions/download-artifact@v4
137+
with:
138+
path: artifacts
139+
140+
- name: Create Release
141+
uses: softprops/action-gh-release@v1
142+
with:
143+
tag_name: v${{ inputs.version }}
144+
name: ${{ inputs.version }}
145+
draft: false
146+
prerelease: false
147+
files: |
148+
artifacts/templates-linux-x86_64/mcpplibs-templates-${{ inputs.version }}-linux-x86_64.tar.gz
149+
artifacts/templates-macosx-arm64/mcpplibs-templates-${{ inputs.version }}-macosx-arm64.tar.gz
150+
artifacts/templates-windows-x86_64/mcpplibs-templates-${{ inputs.version }}-windows-x86_64.zip
151+
env:
152+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,48 @@
1-
.xlings
1+
# xmake
22
.xmake
3-
build
3+
build
4+
5+
# xlings
6+
.xlings
7+
8+
# Compiled Object files
9+
*.slo
10+
*.lo
11+
*.o
12+
*.obj
13+
14+
# Precompiled Headers
15+
*.gch
16+
*.pch
17+
18+
# Linker files
19+
*.ilk
20+
21+
# Debugger Files
22+
*.pdb
23+
24+
# Compiled Dynamic libraries
25+
*.so
26+
*.dylib
27+
*.dll
28+
29+
# Compiled Static libraries
30+
*.lai
31+
*.la
32+
*.a
33+
*.lib
34+
35+
# Executables
36+
*.exe
37+
*.out
38+
*.app
39+
40+
# Debug information files
41+
*.dwo
42+
*.d
43+
44+
# CMake
45+
CMakeCache.txt
46+
CMakeFiles/
47+
cmake_install.cmake
48+
Makefile

CMakeLists.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,24 @@ set(CMAKE_CXX_MODULE_STD 1)
77

88
project(mcpplibs-templates VERSION 1.0.0 LANGUAGES CXX)
99

10-
# Library target
10+
# Library
1111
add_library(mcpplibs-templates STATIC)
1212

13+
file(GLOB_RECURSE MODULE_SOURCES "src/*.cppm")
14+
1315
target_sources(mcpplibs-templates
1416
PUBLIC
1517
FILE_SET CXX_MODULES FILES
16-
src/templates.cppm
18+
${MODULE_SOURCES}
1719
)
1820

19-
# Test executable
20-
add_executable(tests tests/main.cpp)
21-
target_link_libraries(tests PRIVATE mcpplibs-templates)
21+
# Test
22+
add_executable(templates_test tests/main.cpp)
23+
target_link_libraries(templates_test PRIVATE mcpplibs-templates)
2224

23-
# Enable testing
2425
enable_testing()
25-
add_test(NAME mcpplibs-templates-test COMMAND tests)
26+
add_test(NAME mcpplibs-templates-test COMMAND templates_test)
27+
28+
# Example
29+
add_executable(basic examples/basic.cpp)
30+
target_link_libraries(basic PRIVATE mcpplibs-templates)

0 commit comments

Comments
 (0)