Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm: aws-config uses fastrand, which needs a feature patch for WASM compatibility #851

Closed
simbleau opened this issue Jul 21, 2023 · 8 comments
Labels
bug This issue is a bug.

Comments

@simbleau
Copy link

simbleau commented Jul 21, 2023

Describe the bug

To be fixed with #59.

Attempting to compile anything using aws-config on WASM will fail since it uses fastrand.

See the Cargo.toml.

fastrand has a dependency on rand, and rand uses getrandom. getrandom needs to be compiled with the js feature.

Fortunately, fastrand has the undocumented js feature flag to fix this for us. We just need to include it for wasm.

Expected Behavior

Successful compile.

Current Behavior

Fails to compile.

14:35 simbleau on main ~ wasm-pack test --node
[INFO]: 🎯  Checking for the Wasm target...
   Compiling getrandom v0.2.10
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/simbleau/.cargo/registry/src/index.crates.io-6f17d22bba15001f/getrandom-0.2.10/src/lib.rs:285:9
    |
285 | /         compile_error!("the wasm*-unknown-unknown targets are not supported by \
286 | |                         default, you may need to enable the \"js\" feature. \
287 | |                         For more information see: \
288 | |                         https://docs.rs/getrandom/#webassembly-support");
    | |________________________________________________________________________^

Reproduction Steps

  • Create a rust lib project.
  • Include in cargo.toml deps: aws-config = { version = "0.55", default-features = false }
  • Compile.

Possible Solution

Here's the fix to the Cargo.toml:

[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dependencies]
fastrand = { version = "2", features = ["js"] }

[target.'cfg(not(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dependencies]
fastrand = "2"

Additional Information/Context

No response

Version

Main

Environment details (OS name and version, etc.)

MacOS Ventura

Logs

No response

@simbleau simbleau added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 21, 2023
@Velfi Velfi removed the needs-triage This issue or PR still needs to be triaged. label Jul 21, 2023
@Velfi
Copy link
Contributor

Velfi commented Jul 21, 2023

Hey @simbleau, thanks for submitting this issue. We'll add it to our backlog.

To whomever picks this one up: It looks like we should consider making the source of randomness configurable, just like we did for the async sleep impl and the time source.

@jdisanti
Copy link
Contributor

getrandom is also an optional dependency for fastrand, so we could consider disabling it as well. I ran into other issues with getrandom last week and started removing it. I'll check to see if it's completely gone for the next release.

@jdisanti
Copy link
Contributor

It looks like in the latest code, rand and getrandom are no longer pulled in, so this should be resolved with the next release.

@jdisanti jdisanti added the pending-release This issue will be fixed by an approved PR that hasn't been released yet. label Jul 21, 2023
@jdisanti
Copy link
Contributor

I think you can work around this in the current release of aws-config by setting no-default-features.

@simbleau
Copy link
Author

I think you can work around this in the current release of aws-config by setting no-default-features.

By current release, do you mean 0.55?

If so, then that is not correct. I didn't have default features (in the reproduction steps).

@jdisanti
Copy link
Contributor

jdisanti commented Jul 21, 2023

Hmmm. OK, I didn't look into that thoroughly enough. I saw that our integration test for webassembly was depending on aws-config with no default features, and it is currently passing, but that may be a more recent development.

Edit: I think I see why: the test is specifically targeting wasm32-wasi. We need to have one for wasm32-unknown-unknown.

@jdisanti
Copy link
Contributor

jdisanti commented Aug 3, 2023

This has been fixed in the August 3rd release.

@jdisanti jdisanti closed this as completed Aug 3, 2023
@github-actions
Copy link

github-actions bot commented Aug 3, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@rcoh rcoh removed the pending-release This issue will be fixed by an approved PR that hasn't been released yet. label Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants