From c883aad007e0f5929794be8f5370854679a5f213 Mon Sep 17 00:00:00 2001 From: Landon James Date: Mon, 26 Feb 2024 13:18:41 -0800 Subject: [PATCH] Updates from PR feedback Remove WasmSleep in favor of existing TokioSleep Update the targeting in wasm crates dependencies Updating comments around setting timeouts --- rust-runtime/aws-smithy-wasm/Cargo.toml | 4 +++- rust-runtime/aws-smithy-wasm/src/lib.rs | 4 ---- rust-runtime/aws-smithy-wasm/src/wasi.rs | 7 +++++-- rust-runtime/aws-smithy-wasm/src/wasm.rs | 20 -------------------- tools/ci-cdk/canary-wasm/Cargo.lock | 1 + tools/ci-cdk/canary-wasm/Cargo.toml | 1 + tools/ci-cdk/canary-wasm/src/lib.rs | 5 +++-- 7 files changed, 13 insertions(+), 29 deletions(-) delete mode 100644 rust-runtime/aws-smithy-wasm/src/wasm.rs diff --git a/rust-runtime/aws-smithy-wasm/Cargo.toml b/rust-runtime/aws-smithy-wasm/Cargo.toml index ea3f89f9b4..fc06b70d20 100644 --- a/rust-runtime/aws-smithy-wasm/Cargo.toml +++ b/rust-runtime/aws-smithy-wasm/Cargo.toml @@ -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" } @@ -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] diff --git a/rust-runtime/aws-smithy-wasm/src/lib.rs b/rust-runtime/aws-smithy-wasm/src/lib.rs index caf6310972..c2e1ae05f6 100644 --- a/rust-runtime/aws-smithy-wasm/src/lib.rs +++ b/rust-runtime/aws-smithy-wasm/src/lib.rs @@ -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; diff --git a/rust-runtime/aws-smithy-wasm/src/wasi.rs b/rust-runtime/aws-smithy-wasm/src/wasi.rs index d7e6198040..a72c8b7004 100644 --- a/rust-runtime/aws-smithy-wasm/src/wasi.rs +++ b/rust-runtime/aws-smithy-wasm/src/wasi.rs @@ -151,6 +151,8 @@ struct WasiRequestOptions(Option); 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)); @@ -158,8 +160,9 @@ impl From<&HttpConnectorSettings> for WasiRequestOptions { .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) diff --git a/rust-runtime/aws-smithy-wasm/src/wasm.rs b/rust-runtime/aws-smithy-wasm/src/wasm.rs deleted file mode 100644 index c438aa1acc..0000000000 --- a/rust-runtime/aws-smithy-wasm/src/wasm.rs +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -//! WASM Tools for the SDK -use aws_smithy_async::rt::sleep::{AsyncSleep, Sleep}; - -/// A struct implementing the AsyncSleep trait that can be used in -/// Wasm environments -#[derive(Debug, Clone)] -pub struct WasmSleep; - -impl AsyncSleep for WasmSleep { - fn sleep(&self, duration: std::time::Duration) -> Sleep { - Sleep::new(Box::pin(async move { - tokio::time::sleep(duration).await; - })) - } -} diff --git a/tools/ci-cdk/canary-wasm/Cargo.lock b/tools/ci-cdk/canary-wasm/Cargo.lock index aac8afab10..4601b3024d 100644 --- a/tools/ci-cdk/canary-wasm/Cargo.lock +++ b/tools/ci-cdk/canary-wasm/Cargo.lock @@ -90,6 +90,7 @@ version = "0.1.0" dependencies = [ "aws-config", "aws-sdk-s3", + "aws-smithy-async", "aws-smithy-wasm", "tokio", "wit-bindgen", diff --git a/tools/ci-cdk/canary-wasm/Cargo.toml b/tools/ci-cdk/canary-wasm/Cargo.toml index 32e2ad4f42..de883a420c 100644 --- a/tools/ci-cdk/canary-wasm/Cargo.toml +++ b/tools/ci-cdk/canary-wasm/Cargo.toml @@ -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"] diff --git a/tools/ci-cdk/canary-wasm/src/lib.rs b/tools/ci-cdk/canary-wasm/src/lib.rs index d2c7ed365a..3a56a67fb8 100644 --- a/tools/ci-cdk/canary-wasm/src/lib.rs +++ b/tools/ci-cdk/canary-wasm/src/lib.rs @@ -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!({ @@ -31,11 +31,12 @@ impl exports::aws::component::canary_interface::Guest for Component { async fn run_canary() -> Result, 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;