Skip to content

Refactor wasmtime build to use crates_universe-provided wasmtime-c-api-impl crate#501

Draft
leonm1 wants to merge 16 commits intoproxy-wasm:mainfrom
leonm1:build/wasmtime
Draft

Refactor wasmtime build to use crates_universe-provided wasmtime-c-api-impl crate#501
leonm1 wants to merge 16 commits intoproxy-wasm:mainfrom
leonm1:build/wasmtime

Conversation

@leonm1
Copy link
Contributor

@leonm1 leonm1 commented Mar 2, 2026

Always uses prefixed wasmtime-c-api-impl, otherwise the prefixed implementation bitrots. Prefixes the headers in the repo rule to allow for globbing, which is not possible in a genrule.

The crates_vendor-provided wasmtime-c-api-impl provided build allows us to upgrade wasmtime solely by changing the version number in the repositories.bzl and Cargo.toml files.

Build off of #496

@leonm1 leonm1 force-pushed the build/wasmtime branch 3 times, most recently from 6bcf94e to 144d005 Compare March 2, 2026 15:19
wasmtime-c-api-macros = {git = "https://github.com/bytecodealliance/wasmtime", tag = "v24.0.0"}
# Fixes testdata build error due to missing crate_features = ["std"]
log = {version = "0.4.29", default-features = false, features = ['std']}
wasmtime-c-api-impl = {version = "24.0.0", default-features = false, features = ['cranelift', 'wasi', 'wat']}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely a wrong set of features.

At the very least, we need "runtime" feature to execute Wasm modules.

Also, we don't use "their" version of WASI, so "wasi" should be removed.

We didn't support "wat" before, so we probably shouldn't be adding it here either, since it will result in mismatch for WAT support across different Wasm engines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wasmtime runtime, gc, and std features are enabled by the c-api Cargo.toml here: https://github.com/bytecodealliance/wasmtime/blob/f18f06e6dea00a78c06913061d952b26ed700b92/crates/c-api/Cargo.toml#L25

Removed wat and wasi.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. Those are features of wasmtime-c-api-impl and not wasmtime itself...

With that in mind, we don't need default-features = false, since that crates doesn't have any.

leonm1 added 10 commits March 2, 2026 14:22
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
This reverts commit c19e738.

Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Always uses prefixed wasmtime-c-api-impl, otherwise the prefixed
implementation bitrots. Prefixes the headers in the repo rule to allow
for globbing, which is not possible in a genrule.

The crates_vendor-provided wasmtime-c-api-impl provided build allows us
to upgrade wasmtime solely by changing the version number in the
Cargo.toml file (and the corresponding repo in bazel/repositories.bzl
for the C headers).

Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
@leonm1 leonm1 requested a review from PiotrSikora March 2, 2026 19:35
Copy link
Member

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few high-level comments:

  1. Why? Looking at the changes, the benefits don't seem very obvious.
  2. Always using prefixed variant seems fine (although, I think there was a reason why it wasn't the default - perhaps something with Envoy build?), but is that something that's at all relevant with the move to Wasmtime C++ API in #503?
  3. Using wasmtime-c-api-impl and always using prefixed variant are pretty separate changes, so might be good to split them off (but if they are too intertwined and would result in a throwaway work, then we can keep this as-is).


[[package]]
name = "wasmtime-c-api-impl"
version = "24.0.6"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match the version in Cargo.toml.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly overrode semver for wasmtime-c-api-impl.

Done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... For some reason all other Wasmtime crates are still at v24.0.6 and not v24.0.0, so maybe let's stick to v24.0.6.

leonm1 added 6 commits March 3, 2026 08:39
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Signed-off-by: Matt Leon <mattleon@google.com>
Copy link
Contributor Author

@leonm1 leonm1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Looking at the changes, the benefits don't seem very obvious.

Two things:

  1. Updating wasmtime resulted in our rust_static_library in wasmtime.BUILD failing to build due to missing dependencies. With this current approach, the dependency tree is resolved by Cargo and we simply wrap it in rust_static_library. Updates which pull in new dependencies are trivial after this change and (in theory) will never require hunting down missing dependencies.
  2. For prefixing itself, using parts of the wasmtime_c_api (as opposed to the raw wasm_c_api in wasm.h / required for limits) involves a whole tree of c header files in the c-api crate. The approach we used previously, prefixing individual files via genrule, doesn't work with globs for all the required files (as bazel requires declaring all genrule outputs), so the toil and complexity of the old build would be increased significantly to support limits.

Always using prefixed variant seems fine (although, I think there was a reason why it wasn't the default - perhaps something with Envoy build?), but is that something that's at all relevant with the move to Wasmtime C++ API in #503?

Envoy build itself ran the multi runtime tests, so I don't think it required the non-prefixed version.

Using wasmtime-c-api-impl and always using prefixed variant are pretty separate changes, so might be good to split them off (but if they are too intertwined and would result in a throwaway work, then we can keep this as-is).

Ack. I'm considering this a "change how we build wasmtime" PR, which makes sense semantically. While they are separable, due to higher priority tasks on my todo list, I simply don't have a couple hours to spare to split this.


[[package]]
name = "wasmtime-c-api-impl"
version = "24.0.6"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly overrode semver for wasmtime-c-api-impl.

Done.

@PiotrSikora
Copy link
Member

Envoy build itself ran the multi runtime tests, so I don't think it required the non-prefixed version.

I don't believe that was ever the case, and I cannot find a code that would support that.

Do you have a link? If not, could you open a draft PR against Envoy (you'll need to do that anyway at some point) and verify that it builds fine with Wasmtime - it can be either this PR or off the last PR in the stacked series.

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

Successfully merging this pull request may close these issues.

2 participants