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
- i dont have getrandom as a direct dependency for my program though i have rand 0.8.5 which doesnt pull in getrandom (but rand 0.7.3 does…which i have as a transitive dependency)
- my program seems to be pulling in getrandom 0.1.16 and 0.2.15
- i found that getrandom 0.2.15 is a required dependency of ahash 0.7.8. ahash 0.7.8 is an optional dependency for hashbrown 0.11.2. i tried disabling default features for hashbrown 0.11.2. it did not get rid of ahash 0.7.8
if you solve it drop your sol address and ill send you 20 bucks. appreciate the help!
[package]
name = "ld"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"
[lib]
crate-type = ["cdylib", "lib"]
name = "lucky_dog"
[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []
[dependencies]
anchor-lang = "0.29.0"
anchor-spl = "0.29.0"
spl-token = { version = "4.0.0", features = ["no-entrypoint"] }
orao-solana-vrf = { version = "0.4.0", default-features = false, features = ["cpi", "sdk"] }
solana-program = "1.18.18"
spl-pod = "0.2.5"
solana-zk-token-sdk = "1.18.18"
clock = "0.3.3"
scopeguard = "1.2.0"
anchor-client = { version = "0.29.0", optional = true }
solana-account-decoder = "1.18.18"
solana-sdk = { version = "1.18.18", default-features = false }
getrandom = { version = "0.2.15", features = ["custom"] }```
root cargo.toml:
```[workspace]
members = [
"programs/*"
]
resolver = "2"
[profile.release]
overflow-checks = true
lto = "fat"
codegen-units = 1
[profile.release.build-override]
opt-level = 3
incremental = false
codegen-units = 1```
update i tried adding this "getrandom_01 = { package = "getrandom", version = "0.1.16", features = ["dummy"] }
getrandom_02 = { package = "getrandom", version = "0.2.15", features = ["custom"] }" to my program cargo toml and got 214 errors from the socket 2 crate
getrandom
isn't supported on-chain as noted by Jon C in this answer solana.stackexchange.com/a/14670/1708