1

So I'm trying to compile my first Solana smart contract. It's this hello world smart contract:

https://github.com/solana-labs/example-helloworld

Here is my rustc and cargo version:

candid@DESKTOP-5D7VSM9:~/example-helloworld/src/program-rust$ rustc --version
rustc 1.77.2 (25ef9e3d8 2024-04-09)
candid@DESKTOP-5D7VSM9:~/example-helloworld/src/program-rust$ cargo --version
cargo 1.77.2 (e52e36006 2024-03-26)

But here's what happens when I try to compile it:

candid@DESKTOP-5D7VSM9:~/example-helloworld$ npm run build:program-rust

> [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.81
   Compiling unicode-ident v1.0.12
   Compiling serde v1.0.198
   Compiling version_check v0.9.4
   Compiling typenum v1.17.0
   Compiling cfg-if v1.0.0
   Compiling syn v1.0.109
   Compiling crunchy v0.2.2
   Compiling semver v1.0.22
   Compiling subtle v2.4.1
   Compiling crossbeam-utils v0.8.19
   Compiling getrandom v0.1.16
   Compiling libc v0.2.153
   Compiling generic-array v0.14.7
   Compiling wasm-bindgen-shared v0.2.92
   Compiling rustc_version v0.4.0
   Compiling rand_core v0.5.1
   Compiling rayon-core v1.12.1
   Compiling quote v1.0.36
   Compiling syn v2.0.60
   Compiling crossbeam-epoch v0.9.18
   Compiling ahash v0.7.8
   Compiling getrandom v0.2.14
error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
   --> src/lib.rs:357:9
    |
357 | /         compile_error!("target is not supported, for more information see: \
358 | |                         https://docs.rs/getrandom/#unsupported-targets");
    | |________________________________________________________________________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> src/lib.rs:408:9
    |
408 |         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...
Error: Function _ZN15crossbeam_epoch5guard5Guard5flush17h1d1abe609d5edef4E Stack offset of 4112 exceeded max offset of 4096 by 16 bytes, please minimize large stack variables
Error: Function _ZN15crossbeam_epoch8internal6Global7collect17h6342580b0a7115e4E Stack offset of 4152 exceeded max offset of 4096 by 56 bytes, please minimize large stack variables
Error: Function _ZN15crossbeam_epoch8internal5Local5defer17h479e1780ab35f17aE Stack offset of 4176 exceeded max offset of 4096 by 80 bytes, please minimize large stack variables
Error: Function _ZN15crossbeam_epoch8internal5Local8finalize17h1aa606e306161c72E Stack offset of 4104 exceeded max offset of 4096 by 8 bytes, please minimize large stack variables

I am doing this on WSL2 Ubuntu. The build process is failing because some functions in the crossbeam-epoch crate are using more stack space than is allowed for the target platform.

Any ideas on how to fix this? This is a smart contract I am attempting to build from Solana's own "start building" guides on their official site.

0

1 Answer 1

0

This example is really old unfortunately. I would follow what the README says and instead look at https://solana.com/developers/guides/getstarted/local-rust-hello-world

If you really want to get it to work with the new tools however, you can remove the old Cargo.lock file and update the Cargo.toml to the following:

[package]
name = "solana-bpf-helloworld"
version = "0.0.1"
description = "Example template program written in Rust"
authors = ["Solana Maintainers <[email protected]>"]
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
edition = "2021"

[features]
no-entrypoint = []

[dependencies]
borsh = "0.9.3"
borsh-derive = "0.10.0"
solana-program = "1.10.35"

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

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

I was able to get this to build with the newest tools. The changes are to use rust edition 2021, get rid of the tildes ~ to pick up the newest version, and to remove the "name" under the [lib].

1
  • I got it to compile! Thanks for the assist!
    – Mark
    Commented May 3 at 15:14

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.