New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document rust wasm32-unknown-emscripten build tool versions working with wasmer #2498
Comments
Hello, I'm not sure it's the role of Wasmer to write documentation for emscripten. Maybe it must be part of the emscripten's official documentation. Or maybe just a code snippet in the |
Hi Hywan! "Document how to build a wasm32-emscripten binary from rust" is definitely not wasmer's job, no. (Maybe Rust's, but I'm not sure either.) But wasmer doesn't support binaries built by all versions of emscripten (at least #1898 makes it seem like that), and documenting which versions of emscripten are supported by wasmer is wasmer's job, imho.
That'd be great. |
All right, I found a combination that looks like it would work, but then trying to run the binary just hangs. I'll have a deeper look at that another day. FockerdileFROM docker.io/library/debian:bullseye as bin
RUN apt-get update && \
export DEBIAN_FRONTEND=noninteractive && \
apt-get install -yq \
build-essential \
cmake \
curl \
file \
git \
python3 \
python \
sudo \
&& \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
useradd rust --user-group --create-home --shell /bin/bash
USER rust
RUN cd /home/rust && git clone https://github.com/emscripten-core/emsdk.git && cd /home/rust/emsdk && ./em
sdk install 1.38.43 && ./emsdk activate 1.38.43
ENV PATH=/home/rust/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.34 --profile default --no-modify-pa
th && \
rustup target add wasm32-unknown-emscripten
RUN cd ~ \
&& git clone https://github.com/wasmerio/rust-cli-app-example ex \
&& git config --global advice.detachedHead false \
&& git -C ex checkout ee2f893d7d702f3e5efeee30633f7ef4f6723be5
WORKDIR /home/rust/ex
RUN mkdir -p .cargo \
&& echo >>.cargo/config \
&& echo >>.cargo/config [target.wasm32-unknown-emscripten] \
&& echo >>.cargo/config 'rustflags = [ "-C", "link-args=-s EMITTING_JS=1" ]' \
&& echo >>.cargo/config
# EMITTING_JS is the old version of STANDALONE_WASM.
# It's necessary because emscripten would minify import/export names on release builds.
# Alternatively, change -O3 to -O2
#RUN true \
# && echo >>Cargo.toml \
# && echo >>Cargo.toml [profile.release] \
# && echo >>Cargo.toml opt-level = '2' \
# && echo >>Cargo.toml
#RUN cat .cargo/config && false
RUN bash -c ". /home/rust/emsdk/emsdk_env.sh && cargo -v build --locked --target=wasm32-unknown-emscripten
"
FROM docker.io/library/busybox
RUN wget https://github.com/wasmerio/wasmer/releases/download/2.0.0/wasmer-linux-musl-amd64.tar.gz \
&& echo e978d0e9298481bfd79b48a6446b63b8fcc6aa7560e22a37fb3a08705a88375b \ wasmer-linux-musl-amd64
.tar.gz | sha256sum -c \
&& tar xvf wasmer-linux-musl-amd64.tar.gz \
&& rm wasmer-linux-musl-amd64.tar.gz
COPY --from=bin /home/rust/ex/target/wasm32-unknown-emscripten/debug/rust_cli_app_example.wasm .
#ENTRYPOINT ["/bin/sh", "inspect", "rust_cli_app_example.wasm"]
ENTRYPOINT ["/bin/wasmer", "run", "rust_cli_app_example.wasm", "--disable-cache", "--"] |
Awesome, closing the issue. |
Not really working yet. I'll reopen if I have further ideas.. |
All right, I dug a bit deeper. If I run this in wasmer
It looks like wasmer is running in a deadlock somewhere in its emscripten code. :( @syrusakbary Would you mind reopening this? The issue is very much still there, after all. (I should probably open a separate issue for the deadlock.)
no_deadlocks loose on it, without much luck |
2769: Deadlock in emscripten dynamic calls r=Amanieu a=jcaesar # Description Attempting to run [an emscripten-built](#2498 (comment)) rust module lead me to a deadlock. I'm not quite sure what's wrong, but it looks to me like emscripten is calling itself through the host (No idea why. To catch exceptions?) and in the process, wasmer acquires a lock that is still held when calling back into the module. If the module tries that twice recursively, the simplest form of deadlock, a reentrancy deadlock is triggered. The standard library doesn't have reentrant locks. This cannot be solved by replacing the lock on `EmEnv.data` by an RwLock, because the code might also call `setTempRet0`, which does require a write lock. Maybe there is a way to get rid of the mutex entirely, but I do not see it. The easy way out seems to be to clone the function (arcs), let go of the lock, and then do the call back into the module. There are a few other instances of the same problematic pattern, but they call `memset` or `malloc`, which shouldn't call back into wasmer. I assume they are fine and left them alone, but have not done thorough testing. # Review - [x] Add a short description of the change to the CHANGELOG.md file Co-authored-by: Julius Michaelis <glitter@liftm.de>
Summary
Finding a working combination of versions for rustc and emscripten is black magic, many fail with arcane error messages on missing C++ symbols. And the only working combination I found so far (emcc 1.39.20, rustc 1.47.0) runs me into #1898.
It would be really nice to document how to set up and environment that builds emscripten rust executables that can be run with wasmer.
Additional details
(non-working) env setup example:
The text was updated successfully, but these errors were encountered: