Skip to content

Commit

Permalink
Updates from PR feedback
Browse files Browse the repository at this point in the history
Remove WasmSleep in favor of existing TokioSleep

Update the targeting in wasm crates dependencies

Updating comments around setting timeouts
  • Loading branch information
landonxjames committed Feb 26, 2024
1 parent bd2006f commit c883aad
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 29 deletions.
4 changes: 3 additions & 1 deletion rust-runtime/aws-smithy-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/awslabs/smithy-rs"

[target.'cfg(all(target_family = "wasm", target_os = "wasi"))'.dependencies]
[dependencies]
aws-smithy-async = { path = "../aws-smithy-async" }
aws-smithy-runtime-api = { path = "../aws-smithy-runtime-api", features = ["http-1x"]}
aws-smithy-http = { path = "../aws-smithy-http" }
Expand All @@ -20,6 +20,8 @@ http = "1.0.0"
tokio = { version = "1.36.0", features = ["rt", "macros", "time"] }
tower = "0.4.13"
tracing = "0.1.40"

[target.'cfg(all(target_family = "wasm", target_os = "wasi"))'.dependencies]
wasi = "0.12.0+wasi-0.2.0"

[package.metadata.docs.rs]
Expand Down
4 changes: 0 additions & 4 deletions rust-runtime/aws-smithy-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,3 @@
/// Tools for using Smithy SDKs in WASI environments
#[cfg(all(target_family = "wasm", target_os = "wasi"))]
pub mod wasi;

/// Tools for using Smithy SDKs in WASM environments
#[cfg(target_family = "wasm")]
pub mod wasm;
7 changes: 5 additions & 2 deletions rust-runtime/aws-smithy-wasm/src/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,18 @@ struct WasiRequestOptions(Option<outgoing_handler::RequestOptions>);
impl From<&HttpConnectorSettings> for WasiRequestOptions {
fn from(value: &HttpConnectorSettings) -> Self {
//The WASI Duration is nanoseconds represented as u64
//Note: that the HttpConnectorSettings provides nanoseconds as u128
//so here we are clamping to u64::MAX if the value is above that
let connect_timeout = value
.connect_timeout()
.map(|dur| u64::try_from(dur.as_nanos()).unwrap_or(u64::MAX));
let read_timeout = value
.read_timeout()
.map(|dur| u64::try_from(dur.as_nanos()).unwrap_or(u64::MAX));

//Note: unable to find any documentation about what timeout values are not supported
//so not sure under what circumstances these set operations would actually fail
//Note: these only fail if setting this particular type of timeout is not
//supported. Spec compliant runtimes should always support these so it is
//unlikely to be an issue.
let wasi_http_opts = wasi_http::RequestOptions::new();
wasi_http_opts
.set_connect_timeout(connect_timeout)
Expand Down
20 changes: 0 additions & 20 deletions rust-runtime/aws-smithy-wasm/src/wasm.rs

This file was deleted.

1 change: 1 addition & 0 deletions tools/ci-cdk/canary-wasm/Cargo.lock

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

1 change: 1 addition & 0 deletions tools/ci-cdk/canary-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ wit-bindgen = { version = "0.16.0", features = ["macros", "realloc"] }
aws-config = { path = "../../../aws/sdk/build/aws-sdk/sdk/aws-config", default-features = false, features = ["behavior-version-latest"] }
aws-sdk-s3 = { path = "../../../aws/sdk/build/aws-sdk/sdk/s3", default-features = false }
aws-smithy-wasm = { path = "../../../aws/sdk/build/aws-sdk/sdk/aws-smithy-wasm" }
aws-smithy-async = { path = "../../../aws/sdk/build/aws-sdk/sdk/aws-smithy-async", default-features = false, features = ["rt-tokio"]}

[lib]
crate-type = ["cdylib"]
Expand Down
5 changes: 3 additions & 2 deletions tools/ci-cdk/canary-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use aws_config::Region;
use aws_sdk_s3 as s3;
use aws_smithy_wasm::wasi::WasiHttpClientBuilder;
use aws_smithy_wasm::wasm::WasmSleep;
use aws_smithy_async::rt::sleep::TokioSleep;

//Generates the Rust bindings from the wit file
wit_bindgen::generate!({
Expand All @@ -31,11 +31,12 @@ impl exports::aws::component::canary_interface::Guest for Component {

async fn run_canary() -> Result<Vec<String>, String> {
let http_client = WasiHttpClientBuilder::new().build();
let sleep = TokioSleep::new();
let config = aws_config::from_env()
.region(Region::new("us-east-2"))
.no_credentials()
.http_client(http_client)
.sleep_impl(WasmSleep)
.sleep_impl(sleep)
.load()
.await;

Expand Down

0 comments on commit c883aad

Please sign in to comment.