Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
djabi opened this issue Oct 21, 2020 · 10 comments

Comments

@djabi
Copy link

djabi commented Oct 21, 2020

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 <setjmp.h>
^~~~~~~~~~
foo.cpp:2:8: fatal error: could not build module 'std'
import "string"

2 errors generated.
@sbc100
Copy link
Member

sbc100 commented Oct 21, 2020

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
Copy link
Member

sbc100 commented Oct 21, 2020

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
Copy link
Author

djabi commented Oct 21, 2020

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
Copy link

ghost commented Feb 21, 2021

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

kildom referenced this issue in kildom/clang-wasi-port Jul 14, 2021
* Avoid calling `poll_oneoff` with zero subscriptions.

With WebAssembly/WASI#193 merged, WASI is moving
to make `poll_oneoff` with no arguments an error. Even though that's in
ephemeral and not yet in a snapshot, we can start to anticipate it in
libc:
 - Remove the `pause` function, since WASI has no signals and thus no
   way to ever wake it up short of having the host terminate it.
 - Make `poll` and `pselect` return `ENOTSUP` in the case of having no
   events to wait for.

* Remove `pause` from the defined-symbols.txt list.

* Fix __wasilibc_unmodified_upstream markers.

* Check for zero subscriptions, rather than zero events.

Make `poll` and `pselect` return `ENOTSUP` when asked to poll on zero
subscriptions, rather than when the systerm returns zero events.

While here, drop the `__wasilibc_unmodified_upstream` markers, which
were already pretty noisy here, and would be significantly worse with
this change.

* Add comments about the subtle relationship between nfds and nsubscriptions.

* Rewrite the comment.

* Fix code quotes.
@calvin2021y
Copy link

WebAssembly/WASI#490

@calvin2021y
Copy link

@abrown
Copy link
Collaborator

abrown commented Mar 13, 2023

@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
Copy link

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
Copy link
Collaborator

abrown commented Jun 22, 2023

@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: bytecodealliance/wasmtime#6504, bytecodealliance/wasmtime#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.

@abrown abrown transferred this issue from WebAssembly/wasi-sdk Aug 8, 2023
sporniket added a commit to sporniket/yices2-built-with-wasi-sdk that referenced this issue Dec 12, 2023
@sporniket
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants