From c6db7b6bec862fce3bf0ae5b0c111b93e6fb4584 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Wed, 30 Aug 2023 11:43:07 +0200 Subject: [PATCH] chore: ensure webassembly test can compile to non-wasm target --- .../integration-tests/webassembly/Cargo.toml | 8 ++--- .../integration-tests/webassembly/src/lib.rs | 29 +++-------------- .../integration-tests/webassembly/src/wasi.rs | 32 +++++++++++++++++++ ...check-aws-sdk-standalone-integration-tests | 2 +- 4 files changed, 40 insertions(+), 31 deletions(-) create mode 100644 aws/sdk/integration-tests/webassembly/src/wasi.rs diff --git a/aws/sdk/integration-tests/webassembly/Cargo.toml b/aws/sdk/integration-tests/webassembly/Cargo.toml index 1de3d037cf8..dd16d3c9a29 100644 --- a/aws/sdk/integration-tests/webassembly/Cargo.toml +++ b/aws/sdk/integration-tests/webassembly/Cargo.toml @@ -16,16 +16,14 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html -[dependencies] -anyhow = "1.0" +[target.'cfg(target_family = "wasm")'.dependencies] aws-config = { path = "../../build/aws-sdk/sdk/aws-config", default-features = false, features = [ "rt-tokio", ] } aws-sdk-s3 = { path = "../../build/aws-sdk/sdk/s3", default-features = false } aws-smithy-types = { path = "../../build/aws-sdk/sdk/aws-smithy-types" } aws-smithy-wasm = { path = "../../build/aws-sdk/sdk/aws-smithy-wasm" } -futures = "0.3.28" -http = "0.2.8" tokio = { version = "1.32.0", features = ["macros", "rt"] } -tower = "0.4.13" + +[target.'cfg(all(target_family = "wasm", target_os = "wasi"))'.dependencies] wit-bindgen = { version = "0.11.0", features = ["macros", "realloc"] } diff --git a/aws/sdk/integration-tests/webassembly/src/lib.rs b/aws/sdk/integration-tests/webassembly/src/lib.rs index 86770409f1f..27c892cbc17 100644 --- a/aws/sdk/integration-tests/webassembly/src/lib.rs +++ b/aws/sdk/integration-tests/webassembly/src/lib.rs @@ -5,30 +5,9 @@ #![allow(dead_code)] +#[cfg(target_family = "wasm")] mod default_config; +#[cfg(target_family = "wasm")] mod list_objects; - -wit_bindgen::generate!({ - inline: " - package aws:component - - interface run { - run: func() -> result - } - - world main { - export run - } - ", - exports: { - "aws:component/run": Component - } -}); - -struct Component; - -impl exports::aws::component::run::Guest for Component { - fn run() -> Result<(), ()> { - Ok(()) - } -} +#[cfg(all(target_family = "wasm", target_os = "wasi"))] +mod wasi; diff --git a/aws/sdk/integration-tests/webassembly/src/wasi.rs b/aws/sdk/integration-tests/webassembly/src/wasi.rs new file mode 100644 index 00000000000..e85a7c07b05 --- /dev/null +++ b/aws/sdk/integration-tests/webassembly/src/wasi.rs @@ -0,0 +1,32 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +// Needed for WASI-compliant environment as it expects specific functions +// to be exported such as `cabi_realloc`, `_start`, etc. + +wit_bindgen::generate!({ + inline: " + package aws:component + + interface run { + run: func() -> result + } + + world main { + export run + } + ", + exports: { + "aws:component/run": Component + } +}); + +struct Component; + +impl exports::aws::component::run::Guest for Component { + fn run() -> Result<(), ()> { + Ok(()) + } +} diff --git a/tools/ci-scripts/check-aws-sdk-standalone-integration-tests b/tools/ci-scripts/check-aws-sdk-standalone-integration-tests index d5d1feb6f01..dd6dc1c8fce 100755 --- a/tools/ci-scripts/check-aws-sdk-standalone-integration-tests +++ b/tools/ci-scripts/check-aws-sdk-standalone-integration-tests @@ -42,6 +42,6 @@ cargo check --tests # Running WebAssembly (WASI) specific integration tests pushd "${tmp_dir}/aws/sdk/integration-tests/webassembly" &>/dev/null -cargo build +cargo check --tests cargo test -- --nocapture popd