rustc fails to compile to asmjs on Windows #38489

Closed
cramertj opened this Issue Dec 20, 2016 · 9 comments

Projects

None yet

6 participants

@cramertj
Contributor

After following the steps in the "Compiling to the web with Rust and Emscripten" guide, running rustc --target=asmjs-unknown-emscripten hello.rs gives the following output:

λ rustc --target=asmjs-unknown-emscripten hello.rs | clip
error: could not exec the linker `emcc`: The system cannot find the file specified. (os error 2)
  |
  = note: "emcc" "-L" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib" "hello.0.o" "-o" "hello.js" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib\\libstd-17342542cc541012.rlib" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib\\librand-46ed9b788a6928f6.rlib" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib\\libpanic_unwind-f78756b576499725.rlib" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib\\libcollections-e32369d7fef31fbf.rlib" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib\\liballoc-24699c1ddb055eb0.rlib" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib\\liballoc_system-3e467e865c8fa572.rlib" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib\\libunwind-11f7709e0c71505b.rlib" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib\\liblibc-60365c932e50e382.rlib" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib\\librustc_unicode-844a33a197b559a5.rlib" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib\\libcore-d9873b515905cac5.rlib" "C:\\Users\\crame\\.rustup\\toolchains\\nightly-i686-pc-windows-gnu\\lib\\rustlib\\asmjs-unknown-emscripten\\lib\\libcompiler_builtins-e428224f6caf212a.rlib" "-l" "c" "-s" "ERROR_ON_UNDEFINED_SYMBOLS=1"

error: aborting due to previous error

See kripken/emscripten#4741 for discussion. @juj believes it to be an issue with rustc invoking emcc without enabling shell expansion.

@schulzch schulzch added a commit to schulzch/rust that referenced this issue Dec 22, 2016
@schulzch schulzch Partial fix for #38489. a397add
@schulzch
Contributor
schulzch commented Dec 22, 2016 edited

Invoking emcc.bat fixes the error above, but another error pops up (see below).

@chris-morgan
Member

Here is a workaround: instead of invoking cargo build --target=asmjs-unknown-emscripten, invoke cargo rustc --target=asmjs-unknown-emscripten -- -C linker=emcc.bat.

(Wow, it takes a long time—90 seconds until it fails in optimisation for a very basic thing seems inordinate!)

@RReverser
Contributor

Same, when trying to invoke given emcc command directly, getting instead:

error: Unknown attribute kind (52)
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Invalid type for value
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Unknown attribute kind (52)
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Invalid type for value
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Unknown attribute kind (48)
error: Unknown attribute kind (52)
Traceback (most recent call last):
  File "C:\Program Files\Emscripten\emscripten\1.35.0\\emcc", line 1309, in <module>
    final = shared.Building.llvm_opt(final, link_opts, DEFAULT_FINAL)
  File "C:\Program Files\Emscripten\emscripten\1.35.0\tools\shared.py", line 1471, in llvm_opt
    assert os.path.exists(target), 'Failed to run llvm optimizations: ' + output
AssertionError: Failed to run llvm optimizations:
@RReverser
Contributor

Ah, this seems to be rather related to #38588

@schulzch
Contributor

Indeed. PR #38601 is work in progress.
Also emscripten 1.35.0 (latest pre-build binary) does not work (see llvm assertion above). I haven't had the chance to try out emscripten 1.37.0 (emsdk install sdk-incoming-64bit)

@RReverser
Contributor

@schulzch Yep, that's what was suggested in that other issue and I can confirm it works.

@schulzch
Contributor

For the sake of completeness, I finally had the time to test everything. This works for windows:

Get emscripten 1.37.0:

  1. Install VS 2013 Community (required by emscripten)
  2. "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86_amd64
  3. emsdk install sdk-incoming-64bit
  4. emsdk activate sdk-incoming-64bit

Rewire rustc to emcc.bat:

  • Workaround for rust 1.14: rustc --target=asmjs-unknown-emscripten -C linker=emcc.bat
  • Fix: PR #38601

I guess rustc should check for a minimal required emscripten version, but this is probably out of scope.

@sanxiyn sanxiyn added the A-asmjs label Dec 30, 2016
@brson brson added the A-wasm label Dec 30, 2016
@brson
Contributor
brson commented Dec 30, 2016

Thanks for the investigations and the patch @RReverser @schulzch @cramertj @chris-morgan

@bors bors added a commit that referenced this issue Dec 31, 2016
@bors bors Auto merge of #38601 - schulzch:master, r=brson
Partial fix for #38489.

Fixes script name resolution for windows by invoking `emcc.bat` instead of `emcc`, etc.

Remaining issue:
```
Traceback (most recent call last):
  File "C:\Program Files\Emscripten\emscripten\1.35.0\\emcc", line 1309, in <module>
    final = shared.Building.llvm_opt(final, link_opts, DEFAULT_FINAL)
  File "C:\Program Files\Emscripten\emscripten\1.35.0\tools\shared.py", line 1471, in llvm_opt
    assert os.path.exists(target), 'Failed to run llvm optimizations: ' + output
AssertionError: Failed to run llvm optimizations:
```
b68d329
@brson
Contributor
brson commented Jan 3, 2017

Looks like the fix is merged.

@brson brson closed this Jan 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment