cargo-web
cargo-web copied to clipboard
It says emscripten is not installed but it is!
I followed the steps here and it worked with the hello.rs to hello.js with rustc --target asmjs-unknown-emscripten hello.rs
but now I'm trying to build a yew example and it says emscripten is not installed, why?
D:\3rdparty\yew\examples\counter>"d:\Program Files\emsdk-portable-64bit\emsdk_env.bat"
Adding directories to PATH:
PATH += d:\Program Files\emsdk-portable-64bit
Setting environment variables:
EMSDK = d:/Program Files/emsdk-portable-64bit
EM_CONFIG = C:\Users\me\.emscripten
D:\3rdparty\yew\examples\counter>cargo web start
error: you don't have Emscripten installed!
Download and install emscripten from the official site: http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html
(I have to use asmjs instead of wasm to support old browsers.)
EDIT: The hello.rs example worked in the emscripten sdk folder, but when I copy the hello.rs file to another folder and start a cmd.exe there and then run rustc --target asmjs-unknown-emscripten hello.rs
I get note: 'emcc.bat' is not recognized as an internal or external command, operable program or batch file.
even though I ran emsdk_env.bat
in that shell, why?
The emcc.bat
needs to be in your PATH
for it to work, so I guess you should check whenever it really is?
Also on a side note - I'd love to have precompiled Emscripten binaries for Windows too in cargo-web
. If you (or someone else) would be interested in contributing something like that I'd be willing to help out. (Basically, we'd probably need a build script that would automatically build Emscripten on a fresh Windows 10 VM under something like Vagrant, and then perhaps a little bit of code for Windows-specific environmental setup in cargo-web
itself.)
-
It works when I also run
emsdk activate latest
, but shouldn't runningemsdk_env.bat
in a shell be enough? -
Any idea why this fails? https://github.com/DenisKolodin/yew/issues/124
-
I have no idea. Does
emsdk_env.bat
set up the PATH properly? -
That's interesting; it looks like it thinks the
main
symbol is not defined for some reason...? Docargo web build
orcargo web test
fail with the same error?
- It adds some emscripten paths to PATH but
activate
sets more.. - Yes, same error. Is it because the arg is passed without quotation marks?
ERROR:root:a problem occurred in evaluating content after a "-s", specifically EXPORTED_FUNCTIONS=[_main,_rust_eh_personality] . one possible cause of this is missing quotation marks (this depends on the shell you are running in; you may need quotation marks around the entire EXPORTED_FUNCTIONS=[_main,_rust_eh_personality] , or on an individual element)
Hmm... can you try making a new crate with cargo new --bin foobar
and then try to cargo web build
it?
That one works! So why doesn't it work with the yew examples?
Can you now try to add a Web.toml
, add a prepend-js
key (Look at cargo-web
's README on how to do it.) and try to compile that?
I added the Web.toml file next to my Cargo.toml file:
prepend-js = "prepend.js"
and the js file:
console.log("prepend");
when I build it, it returns immediately (as if the source didn't change) and when I execute it with node target\asmjs-unknown-emscripten\debug\foobar.js
it only outputs Hello world!
, not prepend
, why?
Hmmm... that might be an issue with Rust not rebuilding the project when Emscripten flags change.
Anyhow, can you just delete the target
directory and rebuild?
Ah yes, now it works!
prepend
Hello, world!
Now how does it bring us closer to a solution to the issue above?
I wanted to see whenever prepend-js
was the culprit or not (since the path to the specified .js
file is passed to Emscripten through an environment variable.) But I guess I forgot that yew
is using stdweb
0.3
which doesn't use prepend-js
yet, sorry.
Hmm... I guess you could maybe try take the yew
example which fails to compile and successively strip it down until it starts compiling?
Strip it down in what way? Where does the error even originate? Which part is passing those flags?
Start removing things as long as it still exhibits the problem. For example, delete the example code and leave an empty crate, remove yew
dependency and leave only stdweb
, etc. Once we'll know what exactly makes it stop compiling we should be able to figure out how to fix it.
But who is the one calling emcc with "-s" "EXPORTED_FUNCTIONS=[\"_main\",\"_rust_eh_personality\"]"
?
I remember I had a similar problem before where something (cargo or something else) wasn't putting quotation marks around the value of args..
Maybe it should be "-s" "EXPORTED_FUNCTIONS=\"['_main','_rust_eh_personality']\""
?
Rust is. But there must be some reason why it fails.
Is this related? https://github.com/kripken/emscripten/issues/4342
Which line of code in cargo web calls emcc with "-s" "EXPORTED_FUNCTIONS=[\"_main\",\"_rust_eh_personality\"]"
?
cargo-web
doesn't set that. Either rustc
or cargo
does.
Thanks, after talking on IRC I found out the correct quotation syntax and opened an issue: https://github.com/rust-lang/rust/issues/47909
But why does it work when I try to compile foobar
(hello world) but not with that yew example?
Shouldn't rustc also call emcc the same way for foobar
?
Yes. That's why I suggested to try to cut down that example crate from yew
so that we can maybe find out what triggers it and figure out why it happens.
Ok, and how can I print out how emcc is called when building foobar
? I tried cargo web build -vvvv
but it said only 1 verbosity level is allowed, why? With only one level, it doesn't print enough info..
This issue occurs because when there are too many arguments, rustc and emcc use a response file to get around the windows command max length, and the parsing messes this up. Explained further: https://github.com/DenisKolodin/yew/issues/124#issuecomment-379812251.
But I'm not sure about the original error. I got that and had to restart to fix it.