Skip to content

Can't compile with emscripten on windows (rust.metadata.bin) The end of the file was unexpectedly encountered #68146

Open
@Zazck

Description

The following output shows a new project without modification but compilation fails

D:\Code>D:\toolchain\emsdk\emsdk_env.bat
Adding directories to PATH:
PATH += D:\toolchain\emsdk
PATH += D:\toolchain\emsdk\upstream\emscripten
PATH += D:\toolchain\emsdk\node\12.9.1_64bit\bin
PATH += D:\toolchain\emsdk\python\2.7.13.1_64bit\python-2.7.13.amd64
PATH += D:\toolchain\emsdk\java\8.152_64bit\bin

Setting environment variables:
EMSDK = D:/toolchain/emsdk
EM_CONFIG = C:\Users\sekai\.emscripten
EMSDK_NODE = D:\toolchain\emsdk\node\12.9.1_64bit\bin\node.exe
EMSDK_PYTHON = D:\toolchain\emsdk\python\2.7.13.1_64bit\python-2.7.13.amd64\python.exe
JAVA_HOME = D:\toolchain\emsdk\java\8.152_64bit


D:\Code>cargo new rust-emscripten-test
     Created binary (application) `rust-emscripten-test` package

D:\Code>cd rust-emscripten-test

D:\Code\rust-emscripten-test>cargo build --target=wasm32-unknown-emscripten
   Compiling rust-emscripten-test v0.1.0 (D:\Code\rust-emscripten-test)
error: linking with `emcc.bat` failed: exit code: 1
  |
  = note: "cmd" "/c" "emcc.bat" "-s" "DISABLE_EXCEPTION_CATCHING=0" "-L" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.1bjuck14l0ffwfns.rcgu.o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.1q3di4gz2b9t8zn5.rcgu.o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.1ykwen4cd5q90e52.rcgu.o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.4ossifeikpvnv8oq.rcgu.o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.56kwdmqbw2cm8id5.rcgu.o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.5gq8h1mxltrihvjq.rcgu.o" "-o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.js" "-s" "EXPORTED_FUNCTIONS=[\"_main\",\"_rust_eh_personality\"]" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.41vpw4plt3ujpvww.rcgu.o" "-O0" "--memory-init-file" "0" "-g4" "-s" "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]" "-L" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps" "-L" "D:\\Code\\rust-emscripten-test\\target\\debug\\deps" "-L" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libstd-b6414ae168385702.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libpanic_unwind-efbc2c947951b8cc.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libhashbrown-b177382d9a04ffbe.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\librustc_std_workspace_alloc-ba7d2244d33447d5.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libbacktrace-39569dc87e4ea301.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\librustc_demangle-f83165e777dccb8d.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libunwind-10b085de263b1750.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libcfg_if-9a4a22edf44da957.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\liblibc-68fabc677efa98de.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\liballoc-026dc0061b48e8b6.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\librustc_std_workspace_core-7bf75bb619341145.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libcore-ef54709e300503ed.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libcompiler_builtins-4ed27d8420cb4abc.rlib" "-l" "c" "-s" "ERROR_ON_UNDEFINED_SYMBOLS=1" "-s" "ASSERTIONS=1" "-s" "ABORTING_MALLOC=0" "-Wl,--fatal-warnings"
  = note: shared:WARNING: ignoring unsupported linker flag: `--fatal-warnings`
          no symbols
          D:/toolchain/emsdk/upstream/bin\llvm-nm.exe: error: C:\Users\sekai\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\wasm32-unknown-emscripten\lib\libpanic_unwind-efbc2c947951b8cc.rlib(rust.metadata.bin) The end of the file was unexpectedly encountered

          Traceback (most recent call last):
            File "D:\toolchain\emsdk\upstream\emscripten\emcc.py", line 3748, in <module>
              sys.exit(run(sys.argv))
            File "D:\toolchain\emsdk\upstream\emscripten\emcc.py", line 1993, in run
              ensure_archive_index(input_file)
            File "D:\toolchain\emsdk\upstream\emscripten\emcc.py", line 476, in ensure_archive_index
              stdout = run_process([shared.LLVM_NM, '--print-armap', archive_file], stdout=PIPE).stdout
            File "D:\toolchain\emsdk\upstream\emscripten\tools\shared.py", line 195, in run_process
              result.check_returncode()
            File "D:\toolchain\emsdk\upstream\emscripten\tools\shared.py", line 168, in check_returncode
              raise Py2CalledProcessError(returncode=self.returncode, cmd=self.args, output=self.stdout, stderr=self.stderr)
          tools.shared.Py2CalledProcessError: Command '['D:/toolchain/emsdk/upstream/bin\\llvm-nm.exe', '--print-armap', 'C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libpanic_unwind-efbc2c947951b8cc.rlib']' returned non-zero exit status 1


