Skip to content

20 usd in crypto to whoever can help me solve this getrandom error when i run anchor build #14294

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

Closed
luckydog6969 opened this issue Jul 24, 2024 · 7 comments
Labels
S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@luckydog6969
Copy link

luckydog6969 commented Jul 24, 2024

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!

@weihanglo
Copy link
Member

Please provide a detailed reproduction for the error you're encountering. Incentivization won't prioritize your issue if no MCVE provided.

@weihanglo
Copy link
Member

BTW cargo tree could help you find why rand is included in the dependency graph. Something like cargo tree -i rand -e features.

@weihanglo weihanglo added S-triage Status: This issue is waiting on initial triage. S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed S-triage Status: This issue is waiting on initial triage. labels Jul 24, 2024
@epage
Copy link
Contributor

epage commented Jul 24, 2024

You also mentioned that this problem happens with anchor build but not cargo build. It might be more helpful to reach out on an anchor support channel in case there is anything unique they are doing to cargo.

And generally, cargo user support questions are better addressed at https://users.rust-lang.org/ while this is more targeted for when behavior seems to be incorrect.

@luckydog6969
Copy link
Author

luckydog6969 commented Jul 24, 2024

  • rand v0.7.3
    • Pulled by:
      • ed25519-dalek v1.0.1
        • Used by ed25519-dalek-bip32 v0.2.0
          • Which is a dependency for solana-sdk v1.18.19 and subsequently anchor-client v0.29.0, orao-solana-vrf v0.4.0, and other Solana-based dependencies.
      • libsecp256k1 v0.6.0
        • Used directly in your project's Solana program code (linked via solana-program v1.18.19).

@luckydog6969
Copy link
Author

luckydog6969 commented Jul 24, 2024

program cargo.toml:

[package]
name = "LD"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "LD"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = "0.29.0"
orao-solana-vrf = { version = "0.4.0", default-features = false, features = ["cpi", "sdk"] }
spl-token = { version = "4.0.0", features = ["no-entrypoint"] }
solana-program = "1.18.19"
anchor-spl = "0.29.0"
clock = "0.3.3"
scopeguard = "1.2.0"
anchor-client = { version = "0.29.0", optional = true }
solana-account-decoder = "1.18.19"
solana-sdk = { version = "1.18.19", default-features = false }

problem appears when i add anchor client as a dependency. everything else in my program are default. (i did not add any logic to my lib.rs yet) other than that the only other modificaiton i made outside this file was setting the resolver to "2" in my root cargo.toml

@weihanglo
Copy link
Member

@luckydog6969 Without a minimal reproducible example, this is not going to move forward. Check these issues as examples of how to provide an MRE.

To provide an MRE, you can either setup a Git repository, or send a zip file of the affected project here.

@weihanglo
Copy link
Member

You also mentioned that this problem happens with anchor build but not cargo build. It might be more helpful to reach out on an anchor support channel in case there is anything unique they are doing to cargo.

Given this. I am going to close the issue now. If later you find it is potentially a Cargo bug, feel free to open a new one.

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

No branches or pull requests

3 participants