5

The fact that Solana's CLI installer shipped (and still ships) with a nearly year-long outdated version of platform-tools has been a pain point with the previous Solana team I've worked with. platform-tools itself is also usually behind upstream stable rustc by ~4 months.

I haven't closely examined the diff myself, and I figured that this would be good to post for other devs who have the same question.

Other than partial std support, what are the current, specific, benefits of using the fork of rustc/llvm shipped with platform-tools compared to the built-in bpfel-unknown-none target? Is there anything that would make the output of the bpfel-unknown-none incompatible or otherwise non-viable for Solana contract development?

2 Answers 2

1

To start, you can always upgrade to a newer version of platform tools by specifying --tools-version, ie:

cargo build-sbf --tools-version v1.41

But as for changes in the Solana version of Cargo / Rust / LLVM, the best is to always look directly at the source. The Solana Rust is hosted at https://github.com/anza-xyz/rust, cargo at https://github.com/anza-xyz/cargo, and LLVM at https://github.com/anza-xyz/llvm-project/.

This is extremely high-level, but here are the differences:

  • Cargo mainly needs to pull in different compiler builtins at https://github.com/anza-xyz/compiler-builtins (core instructions). For example, floats are not natively supported in bpf, so the functionality is emulated through these builtins
  • Rust is mainly updated to call into the patched LLVM correctly, especially when it comes to the "SBF" backend
  • LLVM is mostly patched to add the "SBF" backend and to update the kind of BPF instructions emitted by the backend.

So you could probably get pretty far with just a normal bpf backend, as long as you're sure to declare the entrypoint correctly and link the files (https://github.com/anza-xyz/agave/blob/master/sdk/bpf/c/bpf.ld) correctly, and to limit the stack size used by functions to 4096.

-1

For compiling Solana smart contracts, two paths are available: using Solana's custom rustc/LLVM toolchain or the standard Rust bpfel-unknown-none target.

Solana's Custom Toolchain: Optimized for Solana's blockchain, it supports specific eBPF instructions and optimizations for Solana. Use the cargo build-bpf command for compiling smart contracts, ensuring compatibility and efficiency on the Solana platform.

Example command:

cargo build-bpf --manifest-path=path/to/Cargo.toml --bpf-out-dir=./target/deploy

This command compiles the Rust project located at path/to/Cargo.toml into a BPF program, placing the output in ./target/deploy. The cargo-build-bpf tool automatically uses Solana's customized toolchain.

Standard bpfel-unknown-none Target: Part of Rust's ecosystem, designed for a wide range of eBPF applications, but lacks Solana-specific enhancements. Ideal for general eBPF development not targeted at Solana.

Example command:

rustup target add bpfel-unknown-none
cargo build --target=bpfel-unknown-none

The first command ensures you have the bpfel-unknown-none target available in your Rust toolchain. The second command compiles your Rust project for the bpfel-unknown-none target.

Key Differences Optimizations and Compatibility: The main difference is that Solana's toolchain is optimized for its blockchain, potentially producing more efficient and compatible smart contracts for Solana. The standard bpfel-unknown-none target is more generic, suitable for a broader range of eBPF applications but lacking Solana-specific enhancements.

Target Use Case: The choice between these approaches depends on your specific goal. If you're developing exclusively for the Solana platform, using its custom toolchain is advisable to ensure maximum performance and compatibility. For more general eBPF development not intended for Solana, the standard bpfel-unknown-none target may be more appropriate.

1
  • Seems the output of a chatgpt reply honestly Commented May 10 at 22:06

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.