Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
eada9fb
fix(api): Minor changes to doc comments
xdoardo Feb 28, 2025
f08cd32
fix(api): Use `BackendKind::default()` to drive the decision of the d…
xdoardo Feb 28, 2025
7aec83b
fix(api): Make `sys::default_engine()` public
xdoardo Feb 28, 2025
3b822fc
fix(c-api): Enable multiple backends to be used with in wasmer's `c-api`
xdoardo Feb 28, 2025
680f6cc
chore: Remove forgotten debug statements
xdoardo Feb 28, 2025
c859247
chore: Make linter happy
xdoardo Feb 28, 2025
e95638a
fix(c-api): Fix message
xdoardo Feb 28, 2025
2231e03
fix(c-api): rename `wasm_config_x_sys` to `wasm_config_sys_x`
xdoardo Feb 28, 2025
5651dad
fix(c-api): Fix pub re-export of `sys::*` items
xdoardo Feb 28, 2025
7fa0b25
fix(c-api): Fix feature gates
xdoardo Feb 28, 2025
ac3f868
fix(c-api): Enable matching compiler features for `cranelift`, `singl…
xdoardo Feb 28, 2025
76578fe
fix(c-api): Make `<backend>_engine_new_with_config` functions `pub(cr…
xdoardo Feb 28, 2025
5f9d8d5
fix(c-api): Make all the engines in the top-level enum visible, then …
xdoardo Feb 28, 2025
aab3893
fix(c-api): Re-instate wrongly deleted `Default` annotation for `wasm…
xdoardo Feb 28, 2025
2c31a42
fix(api): Use `module.exports()` to drive the order of `InstanceHandl…
xdoardo Mar 3, 2025
b880f76
fix(api): Make dep `wat` entail `wasmparser`
xdoardo Mar 3, 2025
af313b3
fix(v8): Fix missing null checks in `imports()`
xdoardo Mar 10, 2025
f75f5b7
fix(v8): Add proper checks when creating memory
xdoardo Mar 10, 2025
8417922
fix(v8): Correct math error in `Module::deserialize`
xdoardo Mar 10, 2025
9506911
fix(wamr): Fix missing checks in `Instance::imports()`
xdoardo Mar 10, 2025
50e0b29
fix(wamr): Bump and lock to stable version of WAMR
xdoardo Mar 10, 2025
8a475c3
fix(wamr): Implement `validate`
xdoardo Mar 10, 2025
6d97d1c
fix(wamr): Implement missing checks when instantiating memory
xdoardo Mar 10, 2025
32304e9
fix(wasmi): Implement missing checks when instantiating memory
xdoardo Mar 10, 2025
3a99583
fix(api): Don't use backend kind to drive `BackendEngine::default()`
xdoardo Mar 10, 2025
4a877b7
fix(api): Use `Cranelift`, `Singlepass`, `LLVM` and `Headless` in `Ba…
xdoardo Mar 10, 2025
933095e
fix(api/build/wamr): Don't re-download if dir is already there
xdoardo Mar 10, 2025
6fe4229
fix(api/wamr): Use default instantiation mechanism for wamr
xdoardo Mar 10, 2025
145a804
chore: Make linter happy
xdoardo Mar 10, 2025
a081049
fix(c_api): Add explicit match on `LLVM`, `Cranelift` and `Singlepass…
xdoardo Mar 10, 2025
aef9b15
fix(c_api): `compiler_headless` entails `sys`.
xdoardo Mar 10, 2025
e357770
feat(ci): Add test for C-API with v8
xdoardo Mar 11, 2025
632d73e
fix(c_api): Re-export target types from `wasmer_types`
xdoardo Mar 11, 2025
5c5ffa7
fix(c_api): Remove feature-gate for `target_lexicon` mod
xdoardo Mar 11, 2025
a70fbe8
fix(c_api): Rename `wasmer_engine_config_*` to `wasmer_backend_config_*`
xdoardo Mar 11, 2025
ebfe28f
chore: Make linter happy
xdoardo Mar 11, 2025
3d82cb2
chore: Make linter happy
xdoardo Mar 11, 2025
ec74f14
fix(c_api): Fix headless compilation
xdoardo Mar 11, 2025
2f42e6e
ci: Disable c-api+v8 tests on linux
xdoardo Mar 11, 2025
662a469
fix(api): Try adding specific clang flags in bindgen for v8 for imports
xdoardo Mar 11, 2025
a1a0550
fix(api): Try adding specific clang flags in bindgen for v8
xdoardo Mar 12, 2025
b4dfba4
fix(api): Change v8-specific clang flags for bindgen
xdoardo Mar 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ jobs:
build-cmd: "make build-capi && make build-capi-headless && make package-capi && make tar-capi",
name: "Build and test C-API",
},
{
key: capi-v8,
build-cmd: "make test-capi-v8",
name: "Build and test C-API with v8",
},
{
key: wasmer,
build-cmd: "make build-wasmer && make package-wasmer && make tar-wasmer",
Expand All @@ -511,20 +516,26 @@ jobs:
target: x86_64-unknown-linux-gnu,
exe: "",
llvm_url: "https://github.com/wasmerio/llvm-custom-builds/releases/download/18.x/llvm-linux-amd64.tar.xz",
# Unfortunately, building a shared lib of the c_api with the v8
# backend does not work, due to unsupported relocations to hidden
# symbols in wee8.
supports_v8: false
},
{
build: macos-x64,
os: macos-13,
target: x86_64-apple-darwin,
exe: "",
llvm_url: "https://github.com/wasmerio/llvm-custom-builds/releases/download/18.x/llvm-darwin-amd64.tar.xz",
supports_v8: true
},
{
build: macos-arm,
os: macos-14,
target: aarch64-apple-darwin,
exe: "",
llvm_url: "https://github.com/wasmerio/llvm-custom-builds/releases/download/18.x/llvm-darwin-aarch64.tar.xz",
supports_v8: true
},
{
build: windows-x64,
Expand All @@ -533,18 +544,21 @@ jobs:
exe: ".exe",
# For now, disable LLVM in `windows-x64.`
# llvm_url: 'https://github.com/wasmerio/llvm-custom-builds/releases/download/18.x/llvm-windows-amd64.tar.xz'
supports_v8: false
},
{
build: windows-gnu,
target: x86_64-pc-windows-gnu,
os: ubuntu-22.04,
supports_v8: false
},
{
build: linux-musl,
target: x86_64-unknown-linux-musl,
os: ubuntu-22.04,
exe: "",
container: "alpine:latest",
supports_v8: false
},
]
container: ${{ matrix.metadata.container }}
Expand Down Expand Up @@ -684,6 +698,10 @@ jobs:
TARGET: ${{ matrix.metadata.target }}
TARGET_DIR: target/${{ matrix.metadata.target }}/release
CARGO_TARGET: ${{ matrix.metadata.target }}
- name: Test C-API (v8)
shell: bash
run: ${{ matrix.build-what.build-cmd }}
if: ${{ matrix.build-what.key == 'capi-v8' && matrix.metadata.supports_v8 == true }}
- name: Build Wasmer
shell: bash
if: ${{ matrix.build-what.key == 'wasmer' && matrix.metadata.build != 'windows-gnu' }}
Expand Down
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ build-docs-capi:

build-capi:
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features wat,compiler,wasi,middlewares,webc_runner $(capi_compiler_features) --locked
--no-default-features --features wat,sys-default,compiler,wasi,middlewares,webc_runner $(capi_compiler_features) --locked

build-capi-singlepass:
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \
Expand All @@ -585,9 +585,21 @@ build-capi-llvm-universal:
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features wat,compiler,llvm,wasi,middlewares,webc_runner --locked

build-capi-v8:
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features wat,v8-default,wasi --locked

build-capi-wamr:
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features wat,wamr-default,wasi --locked

build-capi-wasmi:
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features wat,wasmi-default,wasi --locked

build-capi-jsc:
RUSTFLAGS="${RUSTFLAGS}" $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \
--no-default-features --features wat,jsc,wasi --locked
--no-default-features --features wat,jsc-default,wasi --locked

# Headless (we include the minimal to be able to run)

Expand Down Expand Up @@ -703,6 +715,10 @@ test-capi-ci: $(foreach compiler_engine,$(capi_compilers_engines),test-capi-crat
# compilers first
test-capi: build-capi package-capi test-capi-ci

test-capi-v8: build-capi-v8 package-capi test-capi-integration-v8
test-capi-wasmi: build-capi-wasmi package-capi test-capi-integration-wasmi
test-capi-wamr: build-capi-wamr package-capi test-capi-integration-wamr

test-capi-jsc: build-capi-jsc package-capi test-capi-integration-jsc

test-capi-crate-%:
Expand Down
1 change: 1 addition & 0 deletions lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ js = ["wasm-bindgen", "js-sys"]
js-default = ["js", "std", "wasm-types-polyfill"]

wasm-types-polyfill = ["wasmparser"]
wat = ["dep:wat", "wasmparser"]

jsc = ["rusty_jsc", "wasm-types-polyfill", "wasmparser"]
jsc-default = ["jsc"]
Expand Down
57 changes: 35 additions & 22 deletions lib/api/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#[cfg(feature = "wamr")]
fn build_wamr() {
use bindgen::callbacks::ParseCallbacks;
const WAMR_ZIP: &str = "https://github.com/bytecodealliance/wasm-micro-runtime/archive/0e4dffc47922bb6fcdcaed7de2a6edfe8c48a7cd.zip";
const ZIP_NAME: &str = "wasm-micro-runtime-0e4dffc47922bb6fcdcaed7de2a6edfe8c48a7cd";
const WAMR_ZIP: &str =
"https://github.com/bytecodealliance/wasm-micro-runtime/archive/refs/tags/WAMR-2.2.0.zip";
const ZIP_NAME: &str = "wasm-micro-runtime-WAMR-2.2.0";

use cmake::Config;
use std::{env, path::PathBuf};
Expand Down Expand Up @@ -36,24 +37,27 @@ fn build_wamr() {

// Cleanup tmp data from prior builds
let wamr_dir = PathBuf::from(&crate_root).join("third_party/wamr");
let zip_dir = PathBuf::from(&crate_root)
.join("third_party")
.join(ZIP_NAME);
let _ = std::fs::remove_dir_all(&wamr_dir);
let _ = std::fs::remove_dir_all(&zip_dir);

// Fetch & extract wasm-micro-runtime source
let zip = ureq::get(WAMR_ZIP).call().expect("failed to download wamr");
let mut zip_data = Vec::new();
zip.into_reader()
.read_to_end(&mut zip_data)
.expect("failed to download wamr");
zip::read::ZipArchive::new(std::io::Cursor::new(zip_data))
.expect("failed to open wamr zip file")
.extract(&zip_dir)
.expect("failed to extract wamr zip file");
let _ = std::fs::remove_dir_all(&wamr_dir);
std::fs::rename(zip_dir.join(ZIP_NAME), &wamr_dir).expect("failed to rename wamr dir");
if !wamr_dir.exists() {
let zip_dir = PathBuf::from(&crate_root).join("third_party");
let _ = std::fs::remove_dir_all(&wamr_dir);
let _ = std::fs::remove_dir_all(&zip_dir);

// Fetch & extract wasm-micro-runtime source
let zip = ureq::get(WAMR_ZIP).call().expect("failed to download wamr");
let mut zip_data = Vec::new();
zip.into_reader()
.read_to_end(&mut zip_data)
.expect("failed to download wamr");
zip::read::ZipArchive::new(std::io::Cursor::new(zip_data))
.expect("failed to open wamr zip file")
.extract(&zip_dir)
.expect("failed to extract wamr zip file");
let _ = std::fs::remove_dir_all(&wamr_dir);
std::fs::rename(zip_dir.join(ZIP_NAME), &wamr_dir)
.expect(&format!("failed to rename wamr dir: {zip_dir:?}"));
} else {
println!("cargo::rerun-if-changed={}", wamr_dir.display());
}

let wamr_platform_dir = wamr_dir.join("product-mini/platforms").join(target_os);
let mut dst = Config::new(wamr_platform_dir.as_path());
Expand Down Expand Up @@ -83,7 +87,7 @@ fn build_wamr() {
.define("WAMR_BUILD_LIBC_WASI", "0")
.define("WAMR_BUILD_LIBC_BUILTIN", "0")
.define("WAMR_BUILD_SHARED_MEMORY", "1")
.define("WAMR_BUILD_MULTI_MODULE", "0")
.define("WAMR_BUILD_MULTI_MODULE", "1")
.define("WAMR_DISABLE_HW_BOUND_CHECK", "1")
.define("WAMR_BUILD_TARGET", target_arch);

Expand Down Expand Up @@ -216,7 +220,7 @@ fn build_wamr() {
"cargo:rustc-link-search=native={}",
dst.join("build").display()
);
println!("cargo:rustc-link-lib=wamr");
println!("cargo:rustc-link-lib=static=wamr");
}

#[cfg(feature = "v8")]
Expand Down Expand Up @@ -297,8 +301,17 @@ fn build_v8() {
}

let header_path = v8_header_path.join("wasm.h");
let mut args = vec![];
if cfg!(target_os = "macos") {
args.push("-I/usr/local/include");
args.push("-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1");
args.push("-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include");
args.push("-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include");
args.push("-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks");
}
let bindings = bindgen::Builder::default()
.header(header_path.display().to_string())
.clang_args(args)
.derive_default(true)
.derive_debug(true)
.parse_callbacks(Box::new(Wee8Renamer {}))
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/backend/js/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Data types, functions and traits for the `sys` runtime.
//! Data types, functions and traits for the `js` backend.

pub(crate) mod entities;
pub(crate) mod error;
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/backend/jsc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Data types, functions and traits for the `sys` runtime.
//! Data types, functions and traits for the `jsc` backend.

pub(crate) mod entities;
pub(crate) mod error;
Expand Down
90 changes: 90 additions & 0 deletions lib/api/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,93 @@ pub enum BackendKind {
/// The `jsc` runtime.
Jsc,
}

impl Default for BackendKind {
fn default() -> Self {
#[cfg(feature = "sys-default")]
Comment thread
xdoardo marked this conversation as resolved.
{
#[cfg(feature = "cranelift")]
{
return Self::Cranelift;
}
#[cfg(feature = "singlepass")]
{
return Self::Singlepass;
}
#[cfg(feature = "llvm")]
{
return Self::LLVM;
}
return Self::Headless;
}

#[cfg(feature = "wamr-default")]
{
return Self::Wamr;
}

#[cfg(feature = "wasmi-default")]
{
return Self::Wasmi;
}

#[cfg(feature = "v8-default")]
{
return Self::V8;
}

#[cfg(feature = "js-default")]
{
return Self::Js;
}

#[cfg(feature = "jsc-default")]
{
return Self::Jsc;
}

#[cfg(feature = "sys")]
{
#[cfg(feature = "cranelift")]
{
return Self::Cranelift;
}
#[cfg(feature = "singlepass")]
{
return Self::Singlepass;
}
#[cfg(feature = "llvm")]
{
return Self::LLVM;
}
return Self::Headless;
}

#[cfg(feature = "wamr")]
{
return Self::Wamr;
}

#[cfg(feature = "wasmi")]
{
return Self::Wasmi;
}

#[cfg(feature = "v8")]
{
return Self::V8;
}

#[cfg(feature = "js")]
{
return Self::Js;
}

#[cfg(feature = "jsc")]
{
return Self::Jsc;
}

panic!("No runtime enabled!")
}
}
2 changes: 1 addition & 1 deletion lib/api/src/backend/sys/entities/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn get_default_compiler_config() -> Option<Box<dyn wasmer_compiler::Compiler
}

/// Returns the default engine for the Sys engine
pub(crate) fn default_engine() -> Engine {
pub fn default_engine() -> Engine {
#[allow(unreachable_code, unused_mut)]
fn get_engine() -> Engine {
cfg_if::cfg_if! {
Expand Down
26 changes: 21 additions & 5 deletions lib/api/src/backend/v8/entities/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,28 @@ impl Memory {
let mut store_mut = store.as_store_mut();
let v8_store = store_mut.inner.store.as_v8();

let max_requested = ty.maximum.unwrap_or(Pages::max_value());

let min = ty.minimum.0;
let max = max_requested.0;

if max < min {
return Err(MemoryError::InvalidMemory {
reason: format!("the maximum ({max} pages) is less than the minimum ({min} pages)",),
});
}

let max_allowed = Pages::max_value();
if max_requested > max_allowed {
return Err(MemoryError::MaximumMemoryTooLarge {
max_requested,
max_allowed,
});
}

let limits = Box::into_raw(Box::new(wasm_limits_t {
min: ty.minimum.0,
max: match ty.maximum {
Some(v) => v.0,
None => wasm_limits_max_default,
},
min,
max,
shared: ty.shared,
}));

Expand Down
Loading
Loading