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

Project builds in debug mode, fails with --release #31

Closed
ndarilek opened this issue Jan 2, 2018 · 10 comments
Closed

Project builds in debug mode, fails with --release #31

ndarilek opened this issue Jan 2, 2018 · 10 comments

Comments

@ndarilek
Copy link

ndarilek commented Jan 2, 2018

I'm hacking on this code. If I run:

cargo web build --target-webasm-emscripten

The project builds fine. If I run:

cargo web build --target-webasm-emscripten --release

the build fails with screens of errors, at the top of which is:

  = note: WARNING:root:emcc: cannot find library "SDL2"

The errors look like so:

          WARNING:root:object /tmp/emscripten_temp_3wyyWe_archive_contents/ncollide-cfdd2aa6ffc25dc6.ncollide0.rust-cgu.bytecode.encoded is not valid, cannot link

This is with a stock Emscripten environment under Linux (I.e. the prebuilt 1.37.27 binaries.) No other change is made in the environment beyond adding --release to the build command, and I'm using latest Rust stable.

@koute
Copy link
Owner

koute commented Jan 2, 2018

Does it work with another copy of Emscripten (e.g. from your distro's repos?)

If you build it in debug mode does it also run properly?

Does it also fail to build when compiling to asmjs?

@ndarilek
Copy link
Author

ndarilek commented Jan 2, 2018 via email

@ndarilek
Copy link
Author

ndarilek commented Jan 3, 2018 via email

@koute
Copy link
Owner

koute commented Jan 3, 2018

Hmmm... can you try to add a [profile.release] section to your Cargo.toml and try setting codegen-units = 1, and if that doesn't work then lto = true too?

@ndarilek
Copy link
Author

ndarilek commented Jan 3, 2018 via email

@koute
Copy link
Owner

koute commented Jan 3, 2018

Hmm... it should work in both debug and release modes, unless we have a bug.

You can temporairly get rid of Web.toml and try specifying it manually:

export RUSTFLAGS="-C link-arg=-s -C link-arg=USE_SDL=2"

Then compile in debug mode to verify that it does indeed work, and then you can try to compile in release mode again. You can also try to do cargo build --release --target="wasm32-unknown-emscripten" while having those RUSTFLAGS exported.

@koute
Copy link
Owner

koute commented Jan 5, 2018

@ndarilek Since I've finished what I was doing I took a look at your repository and found the reason for your issue.

The SDL2 error is a red herring. Emscripten runs uglify when building in release mode which rejects ES6+ syntax.

In your tts.rs you need to change this line:

let u = new SpeechSynthesisUtterance();

into this:

var u = new SpeechSynthesisUtterance();

(Also add a ; at the end of the speechSynthesis.speak(u) line.)

Then your code will compile in release mode.

@ndarilek
Copy link
Author

ndarilek commented Jan 5, 2018

Perfect, thanks! Just filed a Rust compiler issue this morning. I'll post this update there--would be helpful if we got a better error message.

@koute
Copy link
Owner

koute commented Jan 5, 2018

I have on my TODO list syntax checking for the JS snippets before handing it off to Emscripten so that we can avoid situations like this, but yeah, unfortunately that's mostly an Emscripten issue.

@koute
Copy link
Owner

koute commented Jan 9, 2018

So since your problem is resolved I'll close this issue; if you have any further problems feel free to create a new one.

@koute koute closed this as completed Jan 9, 2018
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