wasmer: Error while importing "env"."system": unknown import. Expected Function(FunctionType { params: [I32], results: [I32] })

Summary

Hi, I’m wondering what I need to know in order to understand and work on a fix to move past this error message please?

# emcc *.c -o metamath.wasm
# wasmer metamath.wasm
error: failed to run `metamath.wasm`
╰─> 1: Error while importing "env"."system": unknown import. Expected Function(FunctionType { params: [I32], results: [I32] })

Additional details

And here’s the containerised build environment I’m currently using (happy to take alternative suggestions for this)

Dockerfile

FROM emscripten/emsdk:1.40.1
WORKDIR /app

# Get wasmer
RUN curl https://get.wasmer.io -sSfL | sh
ENV PATH="/root/.wasmer/bin:${PATH}"

# Get the metamath source code
RUN curl http://us.metamath.org/downloads/metamath.zip -o metamath.zip
RUN unzip metamath.zip -d .

# For convenience also get set.mm
RUN curl https://raw.githubusercontent.com/metamath/set.mm/develop/set.mm -o set.mm

# And when run, launch the shell
WORKDIR /app/metamath
CMD ["sh"]

usage:

docker build -t metamath .
docker run -it metamath

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (10 by maintainers)

Commits related to this issue

Most upvoted comments

The other option might be to try some old version of emscripten that doesn’t yet use wasi. (Older than 1.39.0, I tried that one.)

Ah, #1640 suggests 1.38.43 or earlier, but 1.39.0 is as far back as the emscripten/emsdk containers go on dockerhub.

Guess I’ll have to find a different container or learn how to install the full development environment myself after all.

Thanks for your help! 😃

Which is why I switched to downloading the github releases. I suppose I should have posted the link.

Yes, that’s impressive work! Well done, and thank you! 😃

Question though: Why’d you try running metamath on wasmer, outside of the web, if the web is your target?

Um, because Metamath is a command line program and wasmer is for command line programs, and I’m spoilt by nodejs, and thus used to command line JavaScript being almost the same as web JavaScript. Wouldn’t have been such a terrible idea if the WASI support was complete consistently across the board, would it? Not so smart in hindsight, sorry. Even now I’m not sure I appreciate the finer points in terms of the distinction between wasmer, @wasmer/cli, and @wasmer/wasm-terminal.

neither github.io nor metamath.org set the necessary CORS headers for the webassembly.sh’s curl to work

Hmm. I seem to be able to curl set.mm fine.

Screenshot 2021-10-06 at 10 35 25

That user you created introduced a permissions problem, so I’ve stripped it out.

Weird, works fine for me.

The next problem is that some part of the system doesn’t have enough memory to read in set.mm

Ah, now that you say it, that’s what ALLOW_MEMORY_GROWTH is for.

However, it works perfectly with demo0.mm

So does

wapm execute --emscripten metamath "read set.mm" "verify proof *" exit

😃 (Though of course this means running untrusted unsandboxed binaries on your system, so I’m not sure it’s all that terribly useful.)

I sure would have liked it if I could use --embed-file to add set.mm and friends into the wasm binary (they’re 40 MB without comments, but it’s generally expected that you need to compress wasm before network transfers, as does wapm, so that’s ~ok.), but that doesn’t seem to work.

Should probably start FROM something that’s not emscripten/emsdk to avoid version confusion.

FROM 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 \
        unzip \
        && \
    apt-get clean && rm -rf /var/lib/apt/lists/* && \
    useradd frust --user-group --create-home --home-dir /work --shell /bin/bash
USER frust
WORKDIR  /work
RUN git clone https://github.com/emscripten-core/emsdk.git
WORKDIR /work/emsdk
RUN ./emsdk install 1.38.43
RUN ./emsdk activate 1.38.43
ENV PATH="/work/emsdk:${PATH}"
ENV PATH="/work/emsdk/node/14.15.5_64bit/bin:${PATH}"
ENV PATH="/work/emsdk/fastcomp/emscripten:${PATH}"
ENV EMSDK_NODE=/work/emsdk/node/14.15.5_64bit/bin/node
ENV EMSDK=/work/emsdk
ENV EM_CONFIG=/work/emsdk/.emscripten
WORKDIR /work
RUN curl http://us.metamath.org/downloads/metamath.zip -o metamath.zip \
        && echo 126fc3eac6699257cfcdbfb2087fb31284fdfe784bb9d6e2ea7c32b8524c3da9 \ metamath.zip | sha256sum -c \
        && unzip metamath.zip -d . \
        && rm metamath.zip
WORKDIR /work/metamath
RUN curl https://raw.githubusercontent.com/metamath/set.mm/develop/set.mm -o set.mm \
        && echo 2a497ca6cbf422e5a58244c7ab064bd62700daa289d9e325d6a9e590ec30d0c4 \ set.mm | sha256sum -c
RUN emcc *.c -o metamath.wasm

# sorry, this isn't a serious docker image for wasmer. Just using another experiment of mine for testing
FROM liftm/wasmer:binfmt-experiment
COPY --from=bin /work/metamath/metamath.wasm /work/metamath/set.mm /
ENTRYPOINT ["/wasmer", "run", "--disable-cache", "metamath.wasm", "--"]

This gets me to the metamath prompt, but trying to read set.mm fails for different reasons. Good luck with that. ;P

(base) ➜  complex em++ --bind -o fib2.wasm fib2.cc --no-entry -O3 
(base) ➜  complex wasmer fib2.wasm                               
error: failed to run `fib2.wasm`
╰─> 1: Error while importing "env"."_embind_register_class": unknown import. Expected Function(FunctionType { params: > [I32, I32, I32, I32, I32, I32, I32, I32, I32, I32, I32, I32, I32], results: [] })

Same Problem