Skip to content

Commit c49b046

Browse files
authored
Merge pull request #1 from mcpplibs/feat/mcpp-build-support
feat: add mcpp build support and switch Linux CI to mcpp
2 parents e5fe6e2 + 4c1dfe4 commit c49b046

6 files changed

Lines changed: 96 additions & 40 deletions

File tree

.github/workflows/ci.yml

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,72 @@ on:
66
pull_request:
77
branches: [main, master]
88

9+
concurrency:
10+
group: ci-${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
913
jobs:
1014
build-linux:
11-
runs-on: ubuntu-latest
15+
name: build + test (linux x86_64, mcpp)
16+
runs-on: ubuntu-24.04
17+
timeout-minutes: 30
18+
env:
19+
MCPP_HOME: /home/runner/.mcpp
1220
steps:
13-
- name: Checkout
14-
uses: actions/checkout@v4
21+
- uses: actions/checkout@v4
1522

16-
- name: Setup xmake
17-
uses: xmake-io/github-action-setup-xmake@v1
23+
# mcpp's sandbox (musl-gcc + ninja + binutils) is multi-hundred-MB;
24+
# key on mcpp.toml so toolchain changes refresh the cache.
25+
- name: Cache mcpp sandbox
26+
uses: actions/cache@v4
1827
with:
19-
xmake-version: latest
20-
package-cache: true
28+
path: ~/.mcpp
29+
key: mcpp-sandbox-${{ runner.os }}-${{ hashFiles('mcpp.toml') }}
30+
restore-keys: |
31+
mcpp-sandbox-${{ runner.os }}-
2132
22-
- name: Install dependencies
23-
run: |
24-
sudo apt-get update
25-
sudo apt-get install -y build-essential
26-
27-
- name: Install Xlings
28-
run: curl -fsSL https://d2learn.org/xlings-install.sh | bash
29-
30-
- name: Install GCC 15.1 with Xlings
33+
- name: Cache xlings
34+
uses: actions/cache@v4
35+
with:
36+
path: ~/.xlings
37+
key: xlings-${{ runner.os }}
38+
restore-keys: |
39+
xlings-${{ runner.os }}-
40+
41+
- name: Bootstrap mcpp via xlings
42+
env:
43+
XLINGS_NON_INTERACTIVE: '1'
3144
run: |
32-
export PATH=/home/xlings/.xlings_data/bin:$PATH
33-
xlings install gcc@15.1 -y
45+
if [ ! -x "$HOME/.xlings/subos/default/bin/xlings" ]; then
46+
curl -fsSL https://d2learn.org/xlings-install.sh | bash
47+
fi
48+
export PATH="$HOME/.xlings/subos/default/bin:$PATH"
49+
xlings --version
50+
xlings install mcpp -y
51+
mcpp --version
52+
echo "$HOME/.xlings/subos/default/bin" >> "$GITHUB_PATH"
53+
54+
- name: Cache target/ (build artifacts + BMIs)
55+
uses: actions/cache@v4
56+
with:
57+
path: target
58+
key: mcpp-target-${{ runner.os }}-${{ hashFiles('src/**', 'tests/**', 'mcpp.toml') }}
59+
restore-keys: |
60+
mcpp-target-${{ runner.os }}-
3461
3562
- name: Build
36-
run: |
37-
export PATH=/home/xlings/.xlings_data/bin:$PATH
38-
xmake -y -vv
63+
run: mcpp build
3964

4065
- name: Test
41-
run: |
42-
export PATH=/home/xlings/.xlings_data/bin:$PATH
43-
xmake run cmdline_test
44-
45-
- name: Run examples (smoke)
46-
run: |
47-
export PATH=/home/xlings/.xlings_data/bin:$PATH
48-
xmake run with_dispatch -- add python 3.12
49-
xmake run with_dispatch -- remove foo
66+
run: mcpp test
5067

68+
# mcpp is Linux-x86_64 first; macOS/Windows support is still WIP, so the
69+
# cross-platform xmake build keeps coverage for those targets.
5170
build-macos:
71+
name: build (macOS, xmake)
5272
runs-on: macos-latest
5373
steps:
54-
- name: Checkout
55-
uses: actions/checkout@v4
74+
- uses: actions/checkout@v4
5675

5776
- name: Setup xmake
5877
uses: xmake-io/github-action-setup-xmake@v1
@@ -69,10 +88,10 @@ jobs:
6988
xmake -y -vv
7089
7190
build-windows:
91+
name: build + test (Windows, xmake)
7292
runs-on: windows-latest
7393
steps:
74-
- name: Checkout
75-
uses: actions/checkout@v4
94+
- uses: actions/checkout@v4
7695

7796
- name: Setup xmake
7897
uses: xmake-io/github-action-setup-xmake@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.xmake
22
build
3+
target

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,21 @@ auto r3 = app.parse_from("myapp remove x --yes");
7676
7777
## 构建
7878
79+
**使用 xmake**
80+
7981
```shell
8082
xmake # 构建库
8183
xmake run basic # 运行基础示例
8284
xmake -y run cmdline_test # 运行测试(自动安装 gtest)
8385
```
8486

87+
**使用 mcpp**
88+
89+
```shell
90+
mcpp build # 构建库
91+
mcpp test # 运行 tests/ 下的测试
92+
```
93+
8594
## 集成到构建工具
8695

8796
### xmake
@@ -101,6 +110,17 @@ target("mytool")
101110
set_policy("build.c++.modules", true)
102111
```
103112

113+
### mcpp
114+
115+
在项目的 `mcpp.toml` 中声明依赖:
116+
117+
```toml
118+
[dependencies]
119+
"mcpplibs.cmdline" = "^0.0.2"
120+
```
121+
122+
然后在源码中 `import mcpplibs.cmdline;` 即可使用。
123+
104124
## 相关链接
105125

106126
- [社区官网](https://mcpp.d2learn.org)

mcpp.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "mcpplibs.cmdline"
3+
version = "0.0.2"
4+
description = "A simple command-line parsing library/framework for modern C++"
5+
license = "Apache-2.0"
6+
authors = ["mcpplibs"]
7+
repo = "https://github.com/mcpplibs/cmdline"
8+
9+
# Library target — exposes module `mcpplibs.cmdline` to dependents.
10+
# Sources default to src/**/*.{cppm,cpp,cc,c}; tests/ and examples/ are
11+
# discovered separately (`mcpp test` / standalone builds).
12+
[targets.cmdline]
13+
kind = "lib"
14+
15+
[dev-dependencies]
16+
gtest = "1.15.2"

tests/cmdline_test.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
import std;
44
import mcpplibs.cmdline;
55

6-
int main(int argc, char** argv) {
7-
::testing::InitGoogleTest(&argc, argv);
8-
return RUN_ALL_TESTS();
9-
}
10-
116
using namespace mcpplibs::cmdline;
127

138
// Build argv from program name + args for parse()

tests/xmake.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
add_rules("mode.debug", "mode.release")
22
set_languages("c++23")
33

4-
add_requires("gtest")
4+
add_requires("gtest", { configs = { main = true, gmock = false } })
55

66
target("cmdline_test")
77
set_kind("binary")
88
add_files("cmdline_test.cpp")
99
add_deps("cmdline")
1010
add_packages("gtest")
1111
set_policy("build.c++.modules", true)
12+
-- MSVC 不会从静态库扫描入口点,需要 /WHOLEARCHIVE 把 gtest_main.lib
13+
-- 强制整体链入,否则报 LNK1561: entry point must be defined。
14+
if is_plat("windows") then
15+
add_ldflags("/wholearchive:gtest_main.lib", { force = true })
16+
end

0 commit comments

Comments
 (0)