Skip to content

Commit

Permalink
Fix compiling S3 crate for wasm (#3590)
Browse files Browse the repository at this point in the history
## Motivation and Context
Running `cargo build --target wasm32-unknown-unknown
--no-default-features` on an S3 crate has stopped working since
#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._
  • Loading branch information
ysaito1001 authored Apr 18, 2024
1 parent 7fbdcc2 commit 6b59ba2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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"
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-inlineable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
5 changes: 4 additions & 1 deletion aws/sdk/integration-tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion aws/sdk/integration-tests/webassembly/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build]
target = "wasm32-wasi"
target = ["wasm32-unknown-unknown", "wasm32-wasi"]

[target.wasm32-wasi]
rustflags = ["-C", "opt-level=1"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6b59ba2

Please sign in to comment.