7

If I run any program with the solana-program dependency set at or above 1.10 I get the following error:

error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
   --> /Users/James/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.1.16/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`
   --> /Users/James/.cargo/registry/src/github.com-1ecc6299db9ec823/getrandom-0.1.16/src/lib.rs:291:5
    |
291 |     imp::getrandom_inner(dest)
    |     ^^^ use of undeclared crate or module `imp`

Even when solana-program is the only dependency I have and I just do a simple "Hello, world!" program I still get the error, so I'm certain it's not a dependency I'm explicitly pulling in. If I set the version to 1.9.5 or 1.8.something I don't have an issue. Would love to know if anyone else has seen this happen. It's happened to me on multiple Rust versions, so I'm assuming it's not that but at this point idk.

Rust version: 1.62.0
Solana CLI version: 1.8.15
Rustup version: 1.25.1

8
  • Update: also doesn't work when Solana CLI version is 1.9.30
    – jamesrp13
    Commented Jul 20, 2022 at 22:03
  • 1
    UPDATE: narrowed down the culprit to solana-program versions in the 1.11 range. I was having trouble with 1.10 versions only because I wasn't using "=" or "~" before them in the toml file so the version in cargo.lock was being set to 1.11.3. I've now confirmed that "=1.11.1" doesn't work either, but everything I've tried in "=1.10.xx" range and below works but everything in the "=1.11.x" range doesn't.
    – jamesrp13
    Commented Jul 20, 2022 at 23:00
  • So lesson learned is that I'll use "~" to make sure I don't get bumped up to an unexpected version. That being said, I would expect 1.11 to work unless it's not a stable version? Where do I find the latest official stable version number?
    – jamesrp13
    Commented Jul 20, 2022 at 23:11
  • 1
    please be sure to post the resolution as an answer instead of a comment!
    – trent.sol
    Commented Jul 21, 2022 at 0:41
  • Idk that I’m satisfied that it’s solved haha. Like 1.11.1 still builds on some of my colleague’s machines but not mine @trent.sol. Are we calling that resolved or…? Definitely have narrowed the scope of the problem but there’s still an issue I think.
    – jamesrp13
    Commented Jul 21, 2022 at 1:16

4 Answers 4

7

I put this in the comments above but for the sake of clarity here's my full answer here:

  1. I was not as precise as I should have been with specifying the version of the solana-program dependency in the cargo.toml file. For example, 1.10.7 can result in cargo resolving to any version >= 1.10.7 and < 2.0.0, so cargo was resolving to 1.11.3. To solve this, I'm now using ~1.10.7 which ensures that the version remains < 1.11.0.
  2. This matters because my issue seems to only happen when cargo resolves solana-program to a version >= 1.11.0
  3. I am still getting the error on versions >= 1.11.0, but from what I can tell that may be because it's not a stable version. I'm still not 100% on that part, but for now I'm happy to work with versions in the 1.10.x range.

You can see more info about specifying Rust dependencies here

3

This is what I found on the Solana GitHub docs.

To work around this dependency issue, add the following dependency to the program's Cargo.toml:

getrandom = { version = "0.1.14", features = ["dummy"] }

or if the dependency is on getrandom v0.2 add:

getrandom = { version = "0.2.2", features = ["custom"] }

Using version 0.2.2 worked for me.

1

Update the Cargo.toml to contain the following:

getrandom = { version = "0.2.2", features = ["custom"] }
1
  • added this to the crate that indirectly uses getrandom and it helped Commented Jun 21, 2023 at 12:03
0

The answer from @JohnVersus helped me. The docs have now been moved to: https://solana.com/docs/programs/lang-rust#depending-on-rand.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.