-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix: Include <features.h> in wasi/api.h to define _Noreturn in C++ mode #24420
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
base: main
Are you sure you want to change the base?
Conversation
What works is
telling me emscripten/system/lib/libc/musl/include/features.h Lines 38 to 43 in 9cc922a
I see this also helps with
emscripten/system/lib/libc/musl/include/stdlib.h Lines 46 to 51 in 9cc922a
|
cc @sbc100 I am guessing a similar fix goes here too ? https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/headers/public/wasi/api.h |
ahh there is some failure I suppose. The feature.h, I was interested in is this https://github.com/emscripten-core/emscripten/blob/9cc922aff5f2fcac6f6f5ff375faf86fb8cc964e/system/lib/libc/musl/include/features.h but I geuss the one being fetched is not the public one (I guess the internal one) Maybe we can not include features.h and just take care of _NoReturn separately ? Not sure I should touch |
The internal musl headers such as How are you constructing your sysroot? Are you perhaps copying the files directly from the |
Yeah that's not what I intended to do. I just wanted to include the features.h that sysroot has to provide (seems like its this file https://github.com/emscripten-core/emscripten/blob/9cc922aff5f2fcac6f6f5ff375faf86fb8cc964e/system/lib/libc/musl/include/features.h) I just want to use features.h that "sysroot/include" provided just like other files are including.
So yeah we use emsdk, activate 3.173 that we're using currently and then we have this
And we preload it in our cmake
which produces the xcpp.data and hence xeus-cpp-lite has access to all standard headers in jupyterlite |
Technically the problem starts from here
emscripten/system/lib/libc/musl/include/stdio.h Lines 4 to 12 in 9cc922a
|
So are you still having this issue, even with the correct features.h? The minimal reproducer above doesn't fail for me when I build locally. (BTW, is there some reason you are still using emscripten 3.1.73 rather than the latest version?) |
Are you able to reproduce the issue with emcc itself? Or is this limited to the browser environment you have built? |
Yess, this works (see that I've added features.h below)
but what I pasted above doesn't work.
I haven't tried this yet (can give it a shot soon) but think about it. We're simply running clang-repl in the browser here (through building llvm against emscripten .... which gives us libclangInterpreter.a which we use) So what defined This can be simply seen through the link if you would like to try it out (https://compiler-research.org/xeus-cpp/lab/index.html)
emscripten/system/lib/libc/musl/include/features.h Lines 38 to 43 in 9cc922a
And I see it being put to use in stdlib.h, stdio.h and other files using |
Technically there shouldn't be no difference. But yeah there's nothing defining _Noreturn for us here correct ? This would fail for the native clang-repl case too isn't it
|
Because the whole ecosystem for xeus-cpp-lite through Jupyterlite depends on emscripten-forge ( see docs here https://emscripten-forge.org/) So Emscripten-forge contains conda recipes for the emscripten-wasm32 platform (but unlike pyodide isn't restricted to python packages and extends to c++/c/rust packages too) Possibly check the llvm recipe here (https://github.com/emscripten-forge/recipes/blob/main/recipes/recipes_emscripten/llvm/recipe.yaml) So yeah the all packages on main are currently being built against a slightly patched emsdk 3.1.73 |
The default for clang and emcc must be C11 or above since that code works fine:
So I guess you implementation of the compiler must have different defaults somehow? |
Actually clang seems to include
|
Wait so my thinking here would be that clang-repl considers the inputs to be c++ based And this is how features.h is helping i) if you see how stdlib.h that uses _Noreturn does it
ii) and features.h has
|
So I guess this is some kind of bug in clang-repl where it doesn't recognize |
My thinking here was .... similar to the above
But its including features.h and hence |
Hmm, maybe but think about it. Let's say I paste the whole code from stdlib.h (removing the featurs.h) So I think for sure any emscripten sysroot header using _Noreturn needs features.h The same code passes perfectly when I have the header. So I think wasi/api.h using _Noreturn but not defining it is problematic here. |
But This code always works in clang:
|
But emscripten sysroot header are doing it (and as I showed above, they won't work without it) Anyways thanks for the back and forth here. I need to get back to the drawing board and think if we should be able to do this directly as you say. |
If you can show and example that fails in regular clang or emcc then clearly we would need to fix on our end. If it only fails in clang-repl than that would suggest a bug in clang-repl instead. |
Hi,
I maintain xeus-cpp-lite, a Jupyter Kernel that allows users to run C++ directly in the browser through Jupyterlite
Feel free to try it out here https://compiler-research.org/xeus-cpp/lab/index.html (check demo notebook for what all can be achieved)
i) trying to include wasi/api.h fails with
ii) Looking into api.h and pasting the code from there into the cell and running it, I observe this is the minimal block replicating the error
Gives the same error