error: aborting due to previous error

error: could not compile `rust-emscripten-test`.

To learn more, run the command again with --verbose.

emcc works fine with pure C hello world example

D:\Code\rust-emscripten-test>emcc ./hello_world.c
cache:INFO: generating system library: libcompiler_rt.a... (this will be cached in "C:\Users\sekai\.emscripten_cache\wasm-obj\libcompiler_rt.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libc-wasm.a... (this will be cached in "C:\Users\sekai\.emscripten_cache\wasm-obj\libc-wasm.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libdlmalloc.a... (this will be cached in "C:\Users\sekai\.emscripten_cache\wasm-obj\libdlmalloc.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libpthread_stub.a... (this will be cached in "C:\Users\sekai\.emscripten_cache\wasm-obj\libpthread_stub.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libc_rt_wasm.a... (this will be cached in "C:\Users\sekai\.emscripten_cache\wasm-obj\libc_rt_wasm.a" for subsequent builds)
cache:INFO:  - ok
cache:INFO: generating system library: libsockets.a... (this will be cached in "C:\Users\sekai\.emscripten_cache\wasm-obj\libsockets.a" for subsequent builds)
cache:INFO:  - ok

D:\Code\rust-emscripten-test>node a.out.js
Hello world!
rustc 1.40.0 (73528e339 2019-12-16)
binary: rustc
commit-hash: 73528e339aae0f17a15ffa49a8ac608f50c6cf14
commit-date: 2019-12-16
host: x86_64-pc-windows-msvc
release: 1.40.0
LLVM version: 9.0
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 1.39.5
clang version 10.0.0 (Cswircachegitchromium.googlesource.com-external-github.com-llvm-llvm--project be2b7ea89ab43d6827634fbdbbd2661e1f242527)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:/toolchain/emsdk/upstream/bin
shared:INFO: (Emscripten: Running sanity checks)

verbose output:

D:\Code\rust-emscripten-test>cargo build --target=wasm32-unknown-emscripten --verbose
   Compiling rust-emscripten-test v0.1.0 (D:\Code\rust-emscripten-test)
     Running `rustc --edition=2018 --crate-name rust_emscripten_test src\main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=0017e6a98f95d3ef --out-dir D:\Code\rust-emscripten-test\target\wasm32-unknown-emscripten\debug\deps --target wasm32-unknown-emscripten -C incremental=D:\Code\rust-emscripten-test\target\wasm32-unknown-emscripten\debug\incremental -L dependency=D:\Code\rust-emscripten-test\target\wasm32-unknown-emscripten\debug\deps -L dependency=D:\Code\rust-emscripten-test\target\debug\deps`
error: linking with `emcc.bat` failed: exit code: 1
  |
  = note: "cmd" "/c" "emcc.bat" "-s" "DISABLE_EXCEPTION_CATCHING=0" "-L" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.1bjuck14l0ffwfns.rcgu.o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.1q3di4gz2b9t8zn5.rcgu.o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.1ykwen4cd5q90e52.rcgu.o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.4ossifeikpvnv8oq.rcgu.o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.56kwdmqbw2cm8id5.rcgu.o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.5gq8h1mxltrihvjq.rcgu.o" "-o" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.js" "-s" "EXPORTED_FUNCTIONS=[\"_main\",\"_rust_eh_personality\"]" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps\\rust_emscripten_test.41vpw4plt3ujpvww.rcgu.o" "-O0" "--memory-init-file" "0" "-g4" "-s" "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]" "-L" "D:\\Code\\rust-emscripten-test\\target\\wasm32-unknown-emscripten\\debug\\deps" "-L" "D:\\Code\\rust-emscripten-test\\target\\debug\\deps" "-L" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libstd-b6414ae168385702.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libpanic_unwind-efbc2c947951b8cc.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libhashbrown-b177382d9a04ffbe.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\librustc_std_workspace_alloc-ba7d2244d33447d5.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libbacktrace-39569dc87e4ea301.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\librustc_demangle-f83165e777dccb8d.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libunwind-10b085de263b1750.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libcfg_if-9a4a22edf44da957.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\liblibc-68fabc677efa98de.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\liballoc-026dc0061b48e8b6.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\librustc_std_workspace_core-7bf75bb619341145.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libcore-ef54709e300503ed.rlib" "C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libcompiler_builtins-4ed27d8420cb4abc.rlib" "-l" "c" "-s" "ERROR_ON_UNDEFINED_SYMBOLS=1" "-s" "ASSERTIONS=1" "-s" "ABORTING_MALLOC=0" "-Wl,--fatal-warnings"
  = note: shared:WARNING: ignoring unsupported linker flag: `--fatal-warnings`
          no symbols
          D:/toolchain/emsdk/upstream/bin\llvm-nm.exe: error: C:\Users\sekai\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\wasm32-unknown-emscripten\lib\libpanic_unwind-efbc2c947951b8cc.rlib(rust.metadata.bin) The end of the file was unexpectedly encountered

          Traceback (most recent call last):
            File "D:\toolchain\emsdk\upstream\emscripten\emcc.py", line 3748, in <module>
              sys.exit(run(sys.argv))
            File "D:\toolchain\emsdk\upstream\emscripten\emcc.py", line 1993, in run
              ensure_archive_index(input_file)
            File "D:\toolchain\emsdk\upstream\emscripten\emcc.py", line 476, in ensure_archive_index
              stdout = run_process([shared.LLVM_NM, '--print-armap', archive_file], stdout=PIPE).stdout
            File "D:\toolchain\emsdk\upstream\emscripten\tools\shared.py", line 195, in run_process
              result.check_returncode()
            File "D:\toolchain\emsdk\upstream\emscripten\tools\shared.py", line 168, in check_returncode
              raise Py2CalledProcessError(returncode=self.returncode, cmd=self.args, output=self.stdout, stderr=self.stderr)
          tools.shared.Py2CalledProcessError: Command '['D:/toolchain/emsdk/upstream/bin\\llvm-nm.exe', '--print-armap', 'C:\\Users\\sekai\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\wasm32-unknown-emscripten\\lib\\libpanic_unwind-efbc2c947951b8cc.rlib']' returned non-zero exit status 1


error: aborting due to previous error

error: could not compile `rust-emscripten-test`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name rust_emscripten_test src\main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=0017e6a98f95d3ef --out-dir D:\Code\rust-emscripten-test\target\wasm32-unknown-emscripten\debug\deps --target wasm32-unknown-emscripten -C incremental=D:\Code\rust-emscripten-test\target\wasm32-unknown-emscripten\debug\incremental -L dependency=D:\Code\rust-emscripten-test\target\wasm32-unknown-emscripten\debug\deps -L dependency=D:\Code\rust-emscripten-test\target\debug\deps` (exit code: 1)

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.O-emscriptenTarget: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL!O-wasmTarget: WASM (WebAssembly), http://webassembly.org/O-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions