From 6b59ba26c41a03983de7321795681da137dffc02 Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Thu, 18 Apr 2024 16:19:22 -0500 Subject: [PATCH] Fix compiling S3 crate for wasm (#3590) ## Motivation and Context Running `cargo build --target wasm32-unknown-unknown --no-default-features` on an S3 crate has stopped working since https://github.com/smithy-lang/smithy-rs/pull/3465 with the following error: ``` error: the wasm*-unknown-unknown targets are not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support --> /Users/[REDACTED]/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.14/src/lib.rs:352:9 | 352 | / compile_error!("the wasm*-unknown-unknown targets are not supported by \ 353 | | default, you may need to enable the \"js\" feature. \ 354 | | For more information see: \ 355 | | https://docs.rs/getrandom/#webassembly-support"); | |________________________________________________________________________^ ``` To address the issue, this PR updates an S3's dependency on `ahash` in a way that disables default features. ## Testing Updated the existing test `integration-tests/webassembly` so that `check-aws-sdk-standalone-integration-tests` will run `cargo check` `aws-sdk-s3` against both `wasm32-wasi` and `wasm32-unknown-unknown` (the updated check would break if we removed `default-features = false` from the `ahash` dependency). ## Checklist - [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --- CHANGELOG.next.toml | 9 ++++++++- aws/rust-runtime/aws-inlineable/Cargo.toml | 2 +- aws/sdk/integration-tests/test.sh | 5 ++++- aws/sdk/integration-tests/webassembly/.cargo/config.toml | 2 +- .../smithy/rust/codegen/core/rustlang/CargoDependency.kt | 2 +- .../check-aws-sdk-standalone-integration-tests | 2 +- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 2739fcc120..84ffc76d30 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -33,4 +33,11 @@ author = "avandesa" message = "Change some credentials related info log messages to debug." references = ["smithy-rs#3546"] meta = { "breaking" = false, "tada" = false, "bug" = false } -author = "orf" \ No newline at end of file +author = "orf" + + +[[aws-sdk-rust]] +message = "Fix an S3 crate's dependency on `ahash` so the crate can be compiled for `wasm32-unknown-unknown`." +references = ["smithy-rs#3590", "aws-sdk-rust#1131"] +meta = { "breaking" = false, "tada" = false, "bug" = true } +author = "ysaito1001" diff --git a/aws/rust-runtime/aws-inlineable/Cargo.toml b/aws/rust-runtime/aws-inlineable/Cargo.toml index 66e8f7ff0b..4d987fe62f 100644 --- a/aws/rust-runtime/aws-inlineable/Cargo.toml +++ b/aws/rust-runtime/aws-inlineable/Cargo.toml @@ -15,7 +15,7 @@ repository = "https://github.com/smithy-lang/smithy-rs" # Used by lru, and this forces it to be a later version that avoids # https://github.com/tkaitchuck/aHash/issues/200 # when built with `cargo update -Z minimal-versions` -ahash = "0.8.11" +ahash = { version = "0.8.11", default-features = false } aws-credential-types = { path = "../aws-credential-types" } aws-runtime = { path = "../aws-runtime", features = ["http-02x"] } aws-sigv4 = { path = "../aws-sigv4" } diff --git a/aws/sdk/integration-tests/test.sh b/aws/sdk/integration-tests/test.sh index 88026f6d7c..6d230a73c6 100755 --- a/aws/sdk/integration-tests/test.sh +++ b/aws/sdk/integration-tests/test.sh @@ -16,7 +16,10 @@ for f in *; do else # The webassembly tests use a custom runner set in config.toml that # is not picked up when running the tests outside of the package - cd webassembly && cargo component test --all-features --all-targets && cd .. + # The tests are written for `wasm32-wasi` but the manifest config also specifies + # `wasm32-unknown-unknown` so we can ensure the test build on that platform as well. + # For executing the tests, however, we explicitly choose a target `wasm32-wasi`. + cd webassembly && cargo component test --all-features --target wasm32-wasi && cd .. fi fi done diff --git a/aws/sdk/integration-tests/webassembly/.cargo/config.toml b/aws/sdk/integration-tests/webassembly/.cargo/config.toml index 06b75c8e09..37f9ac58f5 100644 --- a/aws/sdk/integration-tests/webassembly/.cargo/config.toml +++ b/aws/sdk/integration-tests/webassembly/.cargo/config.toml @@ -1,5 +1,5 @@ [build] -target = "wasm32-wasi" +target = ["wasm32-unknown-unknown", "wasm32-wasi"] [target.wasm32-wasi] rustflags = ["-C", "opt-level=1"] diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt index 07a6a4c02a..444f65a09e 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt @@ -244,7 +244,7 @@ data class CargoDependency( companion object { // Forces AHash to be a later version that avoids // https://github.com/tkaitchuck/aHash/issues/200 - val AHash: CargoDependency = CargoDependency("ahash", CratesIo("0.8.11")) + val AHash: CargoDependency = CargoDependency("ahash", CratesIo("0.8.11"), defaultFeatures = false) val OnceCell: CargoDependency = CargoDependency("once_cell", CratesIo("1.16")) val Url: CargoDependency = CargoDependency("url", CratesIo("2.3.1")) val Bytes: CargoDependency = CargoDependency("bytes", CratesIo("1.0.0")) diff --git a/tools/ci-scripts/check-aws-sdk-standalone-integration-tests b/tools/ci-scripts/check-aws-sdk-standalone-integration-tests index 9ba41631dc..cf843112e8 100755 --- a/tools/ci-scripts/check-aws-sdk-standalone-integration-tests +++ b/tools/ci-scripts/check-aws-sdk-standalone-integration-tests @@ -42,7 +42,7 @@ cargo check --tests --all-features # Running WebAssembly (WASI) specific integration tests pushd "${tmp_dir}/aws/sdk/integration-tests/webassembly" &>/dev/null -cargo check --tests --all-features +cargo check --tests --all-features --all-targets popd popd