rust-random / getrandom

A small cross-platform library for retrieving random data from (operating) system source
Apache License 2.0
291 stars 182 forks source link

$20 in $SOL to whoever can help me solve this getrandom error when i run anchor build #493

Closed luckydog6969 closed 3 months ago

luckydog6969 commented 3 months ago

disclaimer im a noob so pls bear with me. anyway, when i run cargo build my program compiles successfully but when i run anchor build i get this error output.

error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
   --> src/lib.rs:267:9
    |
267 | /         compile_error!("\
268 | |             target is not supported, for more information see: \
269 | |             https://docs.rs/getrandom/#unsupported-targets\
270 | |         ");
    | |__________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> src/lib.rs:291:5
    |
291 |     imp::getrandom_inner(dest)
    |     ^^^ use of undeclared crate or module `imp`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `getrandom` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...`.   

according to the documentation of solana (this section corresponds to my error) https://solana.com/docs/programs/lang-rust#depending-on-rand. “Programs are constrained to run deterministically, so random numbers are not available. Sometimes a program may depend on a crate that depends itself on rand even if the program does not use any of the random number functionality. If a program depends on rand, the compilation will fail because there is no get-random support for Solana. “

and it said to add this to the program cargo.toml: getrandom = { version = "0.1.14", features = ["dummy"] }. and getrandom = { version = "0.2.2", features = ["custom"] }.
i tried it and it did not work

givens

if you solve it drop your sol address and ill send you 20 bucks. appreciate the help!

newpavlov commented 3 months ago

I think the easiest solution for you will be to use a patched version of getrandom with panicking getrandom and getrandom_uninit. Alternatively, you could define a custom impl by following the register_custom_getrandom docs.

Sijlvip commented 3 months ago

https://github.com/rust-random/getrandom/issues/493#issuecomment-2247902502