-
Notifications
You must be signed in to change notification settings - Fork 204
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
Support for wasm32-unknown-unknown #223
Comments
We had something similar previously, but have decided against this approach since it's more fragile and spurious runtime errors are much worse than a clear compile-time one. The best solution in my opinion would be to find the exact dependencies which are responsible for pulling in
I don't see how having in your dependencies list |
I agree for the common case of the user compiling with
I can't argue too strongly against this suggestion, but unfortunately the situation is very confusing and I have spent about a day trying to figure out exactly that. If I diff the output of
The difference is that (AIUI) using the custom macro, the macro invocation itself must be in each and every binary crate, which means in each and every application our users write. Whereas
would only be required in the Cargo.toml of our internal crates which depend on the crate whose updated version (apparently, somehow) pulls in |
Have you tried to use
In some cases
The registration macro simply defines an extern function, so it does not have to be used in binary crates. I don't remember details exactly and there may be issues with using it in a dummy getrandom crate, but it should be fine to use in a library crate on which your binaries depend. |
I hadn't. Curiously, they show that getrandom 0.2 was already a dependency even in our master branch. And checking, I can see it building 0.2 in the cargo build output... which was rather confusing until
Thank you! I hadn't known about this. But I think this is the issue I'm running into https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2 "Features enabled on build-dependencies or proc-macros will not be unified when those same dependencies are used as a normal dependency." We have some build dependencies already that depend on Unfortunately it only partially works 😭 if I build
it works! (Without But building the same binary with
it fails in exactly the same way due to trying to compile
In that case the documentation seems incorrect as it states "Functions can only be registered in the root binary crate. Attempting to register a function in a non-root crate will result in a linker error." (unless I'm just misunderstanding what this is saying??) |
Maybe try asking on URLO about this issue? It certainly looks like an issue with Cargo, which ideally should be solved.
Or I might have forgot something. :) I vaguely remember that there were issues with registering function in the same crate which defines it. If you add such crate to your dependencies, but do not use anything from it explicitly, Cargo will decide that it contains only dead code and will not link it (i.e. it does not see the The wording may be intentionally too strong to dissuade users from registering custom crates in libraries since it may result in quite unpleasant linker errors. |
@newpavlov is correct here, the main reason for that statement is to prevent uses from accidentally having the linker remove their custom implementations. We could update the docs to make this more clear. @randombit if you use the custom handler mechanism in |
Sorry for the delay here I was on another project for some time. There is definitely some Using the custom handler within a library crate (specifically the crate that also brings in the |
Currently
getrandom
works on WASM only in a JS environment. If you try to compile a crate which depends ongetrandom
onwasm32-unknown-unknown
and without thejs
feature, it fails and cannot be made to compile.For context, in the Internet Computer (https://github.com/dfinity/ic) applications are deployed as WASM and without WASI or a JS environment (because the applications are sandboxed and completely deterministic). I am running into exactly this situation, where upgrading a dependency of ours brings in
getrandom 0.2
, and as a result the build fails :( Setting "js" feature doesn't help because there is no JS or WASI.Would you consider (for
wasm32-unknown-unknown
only) an additional feature "unimplemented" analogous to the "js" feature, but which just hasgetrandom
returnErr(UNSUPPORTED)
in all cases. I would be happy to contribute a patch along these lines if it would be accepted.I know this can be emulated using https://docs.rs/getrandom/0.2.3/getrandom/macro.register_custom_getrandom.html but the downside there is it requires each
bin
crate to set the getrandom handler specially. In our case thegetrandom
dependency arises deep in the dep tree and we do not actually needgetrandom
to work at all, so pushing this task onto each and every person who would choose to write an application to run on the IC is a non-starter. In contrast if we can set the feature within our own crates then everything should just work.The text was updated successfully, but these errors were encountered: