Skip to content

Commit

Permalink
Support emscripten (wasm)
Browse files Browse the repository at this point in the history
  • Loading branch information
bytedream committed Nov 24, 2023
1 parent f3dc037 commit eef17e8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand All @@ -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 }}
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};

Expand Down
4 changes: 3 additions & 1 deletion testcrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit eef17e8

Please sign in to comment.