Skip to content
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

npm run build:program-rust -> macOS and Linux error: could not compile getrandom (lib) #652

Open
ethanchain opened this issue Oct 4, 2024 · 4 comments

Comments

@ethanchain
Copy link

I tried running the npm run build:program-rust command on both macOs and Linux systems, and the output is shown below:

> [email protected] build:program-rust
> cargo build-bpf --manifest-path=./src/program-rust/Cargo.toml --bpf-out-dir=dist/program
...
error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
   --> src/lib.rs:224:9
    |
224 | /         compile_error!("target is not supported, for more information see: \
225 | |                         https://docs.rs/getrandom/#unsupported-targets");
    | |________________________________________________________________________^

   Compiling bv v0.11.1
   Compiling num_cpus v1.13.1
error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> src/lib.rs:246:5
    |
246 |     imp::getrandom_inner(dest)
    |     ^^^ use of undeclared crate or module `imp`

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

Environment:

$ rustup show # WSL
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/ethan/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu (default)
1.78.0-x86_64-unknown-linux-gnu
solana

active toolchain
----------------

stable-x86_64-unknown-linux-gnu (default)
rustc 1.81.0 (eeb90cda1 2024-09-04)
$ rustup show # MacBook
Default host: x86_64-apple-darwin
rustup home:  /Users/chansen/.rustup

installed toolchains
--------------------

stable-x86_64-apple-darwin (default)
1.76.0-x86_64-apple-darwin
solana

active toolchain
----------------

stable-x86_64-apple-darwin (default)
rustc 1.79.0 (129f3b996 2024-06-10)
$ solana -vV
solana-cli 1.18.24 (src:7ba2a0e9; feat:3241752014, client:Agave)

This seems to be a bug or version problem of crate getrandom, but the example-helloworld project does not directly depend on getrandom, so it may be a version problem of solana-program, or it may be a problem of getrandom.

@ethanchain
Copy link
Author

ethanchain commented Oct 4, 2024

I paid attention to the versions and dependencies of solana-program and solana-sdk, especially the version of getrandom. The versions of solana-program and solana-sdk are basically the same. This may be due to historical reasons. The 1.10.35 version of solana-program depends on the getrandom version ^0.1, and solana-sdk directly depends on solana-program, whose versions are the same. . The latest solana-program version is 2.0.13, the dependent getrandom version is ^0.2.10, and the latest version of getrandom is 0.2.15. In addition, I also noticed the fact that the 0.1.10 and 0.1.9 versions of getrandom are yanked. I also checked the open issues in getrandom’s GitHub repo.
I tried to update the solana-related versions that Cargo.toml depends on to the latest version, which is 2.0.13. Then run the compiled program, deploy the program to the local blockchain, and run the client's TypeScript code. Everything runs successfully.
Mainly updated the solana-related version that the Cargo.tmol file depends on to the latest version. The following is the relevant code changes:

[dependencies]
solana-program = "2.0.13"

[dev-dependencies]
solana-program-test = "2.0.13"
solana-sdk = "2.0.13"

@WeaiKhanOshi
Copy link

Solution: #648

@ethanchain
Copy link
Author

ethanchain commented Nov 1, 2024

I refer to #648, adding getrandom = { version = "0.2.14", features = ["custom"] } to Cargo.toml. When run npm run build:program-rust, certainly solana-program = "~1.10.35", so did solana-program-test and solana-sdk. Print like this: (In order to describe the problem more accurately, I have not omitted the terminal output below.)

> [email protected] build:program-rust
> cargo build-bpf --manifest-path=./src/program-rust/Cargo.toml --bpf-out-dir=dist/program

   Compiling proc-macro2 v1.0.88
   Compiling unicode-ident v1.0.3
   Compiling serde v1.0.210
   Compiling version_check v0.9.5
   Compiling typenum v1.15.0
   Compiling cfg-if v1.0.0
   Compiling syn v1.0.99
   Compiling autocfg v1.1.0
   Compiling crunchy v0.2.2
   Compiling semver v1.0.23
   Compiling subtle v2.4.1
   Compiling crossbeam-utils v0.8.20
   Compiling getrandom v0.1.16
   Compiling libc v0.2.161
   Compiling crossbeam-epoch v0.9.5
   Compiling scopeguard v1.2.0
   Compiling wasm-bindgen-shared v0.2.95
   Compiling lazy_static v1.4.0
   Compiling rayon-core v1.12.1
   Compiling getrandom v0.2.15
   Compiling log v0.4.22
   Compiling unicode-xid v0.2.2
   Compiling once_cell v1.20.2
   Compiling either v1.6.1
   Compiling bumpalo v3.12.0
   Compiling generic-array v0.14.7
   Compiling ahash v0.7.6
   Compiling feature-probe v0.1.1
   Compiling shlex v1.3.0
   Compiling im v15.1.0
   Compiling rand_core v0.5.1
   Compiling rustc_version v0.4.0
   Compiling bv v0.11.1
   Compiling memoffset v0.6.4
   Compiling rand_core v0.6.3
   Compiling thiserror v1.0.64
   Compiling ppv-lite86 v0.2.10
   Compiling block-padding v0.2.1
   Compiling rustversion v1.0.18
   Compiling rand_pcg v0.2.1
   Compiling num-traits v0.2.19
   Compiling rand_xoshiro v0.6.0
   Compiling arrayref v0.3.9
   Compiling wasm-bindgen v0.2.95
   Compiling opaque-debug v0.3.0
   Compiling solana-frozen-abi-macro v1.10.41
   Compiling rand_chacha v0.2.2
   Compiling solana-frozen-abi v1.10.41
   Compiling solana-program v1.10.41
   Compiling hashbrown v0.11.2
   Compiling quote v1.0.37
   Compiling rand v0.7.3
   Compiling memmap2 v0.5.10
   Compiling bs58 v0.4.0
   Compiling constant_time_eq v0.3.1
   Compiling arrayvec v0.7.6
   Compiling syn v2.0.82
   Compiling keccak v0.1.5
   Compiling byteorder v1.5.0
   Compiling base64 v0.12.3
   Compiling crossbeam-deque v0.8.2
   Compiling bitmaps v2.1.0
   Compiling itertools v0.10.3
   Compiling base64 v0.13.0
   Compiling bitflags v1.3.2
   Compiling rayon v1.10.0
   Compiling sized-chunks v0.6.5
   Compiling jobserver v0.1.32
   Compiling cc v1.1.31
   Compiling blake3 v1.5.1
   Compiling wasm-bindgen-backend v0.2.95
   Compiling synstructure v0.12.4
   Compiling borsh-schema-derive-internal v0.9.3
   Compiling borsh-derive-internal v0.9.3
   Compiling borsh-schema-derive-internal v0.10.4
   Compiling borsh-derive-internal v0.10.4
   Compiling serde_derive v1.0.210
   Compiling thiserror-impl v1.0.64
   Compiling bytemuck_derive v1.8.0
   Compiling wasm-bindgen-macro-support v0.2.95
   Compiling zeroize_derive v1.3.3
   Compiling solana-sdk-macro v1.10.41
   Compiling num-derive v0.3.3
   Compiling zeroize v1.3.0
   Compiling wasm-bindgen-macro v0.2.95
   Compiling bytemuck v1.19.0
   Compiling toml v0.5.8
   Compiling serde_bytes v0.11.15
   Compiling bincode v1.3.3
   Compiling digest v0.9.0
   Compiling libsecp256k1-core v0.2.2
   Compiling crypto-common v0.1.6
   Compiling block-buffer v0.10.2
   Compiling crypto-mac v0.8.0
   Compiling block-buffer v0.9.0
   Compiling hmac v0.8.1
   Compiling curve25519-dalek v3.2.1
   Compiling sha2 v0.9.9
   Compiling digest v0.10.7
   Compiling hmac-drbg v0.3.0
   Compiling proc-macro-crate v0.1.5
   Compiling sha2 v0.10.8
   Compiling sha3 v0.10.8
   Compiling borsh-derive v0.9.3
   Compiling borsh-derive v0.10.4
   Compiling libsecp256k1-gen-ecmult v0.2.1
   Compiling libsecp256k1-gen-genmult v0.2.1
   Compiling libsecp256k1 v0.6.0
   Compiling borsh v0.9.3
