Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 15 additions & 3 deletions .github/workflows/dep_build_wasm_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ permissions:
jobs:
build-docker-image:
if: ${{ inputs.docs_only == 'false' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
strategy:
matrix:
arch:
- name: X64
runner: ubuntu-latest
- name: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.arch.runner }}
steps:
- uses: actions/checkout@v5
with:
Expand Down Expand Up @@ -73,14 +80,19 @@ jobs:

build-wasm-examples:
needs: build-docker-image
runs-on: ubuntu-latest
strategy:
matrix:
wasmtime_version:
- name: lts
features: ""
- name: latest
features: "wasmtime_latest"
arch:
- name: X64
runner: ubuntu-latest
- name: arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.arch.runner }}
steps:
- uses: actions/checkout@v5
with:
Expand Down Expand Up @@ -110,6 +122,6 @@ jobs:
- name: Upload Wasm Modules (wasmtime ${{ matrix.wasmtime_version.name }})
uses: actions/upload-artifact@v4
with:
name: guest-modules-${{ matrix.wasmtime_version.name }}
name: guest-modules-${{ matrix.arch }}-${{ matrix.wasmtime_version.name }}
path: |
x64/release/*.aot

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe this should be by arch too?

78 changes: 63 additions & 15 deletions .github/workflows/dep_rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,54 @@ jobs:
# failed-job rerun does not need to repeat the entire matrix.
fail-fast: false
matrix:
hypervisor: [hyperv, mshv3, kvm] # hyperv is windows, mshv and kvm are linux
cpu: [amd, intel]
hypervisor: [hyperv, mshv3, kvm, hvf] # hyperv is windows, mshv and kvm are linux
cpu: [amd, intel, apple, microsoft]
arch: [X64, arm64]
config: [debug, release]
wasmtime: [latest, lts]
exclude:
# Latest testing: skip debug builds to reduce CI load
- wasmtime: latest
config: debug

runs-on: ${{ fromJson(
format('["self-hosted", "{0}", "X64", "1ES.Pool=hld-{1}-{2}", "JobId=build-{3}-{4}-{5}-{6}-{7}"]',
matrix.hypervisor == 'hyperv' && 'Windows' || 'Linux',
matrix.hypervisor == 'hyperv' && 'win2025' || matrix.hypervisor == 'mshv3' && 'azlinux3-mshv' || matrix.hypervisor,
matrix.cpu,
matrix.config,
matrix.wasmtime,
github.run_id,
github.run_number,
github.run_attempt)) }}
- cpu: apple
hypervisor: hyperv
- cpu: apple
hypervisor: mshv3
- cpu: microsoft
hypervisor: mshv3
- cpu: microsoft
hypervisor: kvm
- cpu: microsoft
hypervisor: hvf
- arch: X64
hypervisor: hvf
- cpu: amd
arch: arm64
- cpu: intel
arch: arm64
- cpu: apple
arch: X64
- cpu: microsoft
arch: X64
runs-on: ${{ fromJson(matrix.arch == 'X64'
&& format('["self-hosted", "{0}", "X64", "1ES.Pool=hld-{1}-{2}", "JobId=build-{3}-{4}-{5}-{6}-{7}"]',
matrix.hypervisor == 'hyperv' && 'Windows' || 'Linux',
matrix.hypervisor == 'hyperv' && 'win2025' || matrix.hypervisor == 'mshv3' && 'azlinux3-mshv' || matrix.hypervisor,
matrix.cpu,
matrix.config,
matrix.wasmtime,
github.run_id,
github.run_number,
github.run_attempt)
|| matrix.hypervisor == 'hyperv'
&& format('["self-hosted", "Windows", "ARM64", "1ES.Pool=hl-windows-arm", "JobId=build-{0}-{1}-{2}-{3}"]',
matrix.config,
matrix.run_id,
matrix.run_number,
matrix.run_attempt)
|| format('["self-hosted", "{0}", "arm64", "{1}"]',
matrix.hypervisor == 'hvf' && 'macos' || 'Linux',
matrix.hypervisor)) }}
env:
# Features to pass to cargo.
# On Windows LTS builds, do not pass any features.
Expand All @@ -69,7 +98,7 @@ jobs:
- uses: actions/checkout@v5

- name: Hyperlight setup
uses: hyperlight-dev/ci-setup-workflow@v1.8.0
uses: hyperlight-dev/ci-setup-workflow@v2.1.0
with:
rust-toolchain: "1.94"

Expand All @@ -86,10 +115,29 @@ jobs:
if: runner.os == 'Windows'
run: rustup component add --toolchain nightly-x86_64-pc-windows-msvc rustfmt

- name: Configure ARM64 libclang
if: runner.os == 'Windows' && inputs.arch == 'arm64'
shell: pwsh
run: |
if (-not $env:VSINSTALLDIR) {
throw "Visual Studio developer environment did not set VSINSTALLDIR"
}
$libclang = Join-Path $env:VSINSTALLDIR "VC\Tools\Llvm\ARM64\bin\libclang.dll"
if (-not (Test-Path $libclang)) {
throw "ARM64 libclang not found at '$libclang'"
}
$llvmPath = Split-Path $libclang
"LIBCLANG_PATH=$llvmPath" >> $env:GITHUB_ENV
$llvmPath >> $env:GITHUB_PATH

- name: Install clang tools (macOS)
if: ${{ runner.os == 'macOS' }}
run: brew install llvm

- name: Download Wasm Modules
uses: actions/download-artifact@v5
with:
name: guest-modules-${{ matrix.wasmtime }}
name: guest-modules-${{matrix.arch}}-${{ matrix.wasmtime }}
path: ./x64/${{ matrix.config }}

- name: Build Rust component model examples
Expand Down
9 changes: 6 additions & 3 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ fmt:
cd src/hyperlight_wasm_runtime && cargo +nightly fmt -v --all
cd src/hyperlight_wasm_macro && cargo +nightly fmt -v --all

clippy-excluded-features := if arch() == "aarch64" { "gdb,trace_guest,crashdump" } else { "" }
clippy-runtime-features := if arch() == "aarch64" { "" } else { ",gdb,trace_guest" }

clippy target=default-target: (check target)
cargo clippy --workspace --exclude hyperlight-wasm-runtime --exclude hyperlight-wasm-macro --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
cargo clippy --workspace --exclude hyperlight-wasm-runtime --exclude hyperlight-wasm-macro --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --features "$(cargo metadata --format-version 1 --no-deps | jq -r '[.packages[]|.name as$pkg|.features|keys.[]|select(.!="default" and (IN($exclude|split(",")[])|not))|$pkg+"/"+.]|join(",")' --arg exclude {{clippy-excluded-features}})" -- -D warnings
cd src/tests/rust_guests/rust_wasm_samples && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
cd src/tests/rust_guests/component_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
cd src/tests/rust_guests/greeter_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
# hyperlight_wasm_runtime has mutually exclusive wasmtime features, so we run clippy for each separately with all other features
cd src/hyperlight_wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --no-default-features --features wasmtime_latest,gdb,trace_guest,pulley -- -D warnings
cd src/hyperlight_wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --no-default-features --features wasmtime_lts,gdb,trace_guest -- -D warnings
cd src/hyperlight_wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --no-default-features --features wasmtime_latest{{clippy-runtime-features}},pulley -- -D warnings
cd src/hyperlight_wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --no-default-features --features wasmtime_lts{{clippy-runtime-features}} -- -D warnings
cd src/hyperlight_wasm_macro && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings

# TESTING
Expand Down
3 changes: 2 additions & 1 deletion src/hyperlight_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ serde_json = "1.0"
junction = "2"

[features]
default = ["function_call_metrics", "kvm", "mshv3"]
default = ["function_call_metrics", "kvm", "mshv3", "hvf"]
function_call_metrics = ["hyperlight-host/function_call_metrics"]
print_debug = ["hyperlight-host/print_debug"]
crashdump = ["hyperlight-host/crashdump"]
gdb = ["hyperlight-host/gdb"]
kvm = ["hyperlight-host/kvm"]
mshv3 = ["hyperlight-host/mshv3"]
hvf = ["hyperlight-host/hvf"]
pulley = []
trace_guest = ["hyperlight-host/trace_guest"]
# Use latest wasmtime instead of the default LTS version in wasm_runtime
Expand Down
6 changes: 5 additions & 1 deletion src/hyperlight_wasm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ fn build_wasm_runtime() -> PathBuf {
cmd.status()
.unwrap_or_else(|e| panic!("could not run cargo build hyperlight-wasm-runtime: {e:?}"));

let target_arch = format!(
"{}-hyperlight-none",
std::env::var("CARGO_CFG_TARGET_ARCH").unwrap()
);
let resource = target_dir
.join("x86_64-hyperlight-none")
.join(target_arch)
.join(profile)
.join("hyperlight-wasm-runtime");

Expand Down
7 changes: 5 additions & 2 deletions src/hyperlight_wasm/scripts/build-wasm-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ if [ -f "/.dockerenv" ] || grep -q docker /proc/1/cgroup; then
cargo run ${AOT_FEATURES} -p hyperlight-wasm-aot compile ${AOT_DEBUG_FLAGS} ${AOT_VERSION_FLAGS} --component ${OUTPUT_DIR}/${COMPONENT_NAME}-p2.wasm ${OUTPUT_DIR}/${COMPONENT_NAME}.aot
done

else
else
# not running in a container so use the docker image to build the wasm files
echo Building docker image that has Wasm sdk. Should be quick if preivoulsy built and no changes to dockerfile.
echo This will take a while if it is the first time you are building the docker image.
echo Log in ${OUTPUT_DIR}/dockerbuild.log

docker pull ghcr.io/hyperlight-dev/wasm-clang-builder:latest
arch="$(uname -m)"
if [[ "$arch" == "x86_64" ]]; then
docker pull ghcr.io/hyperlight-dev/wasm-clang-builder:latest
fi

docker build --build-arg GCC_VERSION=12 --build-arg WASI_SDK_VERSION_FULL=25.0 --cache-from ghcr.io/hyperlight-dev/wasm-clang-builder:latest -t wasm-clang-builder:latest . 2> ${OUTPUT_DIR}/dockerbuild.log

Expand Down
30 changes: 25 additions & 5 deletions src/hyperlight_wasm_aot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ use wasmtime::{Config, Engine, Module, OptLevel, Precompiled};
#[derive(Debug)]
enum SupportedTarget {
X86_64UnknownNone,
AArch64UnknownNone,
WasmtimePulley64,
}

impl Display for SupportedTarget {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SupportedTarget::X86_64UnknownNone => write!(f, "x86_64-unknown-none"),
SupportedTarget::AArch64UnknownNone => write!(f, "aarch64-unknown-none"),
SupportedTarget::WasmtimePulley64 => write!(f, "pulley64"),
}
}
Expand Down Expand Up @@ -112,7 +114,10 @@ fn precompile_bytes_lts(
if pulley {
config.target("pulley64").unwrap();
} else {
#[cfg(target_arch = "x86_64")]
config.target("x86_64-unknown-none").unwrap();
#[cfg(target_arch = "aarch64")]
config.target("aarch64-unknown-none").unwrap();
}
if debug {
config.debug_info(true);
Expand All @@ -133,7 +138,10 @@ fn precompile_bytes_lts(
/// Detect and deserialize using the LTS wasmtime version
fn detect_and_deserialize_lts(bytes: &[u8], debug: bool, file: &str) {
let mut config = wasmtime_lts::Config::new();
#[cfg(target_arch = "x86_64")]
config.target("x86_64-unknown-none").unwrap();
#[cfg(target_arch = "aarch64")]
config.target("aarch64-unknown-none").unwrap();
if debug {
config.debug_info(true);
config.cranelift_opt_level(wasmtime_lts::OptLevel::None);
Expand Down Expand Up @@ -189,7 +197,11 @@ fn main() {
let target = if pulley {
SupportedTarget::WasmtimePulley64
} else {
SupportedTarget::X86_64UnknownNone
#[cfg(target_arch = "x86_64")]
let target = SupportedTarget::X86_64UnknownNone;
#[cfg(target_arch = "aarch64")]
let target = SupportedTarget::AArch64UnknownNone;
target
};
if debug {
println!(
Expand All @@ -216,7 +228,14 @@ fn main() {
let target_name = if pulley {
"pulley64"
} else {
"x86_64-unknown-none"
#[cfg(target_arch = "x86_64")]
{
"x86_64-unknown-none"
}
#[cfg(target_arch = "aarch64")]
{
"aarch64-unknown-none"
}
};
if debug {
println!(
Expand Down Expand Up @@ -356,6 +375,9 @@ fn get_config(debug: bool, minimal: bool, target: &SupportedTarget) -> Config {
// See https://github.com/bytecodealliance/wasmtime/pull/11553
unsafe { config.x86_float_abi_ok(true) };
}
SupportedTarget::AArch64UnknownNone => {
config.target("aarch64-unknown-none").unwrap();
}
SupportedTarget::WasmtimePulley64 => {
config.target("pulley64").unwrap();
}
Expand Down Expand Up @@ -390,9 +412,7 @@ fn get_aot_target(bytes: &[u8]) -> Result<SupportedTarget, String> {
if let Ok(elf) = ElfFile64::<Endianness>::parse(bytes) {
match elf.architecture() {
Architecture::X86_64 => Ok(SupportedTarget::X86_64UnknownNone),
Architecture::Aarch64 => {
Err("Unsupported architecture Aarch64 in AOT compiled file".to_string())
}
Architecture::Aarch64 => Ok(SupportedTarget::AArch64UnknownNone),
Architecture::S390x => {
Err("Unsupported architecture S390x in AOT compiled file".to_string())
}
Expand Down
2 changes: 0 additions & 2 deletions src/hyperlight_wasm_runtime/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ fn load_wasm_module_phys(function_call: FunctionCall) -> Result<ReturnValue> {
#[no_mangle]
#[instrument(skip_all, level = "Info")]
pub extern "C" fn hyperlight_main() {
platform::register_page_fault_handler();

let mut config = Config::new();
// Enable x86_float_abi_ok only for the latest Wasmtime native x86 target.
// Safety:
Expand Down
2 changes: 0 additions & 2 deletions src/hyperlight_wasm_runtime/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,6 @@ fn load_wasm_module_phys(function_call: FunctionCall) -> Result<ReturnValue> {
#[no_mangle]
#[instrument(skip_all, level = "Info")]
pub extern "C" fn hyperlight_main() {
platform::register_page_fault_handler();

register_function(GuestFunctionDefinition::new(
"PrintOutput".to_string(),
vec![ParameterType::String],
Expand Down
Loading
Loading