Adds a new CMake option, defaulting to `ON` so existing builds are
unaffected. When set to `OFF`, `wasi-libc` is built with
`-DBUILD_SHARED=OFF` (its existing `if (NOT BUILD_SHARED)` block then
short-circuits the per-target `set(SHARED ON)` for
`wasm32-wasi`/`wasm32-wasip1`), and the `libcxx`/`libcxxabi`/`libunwind`
invocations no longer use `${pic}` directly for their `*_ENABLE_SHARED`
flags — they go through a new local `shared` variable that AND's
`WASI_SDK_BUILD_SHARED` with `${pic}`.
Motivation: downstream consumers that build wasi-sdk from source as part
of a larger toolchain pipeline (in our case, Firefox's build system)
don't ship or link against shared sysroot artifacts. The current code
path provides no way to opt out, so we've been patching locally. The
existing comment in `wasi-sdk-sysroot.cmake` notes shared libraries
aren't supported with LTO; this doesn't change that default, it just
exposes the same toggle for non-LTO builds too.
A `static` entry is added to the `build-only-sysroot` CI matrix to
exercise the OFF path.
This commit is a refactor of how the test suite in this repository is
specified. Previously an all-encompassing `testcase.sh` script would run
all tests and assert various properties using various scripts and files
that were present throughout the test suite. This has a number of
downsides:
* With CMake configuration it's not a fan of using `glob` to discover
tests.
* Using scripts is generally not that portable as commands can differ
between platforms or be missing entirely (e.g. Windows).
* The current "filter" scripts are pretty brittle and often need changes
with newer Wasmtime versions. For example some tests don't pass with
more recent Wasmtime versions due to output changes.
Instead tests are now specified manually in `CMakeLists.txt` rather than
globbed up, and various options are plumbed through to CTest in CMake.
This makes the tests literally just a single invocation of `wasmtime`
where CTest has various assertions about the result of the process
execution after-the-fact. This gets all tests passing with the latest
version of Wasmtime and additionally updates CI as well.
This commit collects together some LLVM PRs, some changes in the build
configuration here, and some thoughts from #565 and related issues.
Specifically the changes here are:
* The patch for llvm/llvm-project#168449 is updated to its upstream
(unlanded) form.
* Patches for the (landed) llvm/llvm-project#185770 and
llvm/llvm-project#185775 are added.
* The `WASI_SDK_EXCEPTIONS` configuration is now either `ON`, `OFF`, or
`DUAL`. The default depends on the version of Clang in use, where
23.0.0+ (which isn't released officially yet) will be `DUAL` and
otherwise it's `OFF`. CI for our custom-built patched toolchain defaults
to `DUAL`.
* In `DUAL` mode libcxx is built twice into two different directories,
once with exceptions and once without. This is supported by LLVM patches
and means that Clang will select the right set of libraries based on
compiler flags.
The end result here is that the produced toolchain from this repository,
by default, supports C++ exceptions. Additionally if exceptions-related
flags are not passed then the final binary will not use C++ exceptions
nor require the wasm exception-handling proposal.
There's still follow-up work from #565, such as:
* Subjectively it feels wordy to pass `-fwasm-exceptions` vs
`-fexceptions`.
* Personally I think `-mllvm -wasm-use-legacy-eh=false` should become
the default upstream.
* Subjectively I don't think that `-lunwind` should be necessary and it
should be injected automatically with `-fwasm-exceptions` (or
`-fexceptions`).
* Shared libraries for exceptions remain disabled due to build errors I
do not personally know how to resolve.
I'll file follow-up issues for these once this has landed since they're
more minor compared to the main body of "anything works".
Closes#334Closes#565
---------
Co-authored-by: Joel Dice <joel.dice@akamai.com>
Rework of the riscv64-linux CI build to use CMake cross-compilation on a
standard `ubuntu-24.04` runner, rather than a native RISE runner.
## What changed
**`ci/docker/Dockerfile.riscv64-linux`** (new):
- Ubuntu 24.04 base — has `crossbuild-essential-riscv64` in its package
repos
- Sets `CC=riscv64-linux-gnu-gcc` / `CXX=riscv64-linux-gnu-g++` so CMake
detects cross-compilation and causes LLVM to build a native
`llvm-tblgen` first, then cross-compile the rest of the toolchain
- Sets `CARGO_TARGET_RISCV64_UNKNOWN_LINUX_GNU_LINKER` for Rust
cross-builds
- `XDG_CACHE_HOME=/tmp/cache` avoids write permission issues in the
container
**`ci/docker-build.sh`**:
- Select `ci/docker/Dockerfile.<artifact>` if it exists, fall back to
the default `ci/docker/Dockerfile`
- Make the wasmtime volume mount conditional on
`WASI_SDK_CI_SKIP_SYSROOT != 1`
**`.github/workflows/main.yml`**:
- New `riscv64-linux` matrix entry: `os: ubuntu-24.04`, `rust_target:
riscv64-unknown-linux-gnu`
- `cross_cmake_args: -DCMAKE_SYSTEM_NAME=Linux
-DCMAKE_SYSTEM_PROCESSOR=riscv64 -DWASI_SDK_LLDB=OFF`
- `WASI_SDK_CI_SKIP_SYSROOT: 1`
- Handle `cross_cmake_args` in the cmake flags step
## Why WASI_SDK_CI_SKIP_SYSROOT
The cross-compiled clang runs on riscv64, not on the x86_64 build host,
so the wasm sysroot step is skipped.
## Why WASI_SDK_LLDB=OFF
Avoids cross-compiling libedit and libxml2 in this first iteration; can
be re-enabled as a follow-up.
Closes#607
---------
Signed-off-by: Bruno Verachten <gounthar@gmail.com>
No longer use `wasm32-wasi` since Clang issues a deprecation warning
about that. This fixes the `clang` binary, by default, emitting a
warning for example in the final build.
* Update for C++ Exceptions being supported.
* Update the threading-related bits slightly.
* Indicate that dynamic linking works but may not be as fully tested.
* Networking works, just not on WASIp1.
This is intended to provide a known-good build of LLDB with wasm plugin
support which can exist alongside the rest of the LLVM distribution
provided by wasi-sdk.
This includes a new library, `libclang.so`, which is Clang's public C
API. This is used by tooling such as Rust's `bindgen` library to
generate bindings and can be useful when bindings are generated using a
wasi-sdk distribution.
Build `wasip3` target
~Requires #592~
There's a lot of failing tests currently, so we'll probably want to
rebase this PR as we pull in more recent versions of `wasi-libc` and
merge once tests pass
---------
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Co-authored-by: Alex Crichton <alex@alexcrichton.com>