Problem compiling to wasm32


#1

I’m trying to build a hello world example in wasm. I’ve followed the instructions in this article and I get the following error:

Error dump

error: linking with `emcc` failed: exit code: 1
  |
  = note: "emcc" "-s" "DISABLE_EXCEPTION_CATCHING=0" "-L" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib" "/home/me/devel/non-work/sandbox-rs/browser-test/target/wasm32-unknown-emscripten/debug/deps/browser_test-857fb2f0bd318beb.0.o" "-o" "/home/me/devel/non-work/sandbox-rs/browser-test/target/wasm32-unknown-emscripten/debug/deps/browser_test-857fb2f0bd318beb.js" "-s" "EXPORTED_FUNCTIONS=[\"_main\",\"___rdl_usable_size\",\"___rdl_alloc\",\"___rdl_oom\",\"___rdl_realloc_excess\",\"___rdl_realloc\",\"___rdl_alloc_zeroed\",\"___rdl_dealloc\",\"___rdl_grow_in_place\",\"___rdl_shrink_in_place\",\"___rdl_alloc_excess\",\"_rust_eh_personality\"]" "/home/me/devel/non-work/sandbox-rs/browser-test/target/wasm32-unknown-emscripten/debug/deps/browser_test-857fb2f0bd318beb.crate.allocator.o" "-O0" "--memory-init-file" "0" "-g4" "-s" "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]" "-L" "/home/me/devel/non-work/sandbox-rs/browser-test/target/wasm32-unknown-emscripten/debug/deps" "-L" "/home/me/devel/non-work/sandbox-rs/browser-test/target/debug/deps" "-L" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libstd-2d68360a753fa4f5.rlib" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/liballoc_system-9972c7db0df95040.rlib" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/librand-ce1bc40dfee9b55f.rlib" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libpanic_unwind-429ce49a29d5b09d.rlib" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/liballoc-1ece70250e8652cf.rlib" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libstd_unicode-61b9d391a2fc6b86.rlib" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libunwind-0df7ef13535f5ed7.rlib" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/liblibc-50d360f1fe8b2e62.rlib" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libcore-c8fea11b48232c5c.rlib" "/home/me/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-emscripten/lib/libcompiler_builtins-ebe31891daed2f11.rlib" "-l" "c" "-s" "BINARYEN=1" "-s" "ERROR_ON_UNDEFINED_SYMBOLS=1"
  = note: INFO:root:generating port: binaryen_tag_version_37.txt... (this will be cached in "/home/me/.emscripten_cache/asmjs/binaryen_tag_version_37.txt" for subsequent builds)
          INFO:root:building port: binaryen
          /home/me/.emscripten_ports/binaryen/binaryen-version_37/src/wasm/wasm-s-parser.cpp: In member function ‘wasm::Expression* wasm::SExpressionWasmBuilder::makeExpression(wasm::Element&)’:
          /home/me/.emscripten_ports/binaryen/binaryen-version_37/src/wasm/wasm-s-parser.cpp:871:9: error: this statement may fall through [-Werror=implicit-fallthrough=]
                   if (!strncmp(str, "wake", strlen("wake"))) return makeAtomicWake(s);
                   ^~
          /home/me/.emscripten_ports/binaryen/binaryen-version_37/src/wasm/wasm-s-parser.cpp:873:7: note: here
                 default: abort_on(str);
                 ^~~~~~~
          cc1plus: all warnings being treated as errors
          make[2]: *** [src/wasm/CMakeFiles/wasm.dir/build.make:159: src/wasm/CMakeFiles/wasm.dir/wasm-s-parser.cpp.o] Error 1
          make[1]: *** [CMakeFiles/Makefile2:843: src/wasm/CMakeFiles/wasm.dir/all] Error 2
          make: *** [Makefile:130: all] Error 2
          ERROR:root:a problem occurred when using an emscripten-ports library. try to run    emcc --clear-ports    and then run this command again
          Traceback (most recent call last):
            File "/home/me/packages/emsdk-portable/emscripten/incoming/emcc.py", line 2615, in <module>
              run()
            File "/home/me/packages/emsdk-portable/emscripten/incoming/emcc.py", line 1416, in run
              extra_files_to_link = system_libs.get_ports(shared.Settings)
            File "/home/me/packages/emsdk-portable/emscripten/incoming/tools/system_libs.py", line 701, in get_ports
              ret += filter(lambda f: not f.endswith('.txt'), port.get(Ports, settings, shared))
            File "/home/me/packages/emsdk-portable/emscripten/incoming/tools/ports/binaryen.py", line 29, in get
              return [shared.Cache.get('binaryen_tag_' + TAG, create, what='port', extension='.txt')]
            File "/home/me/packages/emsdk-portable/emscripten/incoming/tools/cache.py", line 100, in get
              temp = creator()
            File "/home/me/packages/emsdk-portable/emscripten/incoming/tools/ports/binaryen.py", line 24, in create
              ports.build_native(os.path.join(ports.get_dir(), 'binaryen', 'binaryen-' + TAG))
            File "/home/me/packages/emsdk-portable/emscripten/incoming/tools/system_libs.py", line 689, in build_native
              subprocess.check_call(['cmake', '--build', '.'] + make_args)
            File "/usr/lib/python2.7/subprocess.py", line 186, in check_call
              raise CalledProcessError(retcode, cmd)
          subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--', '-j', '8']' returned non-zero exit status 2
          -- Building with -std=c++11
          -- Building for platform x86-64
          -- Building with -Wall
          -- Building with -Werror
          -- Building with -Wextra
          -- Building with -Wno-unused-parameter
          -- Building with -fno-omit-frame-pointer
          -- Building with -fPIC
          -- Building with -O2
          -- Building with -UNDEBUG
          -- Configuring done
          -- Generating done
          -- Build files have been written to: /home/me/.emscripten_ports/binaryen/binaryen-version_37
          [  2%] Built target cfg
          [  5%] Built target asmjs
          [ 14%] Built target support
          [ 17%] Built target ast
          [ 18%] Building CXX object src/wasm/CMakeFiles/wasm.dir/wasm-s-parser.cpp.o
          [ 22%] Built target emscripten-optimizer
          [ 65%] Built target passes

I was wondering if anyone had any advice?


#2

I’ve removed the -Werror and it seems to work (in CMakeLists), but this doesn’t seem to be a long term solution :stuck_out_tongue:


#3

Hi Derek. I’m running into a very similar issue. Could you provide some details on how to apply the temporary fix you had found?


#4

The problem is that the compiler is setting all warnings to errors, and then the code generates some warnings that terminate the build.

I can’t remember which file cmake sets -Werror, but if you grep (or ack or ag) for -Werror in the build directory, you should find it (The directory is $HOME/.emscripten_ports/binaryen/binaryen-version_37 for me, and its location will be in the output).

I’m sorry this isn’t a more accurate guide - I forgot what I did! Emscripten will probably fix this soon - I think it’s caused by new warnings in gcc.


#5

I ran into (probably) the same issue some time ago and I can second what @derekdreery recommends.
It seems to be fixed in upstream git, but as a quick fix, I did:

  • Run the first rustc, just to encounter the error
  • Edit the CMakeLists.txt in $HOME/.emscripten_ports/binaryen/binaryen-version_37
  • Search for -Werror and remove that from the build options
  • Invoke rustc again, this time it will build

I remember that the problem involves implicit-fall-through warnings for switch statements, which were rather recently introduced into GCC. The option -Werror in CMakeLists.txt turns them into a hard error.