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

support asmjs-unknown-emscripten and wasm32-unknown-emscripten #36

Closed
wants to merge 1 commit into from

Conversation

japaric
Copy link
Contributor

@japaric japaric commented Jan 4, 2017

cc @brson

cross build --target asmjs-unknown-emscripten and node hello.js works.

cross test --target asmjs-unknown-emscripten (and cross run) would Just Work if rustc generated executable .js files with a #!/usr/bin/env node shebang in it.

cross build --target wasm-unknown-emscripten succeeds but its output fails to run using node:

$ node target/wasm32-unknown-emscripten/release/hello.js
trying binaryen method: native-wasm
no native wasm support detected

/home/japaric/tmp/hello/target/wasm32-unknown-emscripten/release/hello.js:462
      throw ex;
      ^
no binaryen method succeeded. consider enabling more options, like interpreting, if you want that: https://github.com/kripken/emscripten/wiki/WebAssembly#binaryen-methods

Is this a regression? @brson reported that node hello.wasm.js worked way back in this thread.

@japaric
Copy link
Contributor Author

japaric commented Jan 4, 2017

@homunkulus try

@homunkulus
Copy link
Contributor

⌛ Trying commit 4de2d6e with merge 4de2d6e...

@japaric
Copy link
Contributor Author

japaric commented Jan 4, 2017

The job exceeded the maximum time limit for jobs, and has been terminated.

😢

@homunkulus
Copy link
Contributor

💔 Test failed - status-travis

@homunkulus
Copy link
Contributor

☔ The latest upstream changes (presumably 5d70947) made this pull request unmergeable. Please resolve the merge conflicts.

@japaric
Copy link
Contributor Author

japaric commented Jan 6, 2017

cross build --target wasm-unknown-emscripten succeeds but its output fails to run using node:

I figured out how to run this output using node. You need to build node from this branch and pass the --expose-wasm flag to node (hat tip to @chicoxyzzy):

$ node --expose-wasm hello-fbbdd13f43d45d24.js
trying binaryen method: native-wasm
binaryen method succeeded.
Hello, world!

The weird part is that it expects the .wasm file that Cargo also outputs to be in the same directory as the .js file ... so this doesn't work:

$ ls target/wasm32-unknown-emscripten/release/
build  deps  examples  hello.js  native

$ node --expose-wasm target/wasm32-unknown-emscripten/release/hello.js
trying binaryen method: native-wasm
failed to compile wasm module: Error: ENOENT: no such file or directory, open 'hello-fbbdd13f43d45d24.wasm'

/mnt/hello/target/wasm32-unknown-emscripten/release/hello.js:462
      throw ex;
      ^
no binaryen method succeeded. consider enabling more options, like interpreting, if you want that: https://github.com/kripken/emscripten/wiki/WebAssembly#binaryen-methods

Nor this:

$ ls target/wasm32-unknown-emscripten/release/deps/
hello-fbbdd13f43d45d24.asm.js  hello-fbbdd13f43d45d24.wasm
hello-fbbdd13f43d45d24.js      hello-fbbdd13f43d45d24.wast

$ node --expose-wasm target/wasm32-unknown-emscripten/release/deps/hello-fbbdd1
3f43d45d24.js
trying binaryen method: native-wasm
failed to compile wasm module: Error: ENOENT: no such file or directory, open 'hello-fbbdd13f43d45d24.wasm'

/mnt/hello/target/wasm32-unknown-emscripten/release/deps/hello-fbbdd13f43d45d24.js:462
      throw ex;
      ^
no binaryen method succeeded. consider enabling more options, like interpreting, if you want that: https://github.com/kripken/emscripten/wiki/WebAssembly#binaryen-methods

It has to be executed like this:

$ cd target/wasm32-unknown-emscripten/release/deps

$ node --expose-wasm hello-fbbdd13f43d45d24.js
trying binaryen method: native-wasm
binaryen method succeeded.
Hello, world!

Which pretty much precludes cargo run and cargo test from working with this target.

@chicoxyzzy
Copy link

chicoxyzzy commented Jan 6, 2017

Hi Jorge!

I haven't tried using cross yet but I think I can provide some information that might (or might not) be useful for it as well. Looks like currently it's not possible to use -o option with file target using cargo. Without -o option it's impossible to compile to HTML.

$ cargo rustc --target=wasm32-unknown-emscripten -- -o wasm.html
   Compiling wasm-test3 v0.1.0 (file:///Users/Chico/Projects/wasm-test3)
warning: ignoring specified output filename because multiple outputs were requested

warning: ignoring --out-dir flag due to -o flag.

Although it's more like emcc issue I think

@japaric
Copy link
Contributor Author

japaric commented Jan 6, 2017

@chicoxyzzy Hmm, if emcc provides another way to make it output html, you could use cargo rustc --target wasm32-unknown-emscripten -- -C link-arg=$flag-for-emcc.

@japaric
Copy link
Contributor Author

japaric commented Feb 9, 2017

rebased. This will likely not land because of timeouts but let's try anyway.

@homunkulus r+

@japaric
Copy link
Contributor Author

japaric commented Feb 9, 2017

@homunkulus r+

@homunkulus
Copy link
Contributor

📌 Commit 9491053 has been approved by japaric

@homunkulus
Copy link
Contributor

⌛ Testing commit 9491053 with merge 9491053...

@homunkulus
Copy link
Contributor

📌 Commit a866006 has been approved by japaric

@homunkulus
Copy link
Contributor

💥 Test timed out

@homunkulus
Copy link
Contributor

☔ The latest upstream changes (presumably #81) made this pull request unmergeable. Please resolve the merge conflicts.

@jan-hudec
Copy link

Since rust-lang/cargo#3954 got merged, setting

[target.asmjs-unknown-emscripten]
linker = "emcc"
runner = "node"

makes cargo test --target asmjs-unknown-emscripten work.

Per comments above, with the right version of node, the following should make cargo test --target wasm32-unknown-emscripten work too:

[target.wasm32-unknown-emscripten]
linker = "emcc"
runner = "node --expose-wasm"

@japaric
Copy link
Contributor Author

japaric commented Jun 7, 2017

Closing in favor of #106

@japaric japaric closed this Jun 7, 2017
@japaric japaric deleted the emscripten branch September 22, 2017 10:32
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

Successfully merging this pull request may close these issues.

None yet

4 participants