-
Notifications
You must be signed in to change notification settings - Fork 785
Cross-compiling from Rust doesn't work as expected #867
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
Comments
I think the string is in the For that assertion, we should be improving it soon, but meanwhile if you can emit HTML instead of JS, it will work (the html will set up the binary for you; alternatively, you can set it up yourself manually). |
Thank you for your answer! In fact my goal is to create a wasm module (using Rust) with simple function exported to use from JS via JavaScript API in Canary / FF Nightly Maybe there are some articles / docs / blog posts which can help? BTW, how can I emit HTML? Should I call Sorry for my newbie questions :( |
To emit html, you just call emcc with If all you want is a wasm module that you use directly, and it doesn't need JS integration, and it doesn't need libc or other system libs (which often needs JS, e.g. to print), then you can read the "standalone wasm". It has a full example, that maybe you can connect rustc to? But the standalone stuff is experimental, so expect breakage. |
It was as simple as rustc --target=wasm32-unknown-emscripten hello.rs -o output.html 🎉
I just need arithmetic operations without any I/O. Standalone wasm is exactly what I need. Thank you! I'll try it. |
@brson is there any way to pass |
@chicoxyzzy no i don't think so, this is the same old tired issue of not being able to pass link arguments to the "system" linker (in this case emcc) via cargo. Of course, you can:
Alternatively, you can perform some path hackery and have PS: your your suggestion works by the way, thank you, I couldn't seem to find this mentioned anywhere obviously... |
I was following instructions from https://users.rust-lang.org/t/compiling-to-the-web-with-rust-and-emscripten/7627 and had no luck in generating working example.
Memory
property ofWebAssembly
object"Hello, Emscripten!"
string anywhereindex.html
with such content:and ran Python's SimpleHTTPServer. Running this in latest Chrome Canary with WebAssembly enabled doesn't do anything while not throwing errors and showing an empty wasm module object.
So I'm not sure if Rust code cross-compiles to correct wasm module at all for now (using rustc 1.14.0 and emcc 1.37.0 / 1.37.1). Am I doing something wrong?
@kripken's answer (from here)
@kripken I've tried to run generated JS file in browser and there is an error
Also there is no
"Hello, Emscripten!"
in generated JS file. And there are no memory segments in wast as far as I can see.Rust source file:
Generated files:
The text was updated successfully, but these errors were encountered: