rust-random / getrandom

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

Error: target is not supported (cargo build-bpf) #409

Closed zxcfer closed 2 months ago

zxcfer commented 2 months ago

Error why running cargo build-bpf in Linux Virtual Machine, but documentations states that Linux and x86_64 are supported.

$ cargo build-bpf
   Compiling getrandom v0.1.15
error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
   --> src/lib.rs:257:9
    |
257 | /         compile_error!("\
258 | |             target is not supported, for more information see: \
259 | |             https://docs.rs/getrandom/#unsupported-targets\
260 | |         ");
    | |__________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> src/lib.rs:281:5
    |
281 |     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

System details:

$ rustc -vV 
rustc 1.77.1 (7cf61ebde 2024-03-27)
binary: rustc
commit-hash: 7cf61ebde7b22796c69757901dd346d0fe70bd97
commit-date: 2024-03-27
host: x86_64-unknown-linux-gnu
release: 1.77.1
LLVM version: 17.0.6
josephlr commented 2 months ago

Duplicate of #237 cargo build-bpf is a cross compilation command which builds for the Solana target. So you will need to register some sort of custom handler for that target (see the docs). Also see https://github.com/solana-labs/solana/pull/32382

josephlr commented 2 months ago

In fact, it seems Solana documents how to handle this on their custom target: https://solana.com/docs/programs/lang-rust#depending-on-rand