Skip to content

Commit 7a1b7cd

Browse files
authored
Implement RFC 11: Redesigning Wasmtime's APIs (#2897)
Implement Wasmtime's new API as designed by RFC 11. This is quite a large commit which has had lots of discussion externally, so for more information it's best to read the RFC thread and the PR thread.
1 parent a5a28b1 commit 7a1b7cd

File tree

233 files changed

+13289
-11937
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+13289
-11937
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ jobs:
6161
toolchain: nightly-2021-04-11
6262

6363
# Build C API documentation
64-
- run: sudo apt-get update && sudo apt-get install -y doxygen git
64+
- run: sudo apt-get update -y && sudo apt-get install -y libclang1-9 libclang-cpp9
65+
- run: curl -L https://doxygen.nl/files/doxygen-1.9.1.linux.bin.tar.gz | tar xzf -
66+
- run: echo "`pwd`/doxygen-1.9.1/bin" >> $GITHUB_PATH
6567
- run: cd crates/c-api && doxygen doxygen.conf
6668

6769
# install mdbook, build the docs, and test the docs
@@ -73,7 +75,7 @@ jobs:
7375
echo "${{ runner.tool_cache }}/mdbook/bin" >> $GITHUB_PATH
7476
cargo install --root ${{ runner.tool_cache }}/mdbook --version ${{ env.CARGO_MDBOOK_VERSION }} mdbook
7577
- run: (cd docs && mdbook build)
76-
- run: cargo build -p wasmtime
78+
- run: cargo build -p wasmtime-wasi --features wasmtime/wat
7779
- run: (cd docs && mdbook test -L ../target/debug/deps)
7880

7981
# Build Rust API documentation

Cargo.lock

Lines changed: 2 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ members = [
7777
"crates/wiggle",
7878
"crates/wiggle/generate",
7979
"crates/wiggle/macro",
80-
"crates/wiggle/wasmtime",
8180
"crates/wasi-common",
8281
"crates/wasi-common/cap-std-sync",
8382
"crates/wasi-common/tokio",

benches/instantiation.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,14 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
33
use rayon::{prelude::*, ThreadPoolBuilder};
44
use std::{path::PathBuf, process::Command};
55
use wasmtime::*;
6-
use wasmtime_wasi::{sync::WasiCtxBuilder, Wasi};
6+
use wasmtime_wasi::{sync::WasiCtxBuilder, WasiCtx};
77

8-
fn instantiate(module: &Module) -> Result<Instance> {
9-
let store = Store::new(&module.engine());
8+
fn instantiate(linker: &Linker<WasiCtx>, module: &Module) -> Result<()> {
9+
let wasi = WasiCtxBuilder::new().build();
10+
let mut store = Store::new(module.engine(), wasi);
11+
let _instance = linker.instantiate(&mut store, module)?;
1012

11-
// As we don't actually invoke Wasm code in this benchmark, we still add
12-
// the WASI context to the store as it is considered part of getting a
13-
// module that depends on WASI "ready to run".
14-
Wasi::set_context(&store, WasiCtxBuilder::new().build())
15-
.map_err(|_| anyhow::anyhow!("wasi set_context failed"))?;
16-
17-
let linker = Linker::new(&store);
18-
let instance = linker.instantiate(module)?;
19-
20-
Ok(instance)
13+
Ok(())
2114
}
2215

2316
fn benchmark_name<'a>(strategy: &InstanceAllocationStrategy) -> &'static str {
@@ -46,15 +39,16 @@ fn bench_sequential(c: &mut Criterion, modules: &[&str]) {
4639
path.push(file_name);
4740

4841
let mut config = Config::default();
49-
Wasi::add_to_config(&mut config);
5042
config.allocation_strategy(strategy.clone());
5143

5244
let engine = Engine::new(&config).expect("failed to create engine");
5345
let module = Module::from_file(&engine, &path)
5446
.expect(&format!("failed to load benchmark `{}`", path.display()));
47+
let mut linker = Linker::new(&engine);
48+
wasmtime_wasi::add_to_linker(&mut linker, |cx| cx).unwrap();
5549

5650
group.bench_function(BenchmarkId::new(benchmark_name(strategy), file_name), |b| {
57-
b.iter(|| instantiate(&module).expect("failed to instantiate module"));
51+
b.iter(|| instantiate(&linker, &module).expect("failed to instantiate module"));
5852
});
5953
}
6054
}
@@ -74,12 +68,13 @@ fn bench_parallel(c: &mut Criterion) {
7468
InstanceAllocationStrategy::pooling(),
7569
] {
7670
let mut config = Config::default();
77-
Wasi::add_to_config(&mut config);
7871
config.allocation_strategy(strategy.clone());
7972

8073
let engine = Engine::new(&config).expect("failed to create engine");
8174
let module = Module::from_file(&engine, "benches/instantiation/wasi.wasm")
8275
.expect("failed to load WASI example module");
76+
let mut linker = Linker::new(&engine);
77+
wasmtime_wasi::add_to_linker(&mut linker, |cx| cx).unwrap();
8378

8479
for threads in 1..=num_cpus::get_physical() {
8580
let pool = ThreadPoolBuilder::new()
@@ -101,7 +96,8 @@ fn bench_parallel(c: &mut Criterion) {
10196
b.iter(|| {
10297
pool.install(|| {
10398
(0..PARALLEL_INSTANCES).into_par_iter().for_each(|_| {
104-
instantiate(&module).expect("failed to instantiate module");
99+
instantiate(&linker, &module)
100+
.expect("failed to instantiate module");
105101
})
106102
})
107103
});

build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,17 @@ fn ignore(testsuite: &str, testname: &str, strategy: &str) -> bool {
218218
_ => (),
219219
},
220220
"Cranelift" => match (testsuite, testname) {
221+
// Skip all reference types tests on the old backend. The modern
222+
// implementation of reference types uses atomic instructions
223+
// for reference counts on `externref`, but the old backend does not
224+
// implement atomic instructions.
225+
("reference_types", _) if cfg!(feature = "old-x86-backend") => return true,
226+
// Skip all SIMD tests on old backend, there are instructions not
227+
// implemented there and support is generally not maintained.
228+
("simd", _) if cfg!(feature = "old-x86-backend") => return true,
221229
// No simd support yet for s390x.
222230
("simd", _) if platform_is_s390x() => return true,
223231

224-
("simd", _) if cfg!(feature = "old-x86-backend") => return true, // skip all SIMD tests on old backend.
225232
// These are new instructions that are not really implemented in any backend.
226233
("simd", "simd_i8x16_arith2")
227234
| ("simd", "simd_conversions")

ci/build-tarballs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ mkdir tmp/$api_pkgname/include
3434
mkdir tmp/$bin_pkgname
3535
cp LICENSE README.md tmp/$api_pkgname
3636
cp LICENSE README.md tmp/$bin_pkgname
37+
cp -r crates/c-api/include tmp/$api_pkgname
3738
cp crates/c-api/wasm-c-api/include/wasm.h tmp/$api_pkgname/include
38-
cp crates/c-api/include/{wasmtime,wasi}.h tmp/$api_pkgname/include
3939

4040
fmt=tar
4141
if [ "$platform" = "x86_64-windows" ]; then

cranelift/interpreter/src/interpreter.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ impl<'a> Interpreter<'a> {
4242
self.call_by_index(index, arguments)
4343
}
4444

45-
/// Call a function by its index in the [FunctionStore]; this is a proxy for [Interpreter::call].
45+
/// Call a function by its index in the [FunctionStore]; this is a proxy for
46+
/// `Interpreter::call`.
4647
pub fn call_by_index(
4748
&mut self,
4849
index: FuncIndex,
@@ -287,7 +288,7 @@ mod tests {
287288
v1 = iadd_imm v0, -1
288289
return v1
289290
}
290-
291+
291292
function %parent(i32) -> i32 {
292293
fn42 = %child(i32) -> i32
293294
block0(v0: i32):

0 commit comments

Comments
 (0)