Skip to content

Commit

Permalink
extension: Upgrade wasmtime to v21 (zed-industries#15210)
Browse files Browse the repository at this point in the history
This PR upgrades the version of `wasmtime` and `wasmtime-wasi` in use to
v21.0.1.

We have to skip v20 because Tree-sitter also skipped it.

Here are the changes that had to be made:

### v19 -> v20

After upgrading the `wasmtime` packages to v20, I also had to run `cargo
update -p mach2` to pull in
[v0.4.2](https://github.com/JohnTitor/mach2/releases/tag/0.4.2) to fix
some compile errors.

There were a few minor API changes in `wasmtime-wasi` from
bytecodealliance/wasmtime#8228 that we needed to
account for.

### v20 -> v21

Since there isn't a Tree-sitter version that depends on `wasmtime@v20`,
we're jumping straight to v21.

The published version of Tree-sitter (v0.22.6) still depends on
`wasmtime@v19`, but there was a commit
(tree-sitter/tree-sitter@7f4a578)
later that month that upgrades the `wasmtime` dependency to v21.

We're patching Tree-sitter to that commit so we can get the new
`wasmtime` version.

The main change in v21 is that imports generated by `bindgen!` are no
longer automatically trapped
(bytecodealliance/wasmtime#8310), so we need to
add `trappable_imports: true` to our `bindgen!` calls.

Release Notes:

- N/A
  • Loading branch information
maxdeviant authored and CharlesChen0823 committed Jul 29, 2024
1 parent a0ba65c commit 319e4b5
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 184 deletions.
360 changes: 194 additions & 166 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ bitflags = "2.6.0"
blade-graphics = { git = "https://github.com/zed-industries/blade", rev = "7e497c534d5d4a30c18d9eb182cf39eaf0aaa25e" }
blade-macros = { git = "https://github.com/zed-industries/blade", rev = "7e497c534d5d4a30c18d9eb182cf39eaf0aaa25e" }
blade-util = { git = "https://github.com/zed-industries/blade", rev = "7e497c534d5d4a30c18d9eb182cf39eaf0aaa25e" }
cap-std = "3.0"
cargo_toml = "0.20"
chrono = { version = "0.4", features = ["serde"] }
clap = { version = "4.4", features = ["derive"] }
Expand Down Expand Up @@ -432,14 +431,14 @@ url = "2.2"
uuid = { version = "1.1.2", features = ["v4", "v5", "serde"] }
wasmparser = "0.201"
wasm-encoder = "0.201"
wasmtime = { version = "19.0.2", default-features = false, features = [
wasmtime = { version = "21.0.1", default-features = false, features = [
"async",
"demangle",
"runtime",
"cranelift",
"component-model",
] }
wasmtime-wasi = "19.0.2"
wasmtime-wasi = "21.0.1"
which = "6.0.0"
wit-component = "0.201"
sys-locale = "0.3.1"
Expand Down Expand Up @@ -483,6 +482,10 @@ features = [
"Win32_UI_WindowsAndMessaging",
]

[patch.crates-io]
# Patch Tree-sitter for updated wasmtime.
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "7f4a57817d58a2f134fe863674acad6bbf007228" }

[profile.dev]
split-debuginfo = "unpacked"
debug = "limited"
Expand Down
1 change: 0 additions & 1 deletion crates/extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ assistant_slash_command.workspace = true
async-compression.workspace = true
async-tar.workspace = true
async-trait.workspace = true
cap-std.workspace = true
client.workspace = true
collections.workspace = true
fs.workspace = true
Expand Down
22 changes: 9 additions & 13 deletions crates/extension/src/wasm_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,29 +159,25 @@ impl WasmHost {
}

async fn build_wasi_ctx(&self, manifest: &Arc<ExtensionManifest>) -> Result<wasi::WasiCtx> {
use cap_std::{ambient_authority, fs::Dir};

let extension_work_dir = self.work_dir.join(manifest.id.as_ref());
self.fs
.create_dir(&extension_work_dir)
.await
.context("failed to create extension work dir")?;

let work_dir_preopen = Dir::open_ambient_dir(&extension_work_dir, ambient_authority())
.context("failed to preopen extension work directory")?;
let current_dir_preopen = work_dir_preopen
.try_clone()
.context("failed to preopen extension current directory")?;
let extension_work_dir = extension_work_dir.to_string_lossy();

let perms = wasi::FilePerms::all();
let file_perms = wasi::FilePerms::all();
let dir_perms = wasi::DirPerms::all();

Ok(wasi::WasiCtxBuilder::new()
.inherit_stdio()
.preopened_dir(current_dir_preopen, dir_perms, perms, ".")
.preopened_dir(work_dir_preopen, dir_perms, perms, &extension_work_dir)
.env("PWD", &extension_work_dir)
.preopened_dir(&extension_work_dir, ".", dir_perms, file_perms)?
.preopened_dir(
&extension_work_dir,
&extension_work_dir.to_string_lossy(),
dir_perms,
file_perms,
)?
.env("PWD", &extension_work_dir.to_string_lossy())
.env("RUST_BACKTRACE", "full")
.build())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/extension/src/wasm_host/wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn new_linker(
f: impl Fn(&mut Linker<WasmState>, fn(&mut WasmState) -> &mut WasmState) -> Result<()>,
) -> Linker<WasmState> {
let mut linker = Linker::new(&wasm_engine());
wasmtime_wasi::command::add_to_linker(&mut linker).unwrap();
wasmtime_wasi::add_to_linker_async(&mut linker).unwrap();
f(&mut linker, wasi_view).unwrap();
linker
}
Expand Down
1 change: 1 addition & 0 deletions crates/extension/src/wasm_host/wit/since_v0_0_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub const MIN_VERSION: SemanticVersion = SemanticVersion::new(0, 0, 1);

wasmtime::component::bindgen!({
async: true,
trappable_imports: true,
path: "../extension_api/wit/since_v0.0.1",
with: {
"worktree": ExtensionWorktree,
Expand Down
1 change: 1 addition & 0 deletions crates/extension/src/wasm_host/wit/since_v0_0_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub const MIN_VERSION: SemanticVersion = SemanticVersion::new(0, 0, 4);

wasmtime::component::bindgen!({
async: true,
trappable_imports: true,
path: "../extension_api/wit/since_v0.0.4",
with: {
"worktree": ExtensionWorktree,
Expand Down
1 change: 1 addition & 0 deletions crates/extension/src/wasm_host/wit/since_v0_0_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub const MAX_VERSION: SemanticVersion = SemanticVersion::new(0, 0, 6);

wasmtime::component::bindgen!({
async: true,
trappable_imports: true,
path: "../extension_api/wit/since_v0.0.6",
with: {
"worktree": ExtensionWorktree,
Expand Down
1 change: 1 addition & 0 deletions crates/extension/src/wasm_host/wit/since_v0_0_7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub const MAX_VERSION: SemanticVersion = SemanticVersion::new(0, 0, 7);

wasmtime::component::bindgen!({
async: true,
trappable_imports: true,
path: "../extension_api/wit/since_v0.0.7",
with: {
"worktree": ExtensionWorktree,
Expand Down

0 comments on commit 319e4b5

Please sign in to comment.