-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support compiling to webassembly (#2254)
* feat(aws-config): define default feature for sso * chore(aws): disable unused features * chore(rust-runtime): disable unused features * chore: add missing tokio fs feature * chore: disable spawn blocking on wasm * chore: fix sso feature * chore: allow unused variables when not sso * chore: remove unnecessary dependency filter for wasm * chore: add integration test for wasm * chore: ensure test-util feature is applied to dev dependencies * chore: disable retry config Co-authored-by: John DiSanti <[email protected]> * chore: simplify features as suggested * chore: no default features for aws types * chore: rename credentials-sso feature * Revert "chore: simplify features as suggested" This reverts commit d8fcf49. * chore: set right name in default features * chore: create smithy client test util in runtime types * Update aws/rust-runtime/aws-types/Cargo.toml Co-authored-by: John DiSanti <[email protected]> * Update aws/rust-runtime/aws-inlineable/Cargo.toml Co-authored-by: John DiSanti <[email protected]> * Update aws/rust-runtime/aws-config/src/profile/credentials/exec.rs Co-authored-by: John DiSanti <[email protected]> * Update aws/rust-runtime/aws-config/src/profile/credentials/exec.rs Co-authored-by: John DiSanti <[email protected]> * Update aws/rust-runtime/aws-config/src/profile/credentials/exec.rs Co-authored-by: John DiSanti <[email protected]> * Update aws/rust-runtime/aws-config/src/lib.rs Co-authored-by: John DiSanti <[email protected]> * chore: use hardcoded credentials feature * chore: make wasm example for s3 instead * chore: fix formatting * chore: fix kotlin formatting * chore: fix kotlin unit tests * chore: use timeout config from smithy types * chore: move tests into main file * chore: add vscode setttings to target wasi by default * chore: fix test-util feature for smithy client * chore: separate adapter into own module * chore: fix test with no default features * Fix typo * Update changelog * Check compilation of `aws-config` against `wasm32` in CI * Fix Dockerfile issue and use correct cargo-wasi command * Small Dockerfile fix * Add missing `tar` binary to Docker image --------- Co-authored-by: Eduardo Rodrigues <[email protected]> Co-authored-by: John DiSanti <[email protected]> Co-authored-by: John DiSanti <[email protected]> Co-authored-by: Russell Cohen <[email protected]>
- Loading branch information
1 parent
5c47cba
commit 8e05979
Showing
27 changed files
with
273 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ members = [ | |
"sts", | ||
"transcribestreaming", | ||
"using-native-tls-instead-of-rustls", | ||
"webassembly", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[build] | ||
target = "wasm32-wasi" | ||
|
||
[target.wasm32-wasi] | ||
rustflags = ["-C", "opt-level=1"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"rust-analyzer.cargo.target": "wasm32-wasi" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This Cargo.toml is unused in generated code. It exists solely to enable these tests to compile in-situ | ||
[package] | ||
name = "webassembly" | ||
version = "0.1.0" | ||
authors = ["Eduardo Rodrigues <[email protected]>"] | ||
description = """ | ||
These tests ensure that things will fail (or not fail) as expected | ||
when target is set to wasm32-wasi for all SDK and runtime crates. | ||
""" | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
repository = "https://github.com/awslabs/smithy-rs" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
aws-config = { path = "../../build/aws-sdk/sdk/aws-config", default-features = false, features = ["rt-tokio"]} | ||
aws-credential-types = { path = "../../build/aws-sdk/sdk/aws-credential-types", features = ["hardcoded-credentials"] } | ||
aws-sdk-s3 = { path = "../../build/aws-sdk/sdk/s3", default-features = false } | ||
aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", default-features = false } | ||
aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } | ||
aws-smithy-types = { path = "../../build/aws-sdk/sdk/aws-smithy-types" } | ||
aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } | ||
http = "0.2.8" | ||
tokio = { version = "1.24.2", features = ["macros", "rt"] } | ||
tower = "0.4.13" |
29 changes: 29 additions & 0 deletions
29
aws/sdk/integration-tests/webassembly/src/adapter/http_client.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use aws_smithy_http::body::SdkBody; | ||
|
||
pub(crate) fn make_request(_req: http::Request<SdkBody>) -> Result<http::Response<SdkBody>, ()> { | ||
// Consumers here would pass the HTTP request to | ||
// the Wasm host in order to get the response back | ||
let body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> | ||
<ListAllMyBucketsResult> | ||
<Buckets> | ||
<Bucket> | ||
<CreationDate>2023-01-23T11:59:03.575496Z</CreationDate> | ||
<Name>doc-example-bucket</Name> | ||
</Bucket> | ||
<Bucket> | ||
<CreationDate>2023-01-23T23:32:13.125238Z</CreationDate> | ||
<Name>doc-example-bucket2</Name> | ||
</Bucket> | ||
</Buckets> | ||
<Owner> | ||
<DisplayName>account-name</DisplayName> | ||
<ID>a3a42310-42d0-46d1-9745-0cee9f4fb851</ID> | ||
</Owner> | ||
</ListAllMyBucketsResult>"; | ||
Ok(http::Response::new(SdkBody::from(body))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
mod http_client; | ||
|
||
use aws_smithy_client::erase::DynConnector; | ||
use aws_smithy_client::http_connector::HttpConnector; | ||
use aws_smithy_http::body::SdkBody; | ||
use aws_smithy_http::result::ConnectorError; | ||
use std::task::{Context, Poll}; | ||
use tower::Service; | ||
|
||
#[derive(Default, Debug, Clone)] | ||
pub(crate) struct Adapter {} | ||
|
||
impl Adapter { | ||
pub fn to_http_connector() -> impl Into<HttpConnector> { | ||
DynConnector::new(Adapter::default()) | ||
} | ||
} | ||
|
||
impl Service<http::Request<SdkBody>> for Adapter { | ||
type Response = http::Response<SdkBody>; | ||
|
||
type Error = ConnectorError; | ||
|
||
#[allow(clippy::type_complexity)] | ||
type Future = std::pin::Pin< | ||
Box<dyn std::future::Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>, | ||
>; | ||
|
||
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
Poll::Ready(Ok(())) | ||
} | ||
|
||
fn call(&mut self, req: http::Request<SdkBody>) -> Self::Future { | ||
println!("Adapter: sending request..."); | ||
let res = http_client::make_request(req).unwrap(); | ||
println!("{:?}", res); | ||
Box::pin(async move { Ok(res) }) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
aws/sdk/integration-tests/webassembly/src/default_config.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use aws_config::retry::RetryConfig; | ||
use aws_credential_types::Credentials; | ||
use aws_smithy_types::timeout::TimeoutConfig; | ||
use aws_types::region::Region; | ||
use std::future::Future; | ||
|
||
use crate::adapter::Adapter; | ||
|
||
pub(crate) fn get_default_config() -> impl Future<Output = aws_config::SdkConfig> { | ||
aws_config::from_env() | ||
.region(Region::from_static("us-west-2")) | ||
.credentials_provider(Credentials::from_keys( | ||
"access_key", | ||
"secret_key", | ||
Some("session_token".to_string()), | ||
)) | ||
.timeout_config(TimeoutConfig::disabled()) | ||
.retry_config(RetryConfig::disabled()) | ||
.http_connector(Adapter::to_http_connector()) | ||
.load() | ||
} | ||
|
||
#[tokio::test] | ||
pub async fn test_default_config() { | ||
let shared_config = get_default_config().await; | ||
let client = aws_sdk_s3::Client::new(&shared_config); | ||
assert_eq!(client.conf().region().unwrap().to_string(), "us-west-2") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
mod adapter; | ||
mod default_config; | ||
mod list_buckets; | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
pub async fn main() { | ||
crate::list_buckets::s3_list_buckets().await | ||
} |
Oops, something went wrong.