Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 53 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,72 @@ on:
pull_request:
branches: [main, master]

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-linux:
runs-on: ubuntu-latest
name: build + test (linux x86_64, mcpp)
runs-on: ubuntu-24.04
timeout-minutes: 30
env:
MCPP_HOME: /home/runner/.mcpp
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Setup xmake
uses: xmake-io/github-action-setup-xmake@v1
# mcpp's sandbox (musl-gcc + ninja + binutils) is multi-hundred-MB;
# key on mcpp.toml so toolchain changes refresh the cache.
- name: Cache mcpp sandbox
uses: actions/cache@v4
with:
xmake-version: latest
package-cache: true
path: ~/.mcpp
key: mcpp-sandbox-${{ runner.os }}-${{ hashFiles('mcpp.toml') }}
restore-keys: |
mcpp-sandbox-${{ runner.os }}-

- 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
- name: Cache xlings
uses: actions/cache@v4
with:
path: ~/.xlings
key: xlings-${{ runner.os }}
restore-keys: |
xlings-${{ runner.os }}-

- name: Bootstrap mcpp via xlings
env:
XLINGS_NON_INTERACTIVE: '1'
run: |
export PATH=/home/xlings/.xlings_data/bin:$PATH
xlings install gcc@15.1 -y
if [ ! -x "$HOME/.xlings/subos/default/bin/xlings" ]; then
curl -fsSL https://d2learn.org/xlings-install.sh | bash
fi
export PATH="$HOME/.xlings/subos/default/bin:$PATH"
xlings --version
xlings install mcpp -y
mcpp --version
echo "$HOME/.xlings/subos/default/bin" >> "$GITHUB_PATH"

- name: Cache target/ (build artifacts + BMIs)
uses: actions/cache@v4
with:
path: target
key: mcpp-target-${{ runner.os }}-${{ hashFiles('src/**', 'tests/**', 'mcpp.toml') }}
restore-keys: |
mcpp-target-${{ runner.os }}-

- name: Build
run: |
export PATH=/home/xlings/.xlings_data/bin:$PATH
xmake -y -vv
run: mcpp build

- name: Test
run: |
export PATH=/home/xlings/.xlings_data/bin:$PATH
xmake run cmdline_test

- name: Run examples (smoke)
run: |
export PATH=/home/xlings/.xlings_data/bin:$PATH
xmake run with_dispatch -- add python 3.12
xmake run with_dispatch -- remove foo
run: mcpp test

# mcpp is Linux-x86_64 first; macOS/Windows support is still WIP, so the
# cross-platform xmake build keeps coverage for those targets.
build-macos:
name: build (macOS, xmake)
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Setup xmake
uses: xmake-io/github-action-setup-xmake@v1
Expand All @@ -69,10 +88,10 @@ jobs:
xmake -y -vv

build-windows:
name: build + test (Windows, xmake)
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Setup xmake
uses: xmake-io/github-action-setup-xmake@v1
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.xmake
build
target
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,21 @@ auto r3 = app.parse_from("myapp remove x --yes");

## 构建

**使用 xmake**

```shell
xmake # 构建库
xmake run basic # 运行基础示例
xmake -y run cmdline_test # 运行测试(自动安装 gtest)
```

**使用 mcpp**

```shell
mcpp build # 构建库
mcpp test # 运行 tests/ 下的测试
```

## 集成到构建工具

### xmake
Expand All @@ -101,6 +110,17 @@ target("mytool")
set_policy("build.c++.modules", true)
```

### mcpp

在项目的 `mcpp.toml` 中声明依赖:

```toml
[dependencies]
"mcpplibs.cmdline" = "^0.0.2"
```

然后在源码中 `import mcpplibs.cmdline;` 即可使用。

## 相关链接

- [社区官网](https://mcpp.d2learn.org)
Expand Down
16 changes: 16 additions & 0 deletions mcpp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "mcpplibs.cmdline"
version = "0.0.2"
description = "A simple command-line parsing library/framework for modern C++"
license = "Apache-2.0"
authors = ["mcpplibs"]
repo = "https://github.com/mcpplibs/cmdline"

# Library target — exposes module `mcpplibs.cmdline` to dependents.
# Sources default to src/**/*.{cppm,cpp,cc,c}; tests/ and examples/ are
# discovered separately (`mcpp test` / standalone builds).
[targets.cmdline]
kind = "lib"

[dev-dependencies]
gtest = "1.15.2"
5 changes: 0 additions & 5 deletions tests/cmdline_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
import std;
import mcpplibs.cmdline;

int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

using namespace mcpplibs::cmdline;

// Build argv from program name + args for parse()
Expand Down
7 changes: 6 additions & 1 deletion tests/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
add_rules("mode.debug", "mode.release")
set_languages("c++23")

add_requires("gtest")
add_requires("gtest", { configs = { main = true, gmock = false } })

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