WebAssembly / wasi-libc

WASI libc implementation for WebAssembly
https://wasi.dev
Other
861 stars 203 forks source link

compiling cpp module with --target=wasm32-wasi results in fatal error: 'setjmp.h' file not found #432

Open djabi opened 4 years ago

djabi commented 4 years ago

Compiling a simple module that touches std namespace will cause /opt/wasi-sdk/share/wasi-sysroot/include/c++/v1/setjmp.h:34:15: fatal error: 'setjmp.h' file not found The same code works w/o using -fmodule and without import header. I can reproduce this on both Ubuntu 20.04 and MacOS 10.15.7. Here is the module source file foo.cpp:

foo.cpp:

module;
import <string>
export module foo;

I'm using the precompiles wasi sdk https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-11/wasi-sdk_11.0_amd64_ubuntu20.04.deb on ubunty 20.04. Installed with $ sudo apt install ./wasi-sdk_11.0_amd64_ubuntu20.04.deb $ sudo apt install libncurses5

x@pirin:~/setjmp_bug$ /opt/wasi-sdk/bin/clang++ -v -std=c++20 -fmodules --precompile -c foo.cpp -o foo.pcm clang version 10.0.0 (https://github.com/llvm/llvm-project d32170dbd5b0d54436537b6b75beaf44324e0c28) Target: wasm32-unknown-wasi Thread model: posix InstalledDir: /opt/wasi-sdk/bin (in-process) "/opt/wasi-sdk/bin/clang-10" -cc1 -triple wasm32-unknown-wasi -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name foo.cpp -mrelocation-model static -mthread-model posix -mframe-pointer=none -fno-rounding-math -masm-verbose -mconstructor-aliases -target-cpu generic -fvisibility hidden -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /opt/wasi-sdk/lib/clang/10.0.0 -isysroot /opt/wasi-sdk/share/wasi-sysroot -internal-isystem /opt/wasi-sdk/share/wasi-sysroot/include/wasm32-wasi/c++/v1 -internal-isystem /opt/wasi-sdk/share/wasi-sysroot/include/c++/v1 -internal-isystem /opt/wasi-sdk/lib/clang/10.0.0/include -internal-isystem /opt/wasi-sdk/share/wasi-sysroot/include/wasm32-wasi -internal-isystem /opt/wasi-sdk/share/wasi-sysroot/include -std=c++20 -fdeprecated-macro -fdebug-compilation-dir /home/x/setjmp_bug -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fmodules -fimplicit-module-maps -fmodules-cache-path=/tmp/org.llvm.clang.x/ModuleCache -fmodules-validate-system-headers -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fno-common -fdiagnostics-show-option -fcolor-diagnostics -o foo.pcm -x c++ foo.cpp clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target wasm32-wasi ignoring nonexistent directory "/opt/wasi-sdk/share/wasi-sysroot/include/wasm32-wasi/c++/v1" ignoring nonexistent directory "/opt/wasi-sdk/share/wasi-sysroot/include/wasm32-wasi"

include "..." search starts here:

include <...> search starts here:

/opt/wasi-sdk/share/wasi-sysroot/include/c++/v1 /opt/wasi-sdk/lib/clang/10.0.0/include /opt/wasi-sdk/share/wasi-sysroot/include End of search list. clang -cc1 version 10.0.0 based upon LLVM 10.0.0 default target wasm32-wasi ignoring nonexistent directory "/opt/wasi-sdk/share/wasi-sysroot/include/wasm32-wasi/c++/v1" ignoring nonexistent directory "/opt/wasi-sdk/share/wasi-sysroot/include/wasm32-wasi"

include "..." search starts here:

include <...> search starts here:

/opt/wasi-sdk/share/wasi-sysroot/include/c++/v1 /opt/wasi-sdk/lib/clang/10.0.0/include /opt/wasi-sdk/share/wasi-sysroot/include End of search list. While building module 'std' imported from foo.cpp:2: In file included from :20: /opt/wasi-sdk/share/wasi-sysroot/include/c++/v1/setjmp.h:34:15: fatal error: 'setjmp.h' file not found

include_next

          ^~~~~~~~~~

foo.cpp:2:8: fatal error: could not build module 'std' import "string"


2 errors generated.
sbc100 commented 4 years ago

The wask-sdk does not support setjmp or other non-local control flow concepts (such as C++ exceptions) yet because WebAssembly does not yet support such things.

There are several proposals in the works that would enable these things, and if/when they get to certain point in the process wask-sdk/wask-libc will add support for setjmp.

sbc100 commented 4 years ago

Apologies, on re-reading this does look like something that could probably be fixed. Most likely the correct solution is to patch libc++ headers to avoid including c++/v1/setjmp.h. We should also probably remove that file from the SDK

djabi commented 4 years ago

I was about to answer to your reply. Correct, I'm not trying to use set jump or exceptions. The code just fails to compile when using modules and std imports. It compiles with only modules use or std imports but not with both. I tried to supply setjmp.h from somewhere else but it brings more issues. cheers!

ghost commented 3 years ago

Hello, I am face to the same issue, just FYI : At least \wasi-sdk-12\wasi-sysroot\include\c++\v1\module.modulemap export some module like thread, csignal, setjmp_h, csetjmp, atomic, barrier, future, latch and semaphore which is not supported in WAsm/WASI

Thks, Ghis

calvin2021y commented 2 years ago

https://github.com/WebAssembly/WASI/issues/490

calvin2021y commented 2 years ago

https://github.com/WebAssembly/exception-handling/issues/179

abrown commented 1 year ago

@djabi: is this still an issue? I was going to recommend moving this issue over to https://github.com/WebAssembly/wasi-libc in order to include a stubbed-out version of setjmp.h but perhaps like @sbc100 mentions something needs to be done here?

paulcdejean commented 1 year ago

I'm still getting this error.


error: failed to run custom build command for `wasmtime-runtime v9.0.3`

Caused by:
  process didn't exit successfully: `C:\Users\Paul Dejean\Documents\rustburn\target\release\build\wasmtime-runtime-3fca1f717556e79b\build-script-build` (exit code: 1)
  --- stdout
  cargo:rerun-if-changed=src/helpers.c
  TARGET = Some("wasm32-wasi")
  OPT_LEVEL = Some("s")
  HOST = Some("x86_64-pc-windows-msvc")
  cargo:rerun-if-env-changed=CC_wasm32-wasi
  CC_wasm32-wasi = None
  cargo:rerun-if-env-changed=CC_wasm32_wasi
  CC_wasm32_wasi = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CFLAGS_wasm32-wasi
  CFLAGS_wasm32-wasi = None
  cargo:rerun-if-env-changed=CFLAGS_wasm32_wasi
  CFLAGS_wasm32_wasi = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  running: "clang" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-wasi" "-Wall" "-Wextra" "-DCFG_TARGET_OS_wasi" "-DCFG_TARGET_ARCH_wasm32" "-o" "C:\\Users\\Paul Dejean\\Documents\\rustburn\\target\\wasm32-wasi\\release\\build\\wasmtime-runtime-2648d1ef287d276f\\out\\src/helpers.o" "-c" "src/helpers.c"
  cargo:warning=src/helpers.c:1:10: fatal error: 'setjmp.h' file not found
  cargo:warning=#include <setjmp.h>
  cargo:warning=         ^~~~~~~~~~
  cargo:warning=1 error generated.
  exit code: 1

  --- stderr

  error occurred: Command "clang" "-Os" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-wasi" "-Wall" "-Wextra" "-DCFG_TARGET_OS_wasi" "-DCFG_TARGET_ARCH_wasm32" "-o" "C:\\Users\\Paul Dejean\\Documents\\rustburn\\target\\wasm32-wasi\\release\\build\\wasmtime-runtime-2648d1ef287d276f\\out\\src/helpers.o" "-c" "src/helpers.c" with args "clang" did not execute successfully (status code exit code: 1).
abrown commented 1 year ago

@paulcdejean, I don't think what you're observing is the same thing. It looks like you are trying to compile Wasmtime (src/helpers.c) targeting wasm32-wasi but that is not going to work: as mentioned here Wasmtime expects to JIT-compile WebAssembly, which isn't really easy (possible?) to do from within WebAssembly. Here's more discussion on that: https://github.com/bytecodealliance/wasmtime/issues/6504, https://github.com/bytecodealliance/wasmtime/issues/6611.

I guess I really need to know if this is still a problem for general C/C++ code that we do expect to compile to WebAssembly.

sporniket commented 11 months ago

I guess I am experiencing this problem, trying to build yices2 : https://github.com/sporniket/yices2-built-with-wasi-sdk

I end up with "no rule to make 'setjmp.h' required by xxx"