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
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ jobs:
- name: test
run: make ci
shell: bash
- name: adapter
run: cd wasm_abi/adapter && cargo build --release -p viceroy-component-adapter --target wasm32-unknown-unknown

# Run the trap test in an isolated job. It needs different cargo features than the usual build, so
# it entails rebuilding the whole workspace if we combine them in a single job. This way, we
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ publish
vendor/
verify-publishable/
.vscode
# Auto-generated adapter wasm files (built by build.rs)
wasm_abi/data/*.wasm
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ categories = [
"wasm"
]
include = [
"build.rs",
"CHANGELOG.md",
"SECURITY.md",
"src/**/*",
"wasm_abi/adapter/**/*",
"wasm_abi/wit/**/*",
"wasm_abi/compute-at-edge-abi/**/*.witx",
"wasm_abi/data/*.wasm",
]
rust-version = "1.90"

Expand Down
55 changes: 0 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,58 +62,3 @@ generate-lockfile:
$(VICEROY_CARGO) generate-lockfile
$(VICEROY_CARGO) generate-lockfile --manifest-path=test-fixtures/Cargo.toml
$(VICEROY_CARGO) generate-lockfile --manifest-path=cli/tests/trap-test/Cargo.toml

# Regenerate the adapter, and move it into `wasm_abi/data`
.PHONY: build-adapter
build-adapter:
# Build the component adapter for adapting the host-call abi to the
# component model. This version uses `--no-default-features` to disable
# the default "exports" feature, to build the imports-only "library"
# version of the adapter.
( \
cd wasm_abi/adapter && \
cargo build \
--package viceroy-component-adapter \
--target wasm32-unknown-unknown \
--no-default-features \
--profile release-library \
)
# Build the non-shift "library" version of the adapter.
( \
cd wasm_abi/adapter && \
cargo build \
--package viceroy-component-adapter \
--target wasm32-unknown-unknown \
--no-default-features \
--profile release-library-noshift \
--features noshift \
)

# Build the component adapter for adapting the host-call abi to the
# component model. This is the normal version that includes the exports.
( \
cd wasm_abi/adapter && \
cargo build \
--package viceroy-component-adapter \
--target wasm32-unknown-unknown \
--release \
)

# Build the non-shift normal version of the adapter.
( \
cd wasm_abi/adapter && \
cargo build \
--package viceroy-component-adapter \
--target wasm32-unknown-unknown \
--profile release-noshift \
--features noshift \
)

cp wasm_abi/adapter/target/wasm32-unknown-unknown/release/viceroy_component_adapter.wasm \
wasm_abi/data/viceroy-component-adapter.wasm
cp wasm_abi/adapter/target/wasm32-unknown-unknown/release-noshift/viceroy_component_adapter.wasm \
wasm_abi/data/viceroy-component-adapter.noshift.wasm
cp wasm_abi/adapter/target/wasm32-unknown-unknown/release-library/viceroy_component_adapter.wasm \
wasm_abi/data/viceroy-component-adapter.library.wasm
cp wasm_abi/adapter/target/wasm32-unknown-unknown/release-library-noshift/viceroy_component_adapter.wasm \
wasm_abi/data/viceroy-component-adapter.library.noshift.wasm
115 changes: 115 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;

fn main() {
// Only rebuild if the adapter source changes
println!("cargo:rerun-if-changed=wasm_abi/adapter");

let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let adapter_dir = manifest_dir.join("wasm_abi/adapter");
let data_dir = manifest_dir.join("wasm_abi/data");

// Ensure the data directory exists
std::fs::create_dir_all(&data_dir).expect("Failed to create wasm_abi/data directory");

// Get the cargo command to use (allows for override like in Makefile)
let cargo = env::var("CARGO").unwrap_or_else(|_| "cargo".to_string());

// Build the component adapter for adapting the host-call abi to the
// component model. This version uses `--no-default-features` to disable
// the default "exports" feature, to build the imports-only "library"
// version of the adapter.
build_adapter(
&cargo,
&adapter_dir,
&data_dir,
"release-library",
&["--no-default-features"],
"viceroy-component-adapter.library.wasm",
);

// Build the non-shift "library" version of the adapter.
build_adapter(
&cargo,
&adapter_dir,
&data_dir,
"release-library-noshift",
&["--no-default-features", "--features", "noshift"],
"viceroy-component-adapter.library.noshift.wasm",
);

// Build the component adapter for adapting the host-call abi to the
// component model. This is the normal version that includes the exports.
build_adapter(
&cargo,
&adapter_dir,
&data_dir,
"release",
&[],
"viceroy-component-adapter.wasm",
);

// Build the non-shift normal version of the adapter.
build_adapter(
&cargo,
&adapter_dir,
&data_dir,
"release-noshift",
&["--features", "noshift"],
"viceroy-component-adapter.noshift.wasm",
);
}

fn build_adapter(
cargo: &str,
adapter_dir: &Path,
data_dir: &Path,
profile: &str,
extra_args: &[&str],
output_name: &str,
) {
eprintln!("Building adapter variant: {}", output_name);

let mut cmd = Command::new(cargo);
cmd.current_dir(adapter_dir)
.arg("build")
.arg("--package")
.arg("viceroy-component-adapter")
.arg("--target")
.arg("wasm32-unknown-unknown")
.arg("--profile")
.arg(profile);

// Add any extra arguments (like --no-default-features or --features)
for arg in extra_args {
cmd.arg(arg);
}

let status = cmd
.status()
.unwrap_or_else(|e| panic!("Failed to execute cargo build for {}: {}", output_name, e));

if !status.success() {
panic!("Failed to build adapter variant: {}", output_name);
}

// Copy the built wasm file to the data directory
let source = adapter_dir
.join("target/wasm32-unknown-unknown")
.join(profile)
.join("viceroy_component_adapter.wasm");

let dest = data_dir.join(output_name);

std::fs::copy(&source, &dest).unwrap_or_else(|e| {
panic!(
"Failed to copy {} to {}: {}",
source.display(),
dest.display(),
e
)
});

eprintln!("Successfully built and copied {}", output_name);
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed wasm_abi/data/viceroy-component-adapter.wasm
Binary file not shown.
Loading