Add experimental support for C++ exceptions#590
Add experimental support for C++ exceptions#590alexcrichton merged 2 commits intoWebAssembly:mainfrom
Conversation
This commit adds initial configuration support for building wasi-sdk with support for C++ exceptions in WebAssembly. A small test is included which is exercised in CI at this time, but otherwise this does not update CI to actually ship sdk builds with C++ exceptions enabled. Instead the intention here is to make it easier to test builds with support for C++ exceptions and centralize planning/development around this. The goal here is to get things compiling to the point that applications can be compiled. I haven't thoroughly tested C++ exceptions and as evident in this PR it still requires changes in LLVM. Some small logic is added here to apply a `*.patch` file to LLVM to avoid needing a new submodule fork or waiting for upstream changes. The intention is that this `*.patch` is short-lived once the changes are officially merged into LLVM itself. The `*.patch` included here contains llvm/llvm-project#168449 as well as another minor edit I found was necessary to get things compiling locally. Given the discussion on that PR it looks like once LLVM is updated with that merged the extra part of the `*.patch` won't be necessary. This PR notably does not enable shared libraries when exceptions are enabled. I don't know enough about how things are supposed to work to be able to fully diagnose the compilation errors I'm seeing if shared libraries are enabled. This is something I'd hope would be fixed before actually shipping exceptions support. This PR then additionally folds in [this gist][gist] for various bits of build logic to this repository itself. Finally, this PR includes some documentation about the current status of exceptions and links to various tracking issues too. [gist]: https://gist.github.com/yerzham/302efcec6a2e82c1e8de4aed576ea29d
| USES_TERMINAL_CONFIGURE ON | ||
| USES_TERMINAL_BUILD ON | ||
| USES_TERMINAL_INSTALL ON | ||
| PATCH_COMMAND |
There was a problem hiding this comment.
PATCH_COMMAND runs unconditionally even when exceptions are disabled.
Consider:
if(WASI_SDK_EXCEPTIONS)
set(patch_cmd PATCH_COMMAND ${CMAKE_COMMAND} -E chdir .. bash -c "...")
else()
set(patch_cmd "")
endif()
There was a problem hiding this comment.
As this fixes a clear mistake (use windows dll decoration by default, thus also on wasm) the fix could be unconditional. The assembly.h part will become unnecessary (although still correct) in future llvm versions.
There was a problem hiding this comment.
Yeah my rough intent here is to simulate future-and-coming LLVM which has this patch unconditionally. In that sense the defines/configuration/etc should handle the build-for-exceptions-or-not, and it's nice otherwise to have the guarantee of building the exact same source just in different ways otherwise.
| USES_TERMINAL_CONFIGURE ON | ||
| USES_TERMINAL_BUILD ON | ||
| USES_TERMINAL_INSTALL ON | ||
| PATCH_COMMAND |
There was a problem hiding this comment.
As this fixes a clear mistake (use windows dll decoration by default, thus also on wasm) the fix could be unconditional. The assembly.h part will become unnecessary (although still correct) in future llvm versions.
|
Would it be possible to upload exception-ful WASI SDK as a perhaps unstable tag? I would like to start using it in YoWASP ASAP, but the overhead of having to build my own copy of the SDK first means I can't really justify it at the moment. It doesn't need to be official or supported, just built and available for a download. |
|
I tested doing that here where all those artifacts have C++ exceptions enabled, would that suffice for testing? |
|
Yes, that's great! I will report when/if I have done so. |
|
@alexcrichton I was already able to use your published version to upgrade my pipeline to support C++ exceptions (and all in one day) - thank you so much! |
This commit adds initial configuration support for building wasi-sdk with support for C++ exceptions in WebAssembly. A small test is included which is exercised in CI at this time, but otherwise this does not update CI to actually ship sdk builds with C++ exceptions enabled. Instead the intention here is to make it easier to test builds with support for C++ exceptions and centralize planning/development around this.
The goal here is to get things compiling to the point that applications can be compiled. I haven't thoroughly tested C++ exceptions and as evident in this PR it still requires changes in LLVM. Some small logic is added here to apply a
*.patchfile to LLVM to avoid needing a new submodule fork or waiting for upstream changes. The intention is that this*.patchis short-lived once the changes are officially merged into LLVM itself.The
*.patchincluded here contains llvm/llvm-project#168449 as well as another minor edit I found was necessary to get things compiling locally. Given the discussion on that PR it looks like once LLVM is updated with that merged the extra part of the*.patchwon't be necessary.This PR notably does not enable shared libraries when exceptions are enabled. I don't know enough about how things are supposed to work to be able to fully diagnose the compilation errors I'm seeing if shared libraries are enabled. This is something I'd hope would be fixed before actually shipping exceptions support.
This PR then additionally folds in this gist for various bits of build logic to this repository itself.
Finally, this PR includes some documentation about the current status of exceptions and links to various tracking issues too.