From eef17e86784a9beeeaae7597f3572e61b3da276d Mon Sep 17 00:00:00 2001 From: bytedream Date: Fri, 24 Nov 2023 13:30:18 +0100 Subject: [PATCH] Support emscripten (wasm) --- .github/workflows/main.yml | 18 ++++++++++++++++++ src/lib.rs | 3 +++ testcrate/src/lib.rs | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f597432..2493d2c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,6 +28,8 @@ jobs: os: macos-latest - target: x86_64-pc-windows-msvc os: windows-latest + - target: wasm32-unknown-emscripten + os: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable @@ -51,6 +53,12 @@ jobs: sudo apt-get update -y sudo apt-get install -y --no-install-recommends gcc-arm-linux-gnueabi libc6-dev-armel-cross shell: bash + - name: Install emscripten (wasm32-unknown-emscripten) + if: ${{ matrix.target == 'wasm32-unknown-emscripten' }} + run: | + sudo apt-get update -y + sudo apt-get install -y --no-install-recommends emscripten + shell: bash - name: Build ${{ matrix.lua }} run: | cargo build --manifest-path testcrate/Cargo.toml --target ${{ matrix.target }} --release --features ${{ matrix.lua }} @@ -71,11 +79,21 @@ jobs: target: x86_64-apple-darwin - os: windows-latest target: x86_64-pc-windows-msvc + - os: ubuntu-latest + target: wasm32-unknown-emscripten steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable with: target: ${{ matrix.target }} + - name: Install emscripten (wasm32-unknown-emscripten) + if: ${{ matrix.target == 'wasm32-unknown-emscripten' }} + run: | + sudo apt-get update -y + sudo apt-get install -y --no-install-recommends emscripten + echo 'CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUNNER=node' >> $GITHUB_ENV + echo 'RUSTFLAGS="-C link-args=-sERROR_ON_UNDEFINED_SYMBOLS=0"' >> $GITHUB_ENV + shell: bash - name: Run ${{ matrix.lua }} tests run: | cargo test --manifest-path testcrate/Cargo.toml --release --features ${{ matrix.lua }} diff --git a/src/lib.rs b/src/lib.rs index 6aab3d8..6502ef8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,6 +104,9 @@ impl Build { // Defined in Lua >= 5.3 config.define("LUA_USE_WINDOWS", None); } + _ if target.ends_with("emscripten") => { + config.define("LUA_USE_POSIX", None); + } _ => panic!("don't know how to build Lua for {}", target), }; diff --git a/testcrate/src/lib.rs b/testcrate/src/lib.rs index 7b5daab..744bc8b 100644 --- a/testcrate/src/lib.rs +++ b/testcrate/src/lib.rs @@ -7,8 +7,10 @@ extern "C" { pub fn lua_tolstring(state: *mut c_void, index: c_int, len: *mut c_long) -> *const c_char; pub fn luaL_loadstring(state: *mut c_void, s: *const c_char) -> c_int; - #[cfg(any(feature = "lua52", feature = "lua53", feature = "lua54"))] + #[cfg(feature = "lua52")] pub fn lua_getglobal(state: *mut c_void, k: *const c_char); + #[cfg(any(feature = "lua53", feature = "lua54"))] + pub fn lua_getglobal(state: *mut c_void, k: *const c_char) -> c_int; } #[cfg(feature = "lua51")]