Skip to content

Commit

Permalink
Revert "wasi-adapter: Implement provider crate that embeds the adapte…
Browse files Browse the repository at this point in the history
…r binaries (#8792)" (#8856)

* Revert "wasi-adapter: Implement provider crate that embeds the adapter binaries (#8792)"

This reverts commit 2dbf8f1.

* Enable requisite feature for cranelift-frontend testing
  • Loading branch information
alexcrichton authored Jun 21, 2024
1 parent 6b89213 commit 00c15df
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 155 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -793,23 +793,17 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true

- name: Install Rust version
run: |
RUST_VERSION=$( \
grep '^rust-version\s*=' crates/wasi-preview1-component-adapter/Cargo.toml | \
sed 's/rust-version.*=.*\"\(.*\)\"/\1/' \
)
rustup toolchain install $RUST_VERSION --profile minimal
rustup target add wasm32-wasi wasm32-unknown-unknown --toolchain $RUST_VERSION
echo RUSTUP_TOOLCHAIN=$RUST_VERSION >> "$GITHUB_ENV"
- uses: ./.github/actions/install-rust
- run: rustup target add wasm32-wasi wasm32-unknown-unknown

- name: Install wasm-tools
run: |
curl -L https://github.com/bytecodealliance/wasm-tools/releases/download/wasm-tools-1.0.27/wasm-tools-1.0.27-x86_64-linux.tar.gz | tar xfz -
echo `pwd`/wasm-tools-1.0.27-x86_64-linux >> $GITHUB_PATH
- run: ./ci/build-wasi-preview1-component-adapter.sh
env:
VERSION: ${{ github.sha }}

- uses: actions/upload-artifact@v4
with:
Expand Down
5 changes: 0 additions & 5 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ members = [
"crates/environ/fuzz",
"crates/test-programs",
"crates/wasi-preview1-component-adapter",
"crates/wasi-preview1-component-adapter/provider",
"crates/wasi-preview1-component-adapter/verify",
"examples/fib-debug/wasm",
"examples/wasi/wasm",
Expand Down Expand Up @@ -205,7 +204,6 @@ wiggle = { path = "crates/wiggle", version = "=23.0.0", default-features = false
wiggle-macro = { path = "crates/wiggle/macro", version = "=23.0.0" }
wiggle-generate = { path = "crates/wiggle/generate", version = "=23.0.0" }
wasi-common = { path = "crates/wasi-common", version = "=23.0.0", default-features = false }
wasi-preview1-component-adapter-provider = { path = "crates/wasi-preview1-component-adapter/provider", version = "23.0.0", default-features = false }
wasmtime-fuzzing = { path = "crates/fuzzing" }
wasmtime-jit-icache-coherence = { path = "crates/jit-icache-coherence", version = "=23.0.0" }
wasmtime-wit-bindgen = { path = "crates/wit-bindgen", version = "=23.0.0" }
Expand Down
60 changes: 9 additions & 51 deletions ci/build-wasi-preview1-component-adapter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@ verify="cargo run -p verify-component-adapter --"
debug="target/wasm32-unknown-unknown/debug/wasi_snapshot_preview1.wasm"
release="target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm"

# The rust version that the adapter is built with is the crate's MSRV
RUST_VERSION=$( \
grep '^rust-version\s*=' crates/wasi-preview1-component-adapter/Cargo.toml | \
sed 's/rust-version.*=.*\"\(.*\)\"/\1/' \
)

if [[ $(rustc --version | grep $RUST_VERSION | wc -c) -eq 0 ]]; then
set +x
echo "The adapter is being built with a different Rust version than its"
echo "MSRV"
echo ""
echo " current rust version: $(rustc --version)"
echo " MSRV: $RUST_VERSION"
echo ""
echo "Please rerun this script with Rust version $RUST_VERSION, or update"
echo "the adapter's MSRV in its Cargo.toml file"
exit 1
fi

# Debug build, default features (reactor)
$build_adapter
$verify $debug
Expand All @@ -34,43 +15,20 @@ $verify $debug
$build_adapter --no-default-features --features command
$verify $debug

compare() {
input=$1
flavor=$2
$verify $input
name=wasi_snapshot_preview1.$flavor.wasm
dst=$(dirname $input)/$name
reference=crates/wasi-preview1-component-adapter/provider/artefacts/$name
wasm-tools metadata add --name "wasi_preview1_component_adapter.$flavor.adapter" $input \
-o $dst
set +x
if [ "$BLESS" = "1" ]; then
cp $dst $reference
elif ! cmp -s $dst $reference; then
echo "Reference copy of adapter is not the same as the generated copy of"
echo "the adapter"
echo ""
echo " reference copy: $reference"
echo " built copy: $dst"
echo ""
echo "To automatically update the reference copy set \`BLESS=1\` in the"
echo "environment"
diff -u <(wasm-tools print $reference) <(wasm-tools print $dst)
exit 1
else
echo "Reference copy of adapter matches local copy"
fi
set -x
}

# Release build, command
$build_adapter --release --no-default-features --features command
compare $release command
$verify $release
wasm-tools metadata add --name "wasi_preview1_component_adapter.command.adapter:${VERSION}" $release \
-o target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.command.wasm

# Release build, default features (reactor)
$build_adapter --release
compare $release reactor
$verify $release
wasm-tools metadata add --name "wasi_preview1_component_adapter.reactor.adapter:${VERSION}" $release \
-o target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.reactor.wasm

# Release build, proxy
$build_adapter --release --no-default-features --features proxy
compare $release proxy
$verify $release
wasm-tools metadata add --name "wasi_preview1_component_adapter.proxy.adapter:${VERSION}" $release \
-o target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.proxy.wasm
1 change: 1 addition & 0 deletions cranelift/frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ smallvec = { workspace = true }

[dev-dependencies]
similar = { workspace = true }
cranelift-codegen = { workspace = true, features = ['x86'] }

[features]
default = ["std"]
Expand Down
1 change: 0 additions & 1 deletion crates/test-programs/artifacts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ wasmtime = { workspace = true, features = ['incremental-cache', 'cranelift', 'co

[build-dependencies]
heck = { workspace = true }
wasi-preview1-component-adapter-provider = { workspace = true }
wit-component = { workspace = true }
cargo_metadata = "0.18.1"
58 changes: 47 additions & 11 deletions crates/test-programs/artifacts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ fn main() {
fn build_and_generate_tests() {
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());

let reactor_adapter = build_adapter(&out_dir, "reactor", &[]);
let command_adapter = build_adapter(
&out_dir,
"command",
&["--no-default-features", "--features=command"],
);
let proxy_adapter = build_adapter(
&out_dir,
"proxy",
&["--no-default-features", "--features=proxy"],
);

println!("cargo:rerun-if-changed=../src");

// Build the test programs:
Expand Down Expand Up @@ -82,13 +94,9 @@ fn build_and_generate_tests() {
continue;
}
let adapter = match target.as_str() {
"reactor" => {
wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_REACTOR_ADAPTER
}
s if s.starts_with("api_proxy") => {
wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_PROXY_ADAPTER
}
_ => wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_COMMAND_ADAPTER,
"reactor" => &reactor_adapter,
s if s.starts_with("api_proxy") => &proxy_adapter,
_ => &command_adapter,
};
let path = compile_component(&wasm, adapter);
generated_code += &format!("pub const {camel}_COMPONENT: &'static str = {path:?};\n");
Expand All @@ -108,6 +116,37 @@ fn build_and_generate_tests() {
std::fs::write(out_dir.join("gen.rs"), generated_code).unwrap();
}

// Build the WASI Preview 1 adapter, and get the binary:
fn build_adapter(out_dir: &PathBuf, name: &str, features: &[&str]) -> Vec<u8> {
println!("cargo:rerun-if-changed=../../wasi-preview1-component-adapter");
let mut cmd = cargo();
cmd.arg("build")
.arg("--release")
.arg("--package=wasi-preview1-component-adapter")
.arg("--target=wasm32-unknown-unknown")
.env("CARGO_TARGET_DIR", out_dir)
.env("RUSTFLAGS", rustflags())
.env_remove("CARGO_ENCODED_RUSTFLAGS");
for f in features {
cmd.arg(f);
}
eprintln!("running: {cmd:?}");
let status = cmd.status().unwrap();
assert!(status.success());

let adapter = out_dir.join(format!("wasi_snapshot_preview1.{name}.wasm"));
std::fs::copy(
out_dir
.join("wasm32-unknown-unknown")
.join("release")
.join("wasi_snapshot_preview1.wasm"),
&adapter,
)
.unwrap();
println!("wasi {name} adapter: {:?}", &adapter);
fs::read(&adapter).unwrap()
}

fn rustflags() -> &'static str {
match option_env!("RUSTFLAGS") {
// If we're in CI which is denying warnings then deny warnings to code
Expand All @@ -125,10 +164,7 @@ fn compile_component(wasm: &Path, adapter: &[u8]) -> PathBuf {
.module(module.as_slice())
.unwrap()
.validate(true)
.adapter(
wasi_preview1_component_adapter_provider::WASI_SNAPSHOT_PREVIEW1_ADAPTER_NAME,
adapter,
)
.adapter("wasi_snapshot_preview1", adapter)
.unwrap()
.encode()
.expect("module can be translated to a component");
Expand Down
1 change: 0 additions & 1 deletion crates/wasi-preview1-component-adapter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "wasi-preview1-component-adapter"
version.workspace = true
rust-version = "1.77.0"
authors.workspace = true
edition.workspace = true
publish = false
Expand Down
19 changes: 0 additions & 19 deletions crates/wasi-preview1-component-adapter/provider/Cargo.toml

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
51 changes: 0 additions & 51 deletions crates/wasi-preview1-component-adapter/provider/src/lib.rs

This file was deleted.

4 changes: 0 additions & 4 deletions scripts/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ const CRATES_TO_PUBLISH: &[&str] = &[
"wasmtime-cli-flags",
"wasmtime-explorer",
"wasmtime-cli",
// wasi component adapter
"wasi-preview1-component-adapter-provider",
];

// Anything **not** mentioned in this array is required to have an `=a.b.c`
Expand Down Expand Up @@ -113,8 +111,6 @@ const PUBLIC_CRATES: &[&str] = &[
// This is a dependency of cranelift crates and as a result can't break in
// patch releases as well
"wasmtime-types",
// wasi component adapter
"wasi-preview1-component-adapter-provider",
];

const C_HEADER_PATH: &str = "./crates/c-api/include/wasmtime.h";
Expand Down

0 comments on commit 00c15df

Please sign in to comment.