Skip to content

Commit

Permalink
Merge pull request #120 from holochain/add-wasmer-prod-compiler
Browse files Browse the repository at this point in the history
feat: Add features for dev and prod wasmer configurations
  • Loading branch information
ThetaSinner authored Oct 31, 2024
2 parents 280f3ac + 1f6cb88 commit 52bf57d
Show file tree
Hide file tree
Showing 21 changed files with 329 additions and 69 deletions.
27 changes: 21 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
matrix:
script: ["test", "bench"]
os: ["ubuntu-latest", "macos-latest"]
wasmer-feature: ["wasmer_sys", "wasmer_wamr"]
wasmer-feature: ["wasmer_sys_dev", "wasmer_sys_prod", "wasmer_wamr"]
exclude:
# TODO bench suite on macos-latest is killed by system due to running out of swap space
# All benches run fine individually
Expand All @@ -33,9 +33,9 @@ jobs:
size: 15G
- uses: actions/checkout@v4
- name: Install nix
uses: cachix/install-nix-action@v26
uses: cachix/install-nix-action@v30
- name: Setup cachix
uses: cachix/cachix-action@v14
uses: cachix/cachix-action@v15
if: ${{ ! contains(matrix.platform.runs-on, 'self-hosted') }}
with:
name: holochain-ci
Expand All @@ -47,7 +47,8 @@ jobs:
fail-fast: false
matrix:
wasmer-feature:
- "wasmer_sys"
- "wasmer_sys_dev"
- "wasmer_sys_prod"
# TODO Building with wasmer_wamr feature flag on windows is not currently working.
# See https://github.com/holochain/holochain-wasmer/issues/117
# - "wasmer_wamr"
Expand All @@ -57,7 +58,21 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install LLVM
env:
LLVM_DIR: .llvm
shell: bash
run: |
LLVM_DIR=$(pwd)/${{ env.LLVM_DIR }}
mkdir -p ${LLVM_DIR}
curl --proto '=https' --tlsv1.2 -sSf "https://github.com/wasmerio/llvm-custom-builds/releases/download/15.x/llvm-windows-amd64.tar.xz" -L -o - | tar xJv -C ${LLVM_DIR}
- name: test root
run: cargo test --release --no-default-features --features error_as_host,${{ matrix.wasmer-feature }} -- --nocapture
shell: pwsh
run: |
$env:LLVM_SYS_150_PREFIX="$(pwd)/.llvm"
cargo test --release --no-default-features --features error_as_host,${{ matrix.wasmer-feature }} -- --nocapture
- name: test
run: cargo test --release --manifest-path test/Cargo.toml --no-default-features --features ${{ matrix.wasmer-feature }} -- --nocapture
shell: pwsh
run: |
$env:LLVM_SYS_150_PREFIX="$(pwd)/.llvm"
cargo test --release --manifest-path test/Cargo.toml --no-default-features --features ${{ matrix.wasmer-feature }} -- --nocapture
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Changed
- **BREAKING CHANGE** The `wasmer_sys` feature has been renamed to `wasmer_sys_dev`

### Added
- A new feature flag, `wasmer_sys_prod` which enables the Wasmer LLVM compiler. The default, with the `wasmer_sys_dev` feature
is the Cranelift compiler. The Cranelift compiler is fast, and recommended for development, but the LLVM compiler is supposed
to be faster and more optimized for production. In testing so far, the compile step is slower with LLVM but the runtime is
faster. More testing is needed yet to confirm the difference.

## [0.0.93] - 2024-04-24

### Changed
Expand Down
128 changes: 109 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions crates/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ authors = ["thedavidmeister", "[email protected]"]
edition = "2021"

[dependencies]
wasmer = { version = "=4.3.6", optional = true, default-feature = false }
wasmer-middlewares = { version = "=4.3.6", optional = true, default-feature = false }
wasmer = { version = "=4.3.6", optional = true, default-features = false }
wasmer-middlewares = { version = "=4.3.6", optional = true, default-features = false }

# Temporarily include a fork of wasmer from the git branch 'wamr', until it is officially released in wasmer v5
hc-wasmer = { version="=4.3.6-hc.1", optional = true, default-features = false }
Expand All @@ -30,14 +30,22 @@ crate-type = ["cdylib", "rlib"]
path = "src/lib.rs"

[features]
default = ["error_as_host", "wasmer_sys"]
default = ["error_as_host", "wasmer_sys_dev"]
debug_memory = []
error_as_host = ["holochain_wasmer_common/error_as_host"]
wasmer_sys = [
"dep:wasmer",
"dep:wasmer-middlewares",
"wasmer/sys",
]
wasmer_sys_dev = [
"wasmer_sys",
"wasmer/default",
]
wasmer_sys_prod = [
"wasmer_sys",
"wasmer/llvm",
]
wasmer_wamr = [
"dep:hc-wasmer",
"hc-wasmer/wamr"
Expand Down
11 changes: 8 additions & 3 deletions crates/host/src/module/wasmer_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use wasmer::sys::BaseTunables;
use wasmer::sys::CompilerConfig;
use wasmer::wasmparser;
use wasmer::CompileError;
use wasmer::Cranelift;
use wasmer::DeserializeError;
use wasmer::Engine;
use wasmer::Module;
Expand All @@ -29,9 +28,15 @@ pub fn make_engine() -> Engine {
// @todo 100 giga-ops is totally arbitrary cutoff so we probably
// want to make the limit configurable somehow.
let metering = Arc::new(Metering::new(WASM_METERING_LIMIT, cost_function));

// the only place where the wasm compiler engine is set
let mut compiler = Cranelift::default();
compiler.canonicalize_nans(true).push_middleware(metering);
#[cfg(feature = "wasmer_sys_dev")]
let mut compiler = wasmer::Cranelift::default();
#[cfg(feature = "wasmer_sys_prod")]
let mut compiler = wasmer::LLVM::default();

compiler.canonicalize_nans(true);
compiler.push_middleware(metering);

// Workaround for invalid memory access on iOS.
// https://github.com/holochain/holochain/issues/3096
Expand Down
Loading

0 comments on commit 52bf57d

Please sign in to comment.