Skip to content

Commit

Permalink
feat: Add features for dev and prod wasmer configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Oct 25, 2024
1 parent 280f3ac commit 4d4618d
Show file tree
Hide file tree
Showing 17 changed files with 321 additions and 58 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
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
23 changes: 18 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,26 @@
inputs.holochain-flake.devShells.${system}.rustDev
];

# These packages and env vars are required to build wasmer on the 'wamr' branch (i.e. the hc-wasmer dependency)
packages = [
pkgs.cmake
pkgs.clang
pkgs.llvmPackages.libclang.lib
packages = with pkgs; [
# These packages and env vars are required to build Wasmer with the 'wamr' feature (i.e. the hc-wasmer dependency)
cmake
clang
llvmPackages.libclang.lib
# These packages are required to build Wasmer with the production config
llvm_15
libffi
libxml2
zlib
ncurses
];
# Used by `wamr`
LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib";
# Used by wasmer production config
shellHook = ''
# This binary lives in a different derivation to `llvm_15` and isn't re-exported through that derivation
export LLVM_SYS_150_PREFIX=$(which llvm-config | xargs dirname | xargs dirname)
export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.libffi}/lib:${pkgs.zlib}/lib:${pkgs.ncurses}/lib"
'';
};
};
};
Expand Down
Loading

0 comments on commit 4d4618d

Please sign in to comment.