Skip to content

wasmerio/v8-wasm-bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

V8 API via Wasm Imports (Wasmer 7.0)

This project demonstrates the pattern:

  • A program compiled to wasm32-unknown-unknown that uses V8 API symbols.
  • The V8 API is provided as imported functions at runtime.
  • The wasm binary does not embed the V8 engine.

Project layout

  • guest/tests/*.cpp: default test sources.
  • guest/tests/manifest.json: default test registry used by host integration tests.
  • guest/build-test-native.sh: builds native test binaries.
  • guest/build-test-wasix.sh: builds WASIX test wasm modules.
  • host/: Wasmer 7.0 runtime that resolves guest imports via real libv8.dylib.
  • host/tests/wasix_examples_compare.rs: compares native and WASIX outputs.

Build and run

  1. Build one guest test (native + WASIX):
./guest/build-test-native.sh version_printf
./guest/build-test-wasix.sh version_printf
  1. Run host (Rust 1.91+; this repo includes rust-toolchain.toml):
cargo run -p v8_host -- target/wasm32-wasix/release/version_printf.wasm wasix

Expected output:

V8_VERSION_STRING=14.5.201.9
wasix_exit_code=0

Why this matches the objective

Guest tests use V8 public headers (v8-version.h, v8-version-string.h) and compile to both native and WASIX artifacts. The host runs WASIX modules with wasmer-wasix, and test assertions enforce native vs WASIX output parity.

Test framework

Run:

cargo test -p v8_host

This validates one default path:

  • native stdout equals WASIX stdout for each test case.

The default test list is loaded from guest/tests/manifest.json, so adding a new parity test is:

  1. add guest/tests/<name>.cpp
  2. add <name> to guest/tests/manifest.json
  3. run cargo test -p v8_host

Current coverage set (easy -> medium):

  • version_printf (v8-version-string.h)
  • version_numbers_printf (v8-version.h)
  • version_string_printf (v8-version-string.h)
  • getversion_signature_printf (v8::V8::GetVersion signature contract)
  • setflags_from_string_printf (v8::V8::SetFlagsFromString runtime imports)

Symbol Binding Contract

  • No custom guest APIs: guest tests only call V8 headers APIs.
  • Host import names: C++ mangled symbols (for example _ZN2v82V810GetVersionEv) are bound in host/src/lib.rs.
  • Pointer-return APIs: if an API returns host memory pointers, host trampolines copy stable bytes into guest memory and return a guest pointer.
  • WASIX modules: use wasmer-wasix runner imports as the default runtime path.

Progression Gate for Next Layer

Before moving to lifecycle APIs, keep these acceptance criteria:

  • cargo test -p v8_host is fully green.
  • every new API test has deterministic native vs WASIX stdout parity.
  • no flaky behavior across repeated runs.

Planned medium-difficulty next API family:

  • v8::V8::SetFlagsFromCommandLine(...) (argv pointer mapping and post-parse argc/argv validation).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages