Skip to content

Support for wasm-unknown-unknown using rustc nightly and -Zwasm-c-abi=spec flag #662

@jadarve

Description

@jadarve

Hi,

I'm trying to integrate mlua (awesome project btw!) into a web project using egui and trunk for bundling. I know mlua can be built into wasm using wasm-unknown-emscripten toolchain. But tools such as wasm-pack do not propagate the emscripten target.

I also saw there is support for using a spec compliant ABI in the nightly rustc: https://github.com/rust-lang/rust/pull/117919/files (I'm not sure that even matters for building mlua)

I tried to build mlua in a project using:

.cargo/config.toml:

[target.wasm32-unknown-unknown]
rustflags = ["-C", "target-feature=+bulk-memory", "-Z", "wasm-c-abi=spec"]

Adding mlua dependency as:

mlua = { version = "0.11.5", features = ["luau", "vendored"] }

and building as:

cargo build --target wasm32-unknown-unknown

Then I get this error:

warning: mlua-sys@0.9.0: ToolExecError: command did not execute successfully (status code exit status: 1): LC_ALL="C" "clang++" "-O3" "-ffunction-sections" "-fdata-sections" "-fno-exceptions" "--target=wasm32-unknown-unknown" "-std=c++17" "-I" "/home/juan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/luau0-src-0.17.0+luau701/luau/Common/include" "-I" "/home/juan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/luau0-src-0.17.0+luau701/luau/Ast/include" "-fno-math-errno" "-DLUAI_MAXCSTACK=1000000" "-DLUA_VECTOR_SIZE=3" "-DLUA_API=extern \"C\"" "-o" "/home/juan/git/my_project/target/wasm32-unknown-unknown/release/build/mlua-sys-df4fd56c73506f73/out/luau-build/00164cb3bff842c0-Parser.o" "-c" "/home/juan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/luau0-src-0.17.0+luau701/luau/Ast/src/Parser.cpp"
error: failed to run custom build command for `mlua-sys v0.9.0`

Caused by:
  process didn't exit successfully: `/home/juan/git/midlife_engine/target/release/build/mlua-sys-5c1c28e5c5461ac1/build-script-main` (exit status: 1)
  --- stdout
  cargo:rerun-if-changed=build
  cargo:warning=In file included from /home/juan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/luau0-src-0.17.0+luau701/luau/Ast/src/Allocator.cpp:3:
  cargo:warning=In file included from /home/juan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/luau0-src-0.17.0+luau701/luau/Ast/include/Luau/Allocator.h:4:
  cargo:warning=/home/juan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/luau0-src-0.17.0+luau701/luau/Ast/include/Luau/Ast.h:6:10: fatal error: 'iterator' file not found
  cargo:warning=    6 | #include <iterator>
  cargo:warning=      |          ^~~~~~~~~~
  cargo:warning=1 error generated.
  exit status: 1

That missing <iterator> file, and possibly more for the std lib, do you think can be fixed somehow and get wasm32-unknown-unknown working?

Some references:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions