This is a cargo generate template for developing Solana programs using the Anchor framework, optimized for IntelliJ RustRover on Linux Ubuntu. It provides a fully-configured development environment with ready-to-use run configurations, Rust toolchains, and build/test workflows.
This template is designed to help developers quickly set up and start building Solana programs using the Anchor framework within IntelliJ RustRover on Linux Ubuntu. It includes pre-configured tools for building, testing, deploying, and formatting Rust-based Solana programs.
- Pre-configured Run Configurations for quick access to building, testing, and deploying the program.
- Anchor Build: For compiling the Solana program.
- Anchor Test: To run your tests.
- Anchor Deploy: For deploying the program to a cluster (e.g., Devnet).
- Run with Environment Variables: Customized configuration to set up environment variables for the Solana cluster and wallet path.
- 🚀 Pre-configured Anchor Framework for Solana smart contract development.
- 🛠 IntelliJ RustRover Optimized: IntelliJ run configurations for building, testing, and deploying Solana programs.
- 🧰 Rust Toolchains and Cargo Configurations: Ensuring consistent builds and formats across different environments.
- ✅ Rust formatting and linting: Integrated
rustfmt
andclippy
support to keep your code clean and efficient.
Before using this template, make sure you have the following dependencies installed on your Linux Ubuntu system:
Install the Rust programming language using rustup
, the Rust toolchain installer:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
Ensure that cargo
(Rust’s package manager) is available in your terminal by running:
cargo --version
The Solana CLI allows you to interact with the Solana network and deploy programs. To install the Solana CLI tools, run the following commands:
sh -c "$(curl -sSfL https://release.solana.com/v1.10.31/install)"
Add Solana CLI to your environment by adding this line to your ~/.bashrc
or ~/.zshrc
:
export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"
Reload your terminal or source your .bashrc
:
source ~/.bashrc
Verify the Solana CLI installation:
solana --version
The Anchor CLI provides the necessary tools to develop Solana smart contracts using the Anchor framework. To install it, run the following command:
cargo install --git https://github.com/coral-xyz/anchor anchor-cli --locked
Verify the installation:
anchor --version
To use this template with cargo generate
, you need to install cargo-generate:
cargo install cargo-generate
Verify the installation:
cargo generate --version
Once the prerequisites are installed, you can use this template to create a new project.
-
Generate a new project using the template:
cargo generate --git https://github.com/yourusername/solana-anchor-rustrover-template.git --name {{project-name}} cd {{project-name}}
-
Build the project:
anchor build
-
Run tests:
anchor test
-
Install IntelliJ RustRover: Download and install IntelliJ RustRover from the JetBrains website.
-
Open the Project: Open the generated project in IntelliJ RustRover.
-
Configure the Rust Toolchain: RustRover should automatically detect the Rust toolchain. If not, go to Settings > Languages & Frameworks > Rust and set the toolchain path to
~/.cargo/bin
. -
Run Configurations: RustRover includes pre-configured run configurations to simplify development:
- Anchor Build: Builds the Solana program.
- Anchor Test: Runs the test suite.
- Anchor Deploy: Deploys the program to the Solana network.
- Run with Env: A custom run configuration that sets environment variables for the Solana cluster (
ANCHOR_PROVIDER_URL
) and wallet (ANCHOR_WALLET
).
You can access these configurations directly from the Run/Debug menu in RustRover.
The run configurations are visible directly in the IDE, offering quick access to build, test, deploy, and custom environment variable runs.
Once everything is set up, you can use the following commands to build, test, and deploy your Solana program.
-
Build the project:
anchor build
-
Run tests:
anchor test
-
Deploy the program (optional): If you want to deploy the program to a Solana cluster (e.g.,
devnet
), use the following command:anchor deploy --provider.cluster devnet
This template is pre-configured with Rust's formatting and linting tools. You can use these commands to keep your code clean and optimized:
-
Format your code using
rustfmt
:cargo fmt
-
Lint your code using
clippy
:cargo clippy
If you encounter any permissions issues while installing or running commands, prepend the command with sudo
:
sudo anchor build
If your terminal doesn’t recognize commands like solana
, ensure that the Solana CLI path is added to your shell configuration file (~/.bashrc
or ~/.zshrc
). Then, reload the terminal:
source ~/.bashrc
Ensure you have installed all necessary libraries, including libssl-dev
, pkg-config
, and build-essential
:
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev pkg-config
This project is licensed under the MIT License. See the LICENSE file for more details.