From 9a8042a39ae77d02eb20520b0eaf62452831c678 Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Mon, 2 Mar 2026 01:20:45 +0800 Subject: [PATCH 01/10] fix: lua_newstate signature changed in Lua 5.5 (3 args) Lua 5.5 added a third 'seed' parameter to lua_newstate(). Use version check to pass the extra argument when needed. Co-Authored-By: Claude Opus 4.6 --- src/capi/lua.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/capi/lua.cpp b/src/capi/lua.cpp index 77f194d..701c158 100644 --- a/src/capi/lua.cpp +++ b/src/capi/lua.cpp @@ -10,7 +10,13 @@ namespace mcpplibs::capi::lua { // State Management // ============================================================================ -State* newstate(Alloc f, void* ud) { return ::lua_newstate(f, ud); } +State* newstate(Alloc f, void* ud) { +#if LUA_VERSION_NUM >= 505 + return ::lua_newstate(f, ud, 0); +#else + return ::lua_newstate(f, ud); +#endif +} void close(State* L) { ::lua_close(L); } State* newthread(State* L) { return ::lua_newthread(L); } CFunction atpanic(State* L, CFunction panicf) { return ::lua_atpanic(L, panicf); } From d56abcbb18492ca54979880b44da023ca868b92a Mon Sep 17 00:00:00 2001 From: SPeak Date: Sun, 10 May 2026 03:17:08 +0800 Subject: [PATCH 02/10] feat: add mcpp.toml for mcpp build support (#2) Wires mcpplibs.capi.lua into the mcpp build system. The descriptor: - targets `capi-lua` (lib) at `src/capi/lua.cppm` (override the default lib-root convention which would look at `src/lua.cppm`), - depends on the upstream Lua 5.4.7 C library shipped via mcpp-community/mcpp-index (added 2026-05-09). mcpp 0.0.3's transitive walker propagates lua's headers into our compile rule, so the existing `extern "C" { #include ... }` in `src/capi/lua_headers.h` keeps working with no path tweaking. Verified locally: `mcpp build` is clean against a fresh `target/`. --- mcpp.toml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 mcpp.toml diff --git a/mcpp.toml b/mcpp.toml new file mode 100644 index 0000000..ee95c54 --- /dev/null +++ b/mcpp.toml @@ -0,0 +1,25 @@ +[package] +name = "mcpplibs.capi.lua" +version = "0.0.3" +description = "C++23 module wrapping the Lua 5.4 C API — `import mcpplibs.capi.lua;`" +license = "Apache-2.0" +repo = "https://github.com/mcpplibs/lua" + +[lib] +# The primary module interface lives at `src/capi/lua.cppm`. The default +# convention would look at `src/lua.cppm` (last segment of the package +# name), so override explicitly. +path = "src/capi/lua.cppm" + +[targets.capi-lua] +kind = "lib" + +# `lua` is the upstream Lua 5.4 C library shipped via mcpp-index. mcpp +# 0.0.3 propagates its headers (lua.h / lauxlib.h / lualib.h) into our +# compile rule via the transitive include-dir walk. +[dependencies] +lua = "5.4.7" + +# `mcpp test` discovers tests/main.cpp automatically. +[dev-dependencies] +gtest = "1.15.2" From 687495f4d4620071c120d0d71ef3d1b4dd570e22 Mon Sep 17 00:00:00 2001 From: SPeak Date: Sun, 10 May 2026 04:14:05 +0800 Subject: [PATCH 03/10] ci: switch to mcpp build (.xlings.json pins mcpp 0.0.3) (#3) Replaces the multi-platform xmake CI with a single mcpp-driven Linux job: - `.xlings.json` declares `mcpp = { linux = "0.0.3" }`. - `.github/workflows/ci.yml` boots xlings, runs `xlings install -y`, then `mcpp build` + `mcpp test` against the existing mcpp.toml. xmake.lua + CMakeLists.txt stay untouched for local development; CI on Linux now goes through mcpp end-to-end. --- .github/workflows/ci.yml | 108 +++++++-------------------------------- .xlings.json | 5 ++ tests/main.cpp | 6 +-- 3 files changed, 25 insertions(+), 94 deletions(-) create mode 100644 .xlings.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8e5a50..f5a9833 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,104 +2,32 @@ name: CI on: push: - branches: [main, master] + branches: [main] pull_request: - branches: [main, master] - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: ci-${{ github.ref }} - cancel-in-progress: true jobs: - build-linux: + build: + name: build + test (linux x86_64, mcpp) runs-on: ubuntu-latest - 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 + - uses: actions/checkout@v4 - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y build-essential - - - name: Install Xlings + - name: Install xlings env: - XLINGS_NON_INTERACTIVE: 1 - run: | - curl -fsSL https://raw.githubusercontent.com/d2learn/xlings/refs/heads/main/tools/other/quick_install.sh | bash - echo "PATH=$HOME/.xlings/subos/current/bin:$PATH" >> "$GITHUB_ENV" - - - name: Install GCC 15.1 with Xlings - run: | - xlings install gcc@15.1 -y - - - name: Build - run: | - xmake f -m release -y -vv - xmake build -y -vv mcpplibs-capi-lua - xmake -y -vv -j$(nproc) - - - name: Test - run: xmake run capi_lua_test - - - name: Run examples + XLINGS_VERSION: 0.4.25 run: | - xmake run basic - xmake run table - xmake run function - xmake run eval - - build-macos: - runs-on: macos-14 - timeout-minutes: 20 - steps: - - name: Checkout - uses: actions/checkout@v4 + tarball="xlings-${XLINGS_VERSION}-linux-x86_64.tar.gz" + curl -fsSL -o "/tmp/${tarball}" \ + "https://github.com/d2learn/xlings/releases/download/v${XLINGS_VERSION}/${tarball}" + tar -xzf "/tmp/${tarball}" -C /tmp + "/tmp/xlings-${XLINGS_VERSION}-linux-x86_64/subos/default/bin/xlings" self install + echo "$HOME/.xlings/subos/current/bin" >> "$GITHUB_PATH" - - name: Install dependencies - run: brew install xmake llvm@20 + - name: Install workspace tools (.xlings.json → mcpp 0.0.3) + run: xlings install -y - - name: Build - 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) - - build-windows: - runs-on: windows-latest - timeout-minutes: 20 - steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Build with mcpp + run: mcpp build - - name: Setup xmake - uses: xmake-io/github-action-setup-xmake@v1 - with: - xmake-version: latest - package-cache: true - - - name: Build - run: | - xmake f -m release -y -vv - xmake -y -vv -j$env:NUMBER_OF_PROCESSORS - - - name: Test - run: xmake run capi_lua_test - - - name: Run examples - run: | - xmake run basic - xmake run table - xmake run function - xmake run eval + - name: Run tests + run: mcpp test diff --git a/.xlings.json b/.xlings.json new file mode 100644 index 0000000..f2be3fd --- /dev/null +++ b/.xlings.json @@ -0,0 +1,5 @@ +{ + "workspace": { + "mcpp": { "linux": "0.0.3" } + } +} diff --git a/tests/main.cpp b/tests/main.cpp index a46b1eb..4c6a6d8 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1097,7 +1097,5 @@ TEST(MiscTest, AtPanic) { lua::close(L); } -int main(int argc, char** argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} +// (No `int main(...)` here — `mcpp test` auto-links gtest_main, which +// supplies its own main() and runs every TEST registered above.) From 7c76eb723ff7f069829663cf2acf1698faa323b0 Mon Sep 17 00:00:00 2001 From: SPeak Date: Sun, 10 May 2026 06:26:57 +0800 Subject: [PATCH 04/10] =?UTF-8?q?ci:=20cache=20mcpp's=20self-bootstrapped?= =?UTF-8?q?=20sandbox=20(~800=20MB=20=E2=86=92=20instant)=20(#4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit mcpp 0.0.3's binary lives at xim-x-mcpp/0.0.3/bin/mcpp; on first run it self-detects home as that grandparent and bootstraps musl-gcc + binutils + glibc + ninja + patchelf into /registry/data/xpkgs. Toolchain set is version-pinned by mcpp 0.0.3, so a fixed cache key is safe. Cache-hit runs skip the ~800 MB download. --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5a9833..e33f485 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,15 @@ jobs: - name: Install workspace tools (.xlings.json → mcpp 0.0.3) run: xlings install -y + # Cache mcpp's self-bootstrapped sandbox (musl-gcc + binutils + + # glibc + ninja + patchelf, ~800 MB). Toolchain set is pinned by + # mcpp 0.0.3, so a fixed key suffices. + - name: Cache mcpp sandbox + uses: actions/cache@v4 + with: + path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.3/registry + key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.3 + - name: Build with mcpp run: mcpp build From 6e15aaf238bf885c09684b2b299606225b90b6d8 Mon Sep 17 00:00:00 2001 From: SPeak Date: Sun, 10 May 2026 06:32:52 +0800 Subject: [PATCH 05/10] =?UTF-8?q?ci:=20bump=20mcpp=200.0.3=20=E2=86=92=200?= =?UTF-8?q?.0.4=20(glob=20exclusion,=20sandbox=20PATH)=20(#5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 8 ++++---- .xlings.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e33f485..6616cbd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,17 +23,17 @@ jobs: "/tmp/xlings-${XLINGS_VERSION}-linux-x86_64/subos/default/bin/xlings" self install echo "$HOME/.xlings/subos/current/bin" >> "$GITHUB_PATH" - - name: Install workspace tools (.xlings.json → mcpp 0.0.3) + - name: Install workspace tools (.xlings.json → mcpp 0.0.4) run: xlings install -y # Cache mcpp's self-bootstrapped sandbox (musl-gcc + binutils + # glibc + ninja + patchelf, ~800 MB). Toolchain set is pinned by - # mcpp 0.0.3, so a fixed key suffices. + # mcpp 0.0.4, so a fixed key suffices. - name: Cache mcpp sandbox uses: actions/cache@v4 with: - path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.3/registry - key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.3 + path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.4/registry + key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.4 - name: Build with mcpp run: mcpp build diff --git a/.xlings.json b/.xlings.json index f2be3fd..b3b1fb4 100644 --- a/.xlings.json +++ b/.xlings.json @@ -1,5 +1,5 @@ { "workspace": { - "mcpp": { "linux": "0.0.3" } + "mcpp": { "linux": "0.0.4" } } } From c69a99cf45394049d7af2f14b6f3c7e080ea781a Mon Sep 17 00:00:00 2001 From: SPeak Date: Mon, 11 May 2026 16:09:15 +0800 Subject: [PATCH 06/10] chore: migrate deps to namespace syntax (mcpp 0.0.6) (#6) * chore: migrate deps to namespace syntax (mcpp 0.0.6) Updates mcpp.toml to use explicit namespace fields: - [package].namespace added - [package].name uses short name only - [dependencies.compat] / [dev-dependencies.compat] for non-modular libs - [dependencies.mcpplibs.capi] for C API wrappers * ci: retrigger with fixed mcpp 0.0.6 --- .github/workflows/ci.yml | 8 ++++---- .xlings.json | 2 +- mcpp.toml | 12 +++--------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6616cbd..d27b500 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,17 +23,17 @@ jobs: "/tmp/xlings-${XLINGS_VERSION}-linux-x86_64/subos/default/bin/xlings" self install echo "$HOME/.xlings/subos/current/bin" >> "$GITHUB_PATH" - - name: Install workspace tools (.xlings.json → mcpp 0.0.4) + - name: Install workspace tools (.xlings.json → mcpp 0.0.7) run: xlings install -y # Cache mcpp's self-bootstrapped sandbox (musl-gcc + binutils + # glibc + ninja + patchelf, ~800 MB). Toolchain set is pinned by - # mcpp 0.0.4, so a fixed key suffices. + # mcpp 0.0.7, so a fixed key suffices. - name: Cache mcpp sandbox uses: actions/cache@v4 with: - path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.4/registry - key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.4 + path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.7/registry + key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.7 - name: Build with mcpp run: mcpp build diff --git a/.xlings.json b/.xlings.json index b3b1fb4..3f993c1 100644 --- a/.xlings.json +++ b/.xlings.json @@ -1,5 +1,5 @@ { "workspace": { - "mcpp": { "linux": "0.0.4" } + "mcpp": { "linux": "0.0.7" } } } diff --git a/mcpp.toml b/mcpp.toml index ee95c54..738275d 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,25 +1,19 @@ [package] -name = "mcpplibs.capi.lua" +namespace = "mcpplibs.capi" +name = "lua" version = "0.0.3" -description = "C++23 module wrapping the Lua 5.4 C API — `import mcpplibs.capi.lua;`" +description = "C++23 module wrapping the Lua 5.4 C API" license = "Apache-2.0" repo = "https://github.com/mcpplibs/lua" [lib] -# The primary module interface lives at `src/capi/lua.cppm`. The default -# convention would look at `src/lua.cppm` (last segment of the package -# name), so override explicitly. path = "src/capi/lua.cppm" [targets.capi-lua] kind = "lib" -# `lua` is the upstream Lua 5.4 C library shipped via mcpp-index. mcpp -# 0.0.3 propagates its headers (lua.h / lauxlib.h / lualib.h) into our -# compile rule via the transitive include-dir walk. [dependencies] lua = "5.4.7" -# `mcpp test` discovers tests/main.cpp automatically. [dev-dependencies] gtest = "1.15.2" From 33efc73542b2048845b7a77a031def13761ecc4e Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Tue, 12 May 2026 05:31:31 +0800 Subject: [PATCH 07/10] fix: use [dependencies.compat] for non-modular deps lua (C library) and gtest are compat (non-modular) packages in mcpp-index. Declare them under [dependencies.compat] / [dev-dependencies.compat] subtables so mcpp resolves the correct namespace ("compat") instead of the default ("mcpp") namespace. Required for mcpp 0.0.10+ namespace-aware dependency pipeline. --- mcpp.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mcpp.toml b/mcpp.toml index 738275d..b8a5f03 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -12,8 +12,8 @@ path = "src/capi/lua.cppm" [targets.capi-lua] kind = "lib" -[dependencies] +[dependencies.compat] lua = "5.4.7" -[dev-dependencies] +[dev-dependencies.compat] gtest = "1.15.2" From 03b5fb29a32a2ddf040eacfad9cfb118b7c8a4c9 Mon Sep 17 00:00:00 2001 From: SPeak Date: Tue, 12 May 2026 07:16:59 +0800 Subject: [PATCH 08/10] ci: bump mcpp to 0.0.8 (namespace-aware index support) (#7) --- .github/workflows/ci.yml | 10 +++++----- .xlings.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d27b500..5f875aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: - name: Install xlings env: - XLINGS_VERSION: 0.4.25 + XLINGS_VERSION: 0.4.30 run: | tarball="xlings-${XLINGS_VERSION}-linux-x86_64.tar.gz" curl -fsSL -o "/tmp/${tarball}" \ @@ -23,17 +23,17 @@ jobs: "/tmp/xlings-${XLINGS_VERSION}-linux-x86_64/subos/default/bin/xlings" self install echo "$HOME/.xlings/subos/current/bin" >> "$GITHUB_PATH" - - name: Install workspace tools (.xlings.json → mcpp 0.0.7) + - name: Install workspace tools (.xlings.json → mcpp 0.0.8) run: xlings install -y # Cache mcpp's self-bootstrapped sandbox (musl-gcc + binutils + # glibc + ninja + patchelf, ~800 MB). Toolchain set is pinned by - # mcpp 0.0.7, so a fixed key suffices. + # mcpp 0.0.8, so a fixed key suffices. - name: Cache mcpp sandbox uses: actions/cache@v4 with: - path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.7/registry - key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.7 + path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.8/registry + key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.8 - name: Build with mcpp run: mcpp build diff --git a/.xlings.json b/.xlings.json index 3f993c1..ad3e668 100644 --- a/.xlings.json +++ b/.xlings.json @@ -1,5 +1,5 @@ { "workspace": { - "mcpp": { "linux": "0.0.7" } + "mcpp": { "linux": "0.0.8" } } } From ae12683b77e63863e910f96c96c758c25bd78e4a Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Tue, 12 May 2026 18:33:52 +0800 Subject: [PATCH 09/10] chore: bump mcpp to 0.0.11 + add mcpp usage to README MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - .xlings.json: mcpp 0.0.8 → 0.0.11 - CI: mcpp 0.0.11 - README: add mcpp build/usage section --- .github/workflows/ci.yml | 8 ++++---- .xlings.json | 2 +- README.md | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f875aa..f0ee911 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,17 +23,17 @@ jobs: "/tmp/xlings-${XLINGS_VERSION}-linux-x86_64/subos/default/bin/xlings" self install echo "$HOME/.xlings/subos/current/bin" >> "$GITHUB_PATH" - - name: Install workspace tools (.xlings.json → mcpp 0.0.8) + - name: Install workspace tools (.xlings.json → mcpp 0.0.11) run: xlings install -y # Cache mcpp's self-bootstrapped sandbox (musl-gcc + binutils + # glibc + ninja + patchelf, ~800 MB). Toolchain set is pinned by - # mcpp 0.0.8, so a fixed key suffices. + # mcpp 0.0.11, so a fixed key suffices. - name: Cache mcpp sandbox uses: actions/cache@v4 with: - path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.8/registry - key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.8 + path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.11/registry + key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.11 - name: Build with mcpp run: mcpp build diff --git a/.xlings.json b/.xlings.json index ad3e668..e986e06 100644 --- a/.xlings.json +++ b/.xlings.json @@ -1,5 +1,5 @@ { "workspace": { - "mcpp": { "linux": "0.0.8" } + "mcpp": { "linux": "0.0.11" } } } diff --git a/README.md b/README.md index 8d30700..7146bf9 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,34 @@ target("myapp") set_policy("build.c++.modules", true) ``` +### mcpp + +#### 添加依赖 + +```bash +mcpp add mcpplibs.capi:lua@0.0.3 +``` + +或在 `mcpp.toml` 中手动添加: + +```toml +[dependencies] +"mcpplibs.capi:lua" = "0.0.3" +``` + +#### 构建 + +```bash +mcpp build +``` + +#### 代码示例 + +```cpp +import mcpplibs.capi.lua; +// ... 参见上方"快速开始" +``` + ## 覆盖范围 封装了 Lua 5.4 C API 的核心功能: From 6fe17fbc274520fb6a1d3205e7123e588ecf1f14 Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Tue, 12 May 2026 18:40:49 +0800 Subject: [PATCH 10/10] fix: revert to flat dependency form (xlings compat) --- mcpp.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mcpp.toml b/mcpp.toml index b8a5f03..738275d 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -12,8 +12,8 @@ path = "src/capi/lua.cppm" [targets.capi-lua] kind = "lib" -[dependencies.compat] +[dependencies] lua = "5.4.7" -[dev-dependencies.compat] +[dev-dependencies] gtest = "1.15.2"