Error: Function _ZN209_$LT$curve25519_dalek..window..NafLookupTable8$LT$curve25519_dalek..backend..serial..curve_models..ProjectiveNielsPoint$GT$$u20$as$u20$core..convert..From$LT$$RF$curve25519_dalek..edwards..EdwardsPoint$GT$$GT$4from17hbbd3b8b52cf36b25E Stack offset of 11048 exceeded max offset of 4096 by 6952 bytes, please minimize large stack variables
Error: Function _ZN205_$LT$curve25519_dalek..window..NafLookupTable8$LT$curve25519_dalek..backend..serial..curve_models..AffineNielsPoint$GT$$u20$as$u20$core..convert..From$LT$$RF$curve25519_dalek..edwards..EdwardsPoint$GT$$GT$4from17h3921bb71d4ce2f2dE Stack offset of 8352 exceeded max offset of 4096 by 4256 bytes, please minimize large stack variables
Error: Function _ZN116_$LT$curve25519_dalek..edwards..EdwardsBasepointTableRadix16$u20$as$u20$curve25519_dalek..traits..BasepointTable$GT$6create17hdd5f5de80d9cef05E Stack offset of 31832 exceeded max offset of 4096 by 27736 bytes, please minimize large stack variables
Error: Function _ZN116_$LT$curve25519_dalek..edwards..EdwardsBasepointTableRadix32$u20$as$u20$curve25519_dalek..traits..BasepointTable$GT$6create17hd48d5fe34c761da5E Stack offset of 63528 exceeded max offset of 4096 by 59432 bytes, please minimize large stack variables
Error: Function _ZN116_$LT$curve25519_dalek..edwards..EdwardsBasepointTableRadix64$u20$as$u20$curve25519_dalek..traits..BasepointTable$GT$6create17h2d282d14f67fde13E Stack offset of 236832 exceeded max offset of 4096 by 232736 bytes, please minimize large stack variables
Error: Function _ZN117_$LT$curve25519_dalek..edwards..EdwardsBasepointTableRadix128$u20$as$u20$curve25519_dalek..traits..BasepointTable$GT$6create17h0215b383ecdfc8b2E Stack offset of 491688 exceeded max offset of 4096 by 487592 bytes, please minimize large stack variables
Error: Function _ZN117_$LT$curve25519_dalek..edwards..EdwardsBasepointTableRadix256$u20$as$u20$curve25519_dalek..traits..BasepointTable$GT$6create17h4526c62b6365ebdcE Stack offset of 983208 exceeded max offset of 4096 by 979112 bytes, please minimize large stack variables
Error: Function _ZN212_$LT$curve25519_dalek..window..LookupTableRadix64$LT$curve25519_dalek..backend..serial..curve_models..ProjectiveNielsPoint$GT$$u20$as$u20$core..convert..From$LT$$RF$curve25519_dalek..edwards..EdwardsPoint$GT$$GT$4from17h8f2d1cc9727c5efdE Stack offset of 5776 exceeded max offset of 4096 by 1680 bytes, please minimize large stack variables
Error: Function _ZN208_$LT$curve25519_dalek..window..LookupTableRadix64$LT$curve25519_dalek..backend..serial..curve_models..AffineNielsPoint$GT$$u20$as$u20$core..convert..From$LT$$RF$curve25519_dalek..edwards..EdwardsPoint$GT$$GT$4from17hd17db0ea2ed3c158E Stack offset of 4360 exceeded max offset of 4096 by 264 bytes, please minimize large stack variables
Error: Function _ZN213_$LT$curve25519_dalek..window..LookupTableRadix128$LT$curve25519_dalek..backend..serial..curve_models..ProjectiveNielsPoint$GT$$u20$as$u20$core..convert..From$LT$$RF$curve25519_dalek..edwards..EdwardsPoint$GT$$GT$4from17h0f16c5ca135262afE Stack offset of 10896 exceeded max offset of 4096 by 6800 bytes, please minimize large stack variables
Error: Function _ZN209_$LT$curve25519_dalek..window..LookupTableRadix128$LT$curve25519_dalek..backend..serial..curve_models..AffineNielsPoint$GT$$u20$as$u20$core..convert..From$LT$$RF$curve25519_dalek..edwards..EdwardsPoint$GT$$GT$4from17h1cd17ac167d6e07cE Stack offset of 8200 exceeded max offset of 4096 by 4104 bytes, please minimize large stack variables
Error: Function _ZN213_$LT$curve25519_dalek..window..LookupTableRadix256$LT$curve25519_dalek..backend..serial..curve_models..ProjectiveNielsPoint$GT$$u20$as$u20$core..convert..From$LT$$RF$curve25519_dalek..edwards..EdwardsPoint$GT$$GT$4from17hcde3b713fc4ef7adE Stack offset of 21136 exceeded max offset of 4096 by 17040 bytes, please minimize large stack variables
Error: Function _ZN209_$LT$curve25519_dalek..window..LookupTableRadix256$LT$curve25519_dalek..backend..serial..curve_models..AffineNielsPoint$GT$$u20$as$u20$core..convert..From$LT$$RF$curve25519_dalek..edwards..EdwardsPoint$GT$$GT$4from17h8f8b9eaad912f082E Stack offset of 15880 exceeded max offset of 4096 by 11784 bytes, please minimize large stack variables
Error: Function _ZN112_$LT$solana_program..instruction..InstructionError$u20$as$u20$solana_frozen_abi..abi_example..AbiEnumVisitor$GT$13visit_for_abi17h889329966ace958fE Stack offset of 4448 exceeded max offset of 4096 by 352 bytes, please minimize large stack variables
   Compiling solana-bpf-helloworld v0.0.1 (/home/ethan/solana-ws/example-helloworld/src/program-rust)
    Finished release [optimized] target(s) in 38.84s

Run solana program deploy dist/program/helloworld.so

Error: ELF error: ELF error: Failed to parse ELF file: Section or symbol name `.data._ZN12wasm_` is longer than `16` bytes

When I switch back to the solution I mentioned above to upgrade solana-program, solana-program-test and solana-sdk version ''~2.0.13 ''. Everything is normal, smart contracts can be deployed on the chain, and smart contracts can be called normally when running front-end code. What can I do?

Environment WSL

@TheShiveshNetwork
Copy link

I wonder if this is an issue related to build-bpf. Initially it fails with the above error but when I switch the build:program-rust command to:

"build:program-rust": "cargo build --manifest-path=./src/program-rust/Cargo.toml"

It builds without any errors.
I'm new to rust and cargo so if anyone could explain the difference it makes, I'd appreciate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants