Skip to content

Commit

Permalink
chore: ensure webassembly test can compile to non-wasm target
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardomourar committed Aug 30, 2023
1 parent 044d37a commit 917e001
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
8 changes: 3 additions & 5 deletions aws/sdk/integration-tests/webassembly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
29 changes: 4 additions & 25 deletions aws/sdk/integration-tests/webassembly/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion aws/sdk/integration-tests/webassembly/src/list_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use aws_sdk_s3::operation::list_objects_v2::ListObjectsV2Output;

async fn s3_list_objects() -> ListObjectsV2Output {
use aws_sdk_s3::Client;
use crate::default_config::get_default_config;
use aws_sdk_s3::Client;

let shared_config = get_default_config().await;
let client = Client::new(&shared_config);
Expand Down
32 changes: 32 additions & 0 deletions aws/sdk/integration-tests/webassembly/src/wasi.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 917e001

Please sign in to comment.