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

Using aHash 0.5 with wasm #59

Closed
emilk opened this issue Nov 6, 2020 · 8 comments
Closed

Using aHash 0.5 with wasm #59

emilk opened this issue Nov 6, 2020 · 8 comments

Comments

@emilk
Copy link
Contributor

emilk commented Nov 6, 2020

Hi!

I found a small issue when using aHash with --target wasm32-unknown-unknown. Starting in aHash version 0.5 I get this:

error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
   --> /Users/emil.ernerfeldt/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.0/src/lib.rs:224:9
    |
224 | /         compile_error!("target is not supported, for more information see: \
225 | |                         https://docs.rs/getrandom/#unsupported-targets");
    | |_________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared type or module `imp`
   --> /Users/emil.ernerfeldt/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.2.0/src/lib.rs:246:5
    |
246 |     imp::getrandom_inner(dest)
    |     ^^^ use of undeclared type or module `imp`

There is a simple workaround:

ahash = { version = "0.5", features = ["std"], default-features = false }
getrandom = { version = "0.2", features = ["js"] } # used by ahash

I was wondering if aHash could have some helpful feature flag for this (features = ["std", "wasm"]), or maybe even detect the wasm32 target? I'm not great with how Cargo.toml dependencies work :)

PS: I really love using aHash as a faster drop-in replacement for HashMap and HashSet.

@tkaitchuck
Copy link
Owner

Per the doc here it seems like this occurs because its not clear which interface it should use on wasm32-unknown-unknown. So if aHash were to set the "js" flag on getrandom it would be wrong if javascript were not available. So I don't know if there is anything I can directly do. There is some discussion of this issue here.

The only direct workaround I see is to do what you have outlined above or to depend on either wasm-bindgen-getrandom or stdweb-getrandom.

@emilk
Copy link
Contributor Author

emilk commented Nov 7, 2020

Ah, yeah that makes sense.

What is aHash using randomness for? Is it to defeat DOS attacks? Can it be made an opt-in?

@emilk
Copy link
Contributor Author

emilk commented Nov 7, 2020

I just realized I need my project to compile and work where there is no (easy) source of randomness (inside of wasmtime), so I think I'm forced to revert to aHash version 0.4 until there is a way to opt-out of the random source in aHash.

@tkaitchuck
Copy link
Owner

What is aHash using randomness for? Is it to defeat DOS attacks? Can it be made an opt-in?

Yes, and it is. See https://github.com/tkaitchuck/aHash/blob/master/compare/readme.md#dos-resistance

@tkaitchuck
Copy link
Owner

I just realized I need my project to compile and work where there is no (easy) source of randomness (inside of wasmtime), so I think I'm forced to revert to aHash version 0.4 until there is a way to opt-out of the random source in aHash.

No need to do that, just disable the std feature and enable compile-time-rng instead.

@emilk
Copy link
Contributor Author

emilk commented Nov 8, 2020

No need to do that, just disable the std feature and enable compile-time-rng instead.

If I do that I don't have access to AHashMap, since that requires the std feature to be enabled.

@tkaitchuck
Copy link
Owner

tkaitchuck commented Nov 9, 2020

This may be orthogonal, but isn't wasmtime wasm32‑wasi rather than the more generic wasm32-unknown-unknown?
There is also some discussion here worth reading: rust-lang/futures-rs#1804

@emilk
Copy link
Contributor Author

emilk commented Nov 9, 2020

@tkaitchuck wasi is pretty new and experimental, and I would like my library to also work without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants