rustc fails to compile to asmjs on Windows

Created on 20 Dec 2016  Â·  11Comments  Â·  Source: rust-lang/rust

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 https://github.com/kripken/emscripten/issues/4741 for discussion. @juj believes it to be an issue with rustc invoking emcc without enabling shell expansion.

O-asmjs O-wasm

Most helpful comment

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!)

All 11 comments

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

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!)

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:

Ah, this seems to be rather related to https://github.com/rust-lang/rust/issues/38588

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)

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

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.

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

Looks like the fix is merged.

I get the same error. Unless I run rustc from the same cmd windows I used to run emsdk activate. Running emsdk activate with --global doe not seem to change anything. This may just be how it is intended to work.

@jeffwllms Did you run emsdk activate --global in elevated cmd? That's what it would take for it to work and permanently store generated environment variables in registry.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SharplEr picture SharplEr  Â·  3Comments

Robbepop picture Robbepop  Â·  3Comments

tikue picture tikue  Â·  3Comments

dwrensha picture dwrensha  Â·  3Comments

cuviper picture cuviper  Â·  3Comments