Skip to content
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

wasm-interp for the web #2157

Closed
iBicha opened this issue Mar 3, 2023 · 13 comments
Closed

wasm-interp for the web #2157

iBicha opened this issue Mar 3, 2023 · 13 comments

Comments

@iBicha
Copy link

iBicha commented Mar 3, 2023

Can wasm-interp be built for wasm?
Solving for WebAssembly/binaryen#5530

@sbc100
Copy link
Member

sbc100 commented Mar 3, 2023

I don't see why not, in fact I think we already do build it as part of CI:

emscripten:
name: emscripten
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: build
run: |
docker run -di --name emscripten -v $(pwd):/src emscripten/emsdk:latest bash
docker exec emscripten emcc -v
docker exec emscripten emcmake cmake .
docker exec emscripten make -j 2 VERBOSE=1

@iBicha
Copy link
Author

iBicha commented Mar 5, 2023

I don't see why not, in fact I think we already do build it as part of CI:

emscripten:
name: emscripten
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
submodules: true
- name: build
run: |
docker run -di --name emscripten -v $(pwd):/src emscripten/emsdk:latest bash
docker exec emscripten emcc -v
docker exec emscripten emcmake cmake .
docker exec emscripten make -j 2 VERBOSE=1

Perhaps I need to look closer, but after inspecting the artifacts, I don't see something like wasm-interp.wasm which is what I'm actually after (similar to https://github.com/wasm3/wasm3/releases/download/v0.5.0/wasm3-wasi.wasm)

I appreciate the guidance! I'm pretty new to wabt

@sbc100
Copy link
Member

sbc100 commented Mar 5, 2023

I don't think we public the emscripten build as part of the release. It should be fairly straight forward to build it yourself if you need to.

@sbc100
Copy link
Member

sbc100 commented Mar 5, 2023

If you want to create a PR that will stash the CI artifacts somewhere that would be great too (then I think you could download them from any CI run).

@iBicha
Copy link
Author

iBicha commented Mar 5, 2023

What I'm saying is that the github action might not be producing the actual interpreter in wasm.
I ran the build locally, and the produced artifacts look like test artifacts, not wasm-interp.wasm

> find *.wasm
callback.wasm
finalize.wasm
global.wasm
hello.wasm
hostref.wasm
memory.wasm
multi.wasm
reflect.wasm
serialize.wasm
start.wasm
table.wasm
threads.wasm
trap.wasm

@sbc100
Copy link
Member

sbc100 commented Mar 5, 2023

Yes those are not the build artifacts. How did you do that build? The build artifacts end up the bin directory inside the build directory.

I would do something like this:

$ mkdir build
$ cd build
$ emcmake cmake -G Ninja ..
$ ninja wasm-interp
$ node wasm-interp.js 
wasm-interp: expected filename argument.

It looks like wabt build to pure JS by default, if you want the wasm version you would need to edit CMakeLists.txt and remove -sWASM=0. (We should probably remove that).

@iBicha
Copy link
Author

iBicha commented Mar 5, 2023

I followed the CI (docker was nice, since I didn't have to worry about the right deps)

docker run -di --name emscripten -v $(pwd):/src emscripten/emsdk:latest bash
docker exec emscripten emcc -v
docker exec emscripten emcmake cmake .
docker exec emscripten make -j 2 VERBOSE=1

I removed -sWASM=0, but that didn't change the output.

@sbc100
Copy link
Member

sbc100 commented Mar 5, 2023

And do you get a wasm-interp.js file being produced?

@sbc100
Copy link
Member

sbc100 commented Mar 5, 2023

BTW, you don't need to use docker, you can also just install emsdk in your machine if you want.

@iBicha
Copy link
Author

iBicha commented Mar 5, 2023

And do you get a wasm-interp.js file being produced?

Yes, and I'm trying make it produce wasm-interp.wasm
I dug a bit in the settings, and then changed the extra link flags to

    set(EXTRA_LINK_FLAGS
      "${EXTRA_LINK_FLAGS} -sSINGLE_FILE -Oz -sSTANDALONE_WASM -sALLOW_MEMORY_GROWTH"
    )

But ninja.build still contains target for wasm-interp.js, and still produces that file, not the wasm

@sbc100
Copy link
Member

sbc100 commented Mar 5, 2023

Oh you have to remove -sSINGLE_FILE too since otherwise it embeds the wasm inside the JS.

BTW do you really want to the wasm file or do you just want to run it on the web (in which case you probably want to the JS file too).

@iBicha
Copy link
Author

iBicha commented Mar 5, 2023

Oh you have to remove -sSINGLE_FILE too since otherwise it embeds the wasm inside the JS.

BTW do you really want to the wasm file or do you just want to run it on the web (in which case you probably want to the JS file too).

I will try removing the SINGLE_FILE flag and see!

Yeah sorry for leaving an important detail (related to the ticket I mentioned) I do not have a js runtime. What I have is a tool that is capable of transforming wasm into brightscript. But the transformed code has limitations. So I was hoping I can built wasm-interp into wasm, transform that into brightscript, and use it to load other wasm modules, bringing functionality to Roku OS apps.

@iBicha
Copy link
Author

iBicha commented Mar 5, 2023

Yup, removing SINGLE_FILE produces the wasm module! I will close this issue, since this is a very niche thing, so I doubt someone would need to build into wasm specifically.
Thank you for the guidance @sbc100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants