diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8e5a50..f0ee911 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,104 +2,41 @@ 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 - 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 - - - name: Install dependencies - run: brew install xmake llvm@20 - - - 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: Setup xmake - uses: xmake-io/github-action-setup-xmake@v1 + XLINGS_VERSION: 0.4.30 + run: | + 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 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.11, so a fixed key suffices. + - name: Cache mcpp sandbox + uses: actions/cache@v4 with: - xmake-version: latest - package-cache: true + path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.11/registry + key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.11 - - 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: Build with mcpp + run: mcpp build - - 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..e986e06 --- /dev/null +++ b/.xlings.json @@ -0,0 +1,5 @@ +{ + "workspace": { + "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 的核心功能: diff --git a/mcpp.toml b/mcpp.toml new file mode 100644 index 0000000..738275d --- /dev/null +++ b/mcpp.toml @@ -0,0 +1,19 @@ +[package] +namespace = "mcpplibs.capi" +name = "lua" +version = "0.0.3" +description = "C++23 module wrapping the Lua 5.4 C API" +license = "Apache-2.0" +repo = "https://github.com/mcpplibs/lua" + +[lib] +path = "src/capi/lua.cppm" + +[targets.capi-lua] +kind = "lib" + +[dependencies] +lua = "5.4.7" + +[dev-dependencies] +gtest = "1.15.2" 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); } 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.)