-
Notifications
You must be signed in to change notification settings - Fork 0
adds solana node, anchor, and supporting dependencies [macos] #4
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
00fd255
adds simple nix dev shell
hxrts 5ef47a2
add .gitignore
hxrts 47ab498
functional solana env on macos
hxrts 4bd59aa
Add Solana integration files for testing
hxrts 91acea5
solana integration tested in separate repo
hxrts 767bed1
Fix PR review comments
hxrts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Nix build outputs | ||
result* | ||
.direnv/ | ||
|
||
# Development environments | ||
.vscode/ | ||
.cursor/ | ||
|
||
# Rust/Cargo | ||
target/ | ||
Cargo.lock | ||
**/*.rs.bk | ||
*.pdb | ||
|
||
# macOS | ||
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Temporary files | ||
*.tmp | ||
*.temp | ||
*.log | ||
|
||
# General | ||
*.backup | ||
*.bak | ||
*.orig | ||
|
||
# Working | ||
work/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
# Solana Development | ||
|
||
This document covers how to use zero.nix for Solana development, including setup of the Solana CLI, Anchor framework, and platform tools. | ||
|
||
## Overview | ||
|
||
Zero.nix provides a complete Solana development environment with: | ||
- **Solana CLI** (v2.0.22) - Core Solana command-line tools | ||
- **Anchor CLI** (v0.31.1) - Solana development framework | ||
- **Platform Tools** (v1.48) - Rust compiler and LLVM tools optimized for Solana | ||
- **SBF compilation** - Support for Solana Berkeley Format programs | ||
|
||
## Quick Start | ||
|
||
### Using the Template | ||
|
||
Create a new Solana project using the zero.nix template: | ||
|
||
```bash | ||
nix flake new -t github:timewave-computer/zero.nix#solana-dev my-solana-project | ||
cd my-solana-project | ||
nix develop | ||
``` | ||
|
||
### Manual Setup | ||
|
||
Add zero.nix to your existing Solana project: | ||
|
||
```nix | ||
{ | ||
description = "My Solana project"; | ||
|
||
inputs = { | ||
zero-nix.url = "github:timewave-computer/zero.nix"; | ||
}; | ||
|
||
outputs = { self, zero-nix }: | ||
zero-nix.lib.mkFlake { | ||
inherit self; | ||
src = ./.; | ||
}; | ||
} | ||
``` | ||
|
||
## Development Environment | ||
|
||
### Entering the Development Environment | ||
|
||
```bash | ||
nix develop | ||
``` | ||
|
||
This provides access to: | ||
- `solana` - Solana CLI tools | ||
- `anchor` - Anchor framework CLI | ||
- `cargo-build-sbf` - SBF program compilation | ||
- `setup-solana` - Environment initialization script | ||
|
||
### Environment Setup | ||
|
||
Initialize the Solana development environment: | ||
|
||
```bash | ||
setup-solana | ||
``` | ||
|
||
This script: | ||
- Creates necessary cache directories | ||
- Verifies platform tools installation | ||
- Sets up proper permissions | ||
|
||
## Working with Anchor | ||
|
||
### Creating a New Anchor Project | ||
|
||
```bash | ||
anchor init my-project | ||
cd my-project | ||
``` | ||
|
||
### Building Anchor Programs | ||
|
||
```bash | ||
# Build the program | ||
anchor build | ||
|
||
# Build with SBF compilation | ||
cargo-build-sbf | ||
``` | ||
|
||
### Testing Anchor Programs | ||
|
||
```bash | ||
# Run tests | ||
anchor test | ||
|
||
# Run tests with local validator | ||
anchor test --skip-local-validator | ||
``` | ||
|
||
## Solana CLI Usage | ||
|
||
### Configuration | ||
|
||
```bash | ||
# Configure Solana CLI for devnet | ||
solana config set --url https://api.devnet.solana.com | ||
|
||
# Generate a new keypair | ||
solana-keygen new | ||
|
||
# Check balance | ||
solana balance | ||
``` | ||
|
||
### Local Development | ||
|
||
```bash | ||
# Start local test validator | ||
solana-test-validator | ||
|
||
# Deploy to local cluster | ||
solana program deploy target/deploy/my_program.so | ||
``` | ||
|
||
## Platform Tools | ||
|
||
The zero.nix Solana environment includes platform tools that provide: | ||
- **Rust toolchain** - Optimized for Solana development | ||
- **LLVM tools** - Required for SBF compilation | ||
- **Cargo extensions** - SBF-specific build tools | ||
|
||
### Platform Tools Environment | ||
|
||
Platform tools are automatically configured with: | ||
- `PLATFORM_TOOLS_DIR` - Points to platform tools directory | ||
- `SBF_SDK_PATH` - SDK path for SBF compilation | ||
- `PATH` - Extended to include platform tools | ||
|
||
## SBF Program Development | ||
|
||
### Building SBF Programs | ||
|
||
```bash | ||
# Build SBF programs directly | ||
cargo-build-sbf --manifest-path=Cargo.toml | ||
|
||
# Build with Anchor (recommended) | ||
anchor build | ||
``` | ||
|
||
### SBF Compilation Environment | ||
|
||
The environment automatically configures: | ||
- Rust toolchain compatible with Solana | ||
- LLVM tools for SBF target compilation | ||
- Proper linker settings for macOS | ||
|
||
## Available Tools | ||
|
||
### Core Tools | ||
|
||
- **solana** - Main Solana CLI | ||
- **solana-keygen** - Key generation and management | ||
- **solana-test-validator** - Local test validator | ||
- **anchor** - Anchor framework CLI | ||
- **cargo-build-sbf** - SBF program compilation | ||
|
||
### Development Tools | ||
|
||
- **rustc** - Rust compiler | ||
- **cargo** - Rust package manager | ||
- **rust-analyzer** - Rust language server | ||
- **nodejs** - JavaScript runtime | ||
- **python3** - Python interpreter | ||
|
||
## Configuration | ||
|
||
### Environment Variables | ||
|
||
The development environment automatically sets: | ||
|
||
```bash | ||
MACOSX_DEPLOYMENT_TARGET=11.0 # macOS deployment target | ||
SOLANA_INSTALL_DIR=$HOME/.cache/solana # Solana cache directory | ||
ANCHOR_VERSION=0.31.1 # Anchor version | ||
SOLANA_VERSION=2.0.22 # Solana version | ||
RUST_BACKTRACE=1 # Enable Rust backtraces | ||
PLATFORM_TOOLS_DIR=<nix-store-path> # Platform tools directory (avoids redownloading) | ||
SBF_SDK_PATH=<nix-store-path> # SBF SDK path for compilation | ||
PROTOC=<nix-store-path>/bin/protoc # Protocol buffers compiler | ||
CARGO_HOME=$HOME/.cache/solana/v1.48/cargo # Cargo cache directory (prevents redownloading) | ||
RUSTUP_HOME=$HOME/.cache/solana/v1.48/rustup # Rustup cache directory (prevents redownloading) | ||
``` | ||
|
||
These environment variables ensure that: | ||
- Platform tools are not redownloaded on each build | ||
- SBF compilation uses the pre-installed tools | ||
- Proper macOS deployment target is set | ||
- Debugging information is available | ||
- Cargo and rustup use cached platform tools configuration | ||
|
||
### Custom Configuration | ||
|
||
Override environment variables in your `flake.nix`: | ||
|
||
```nix | ||
{ | ||
outputs = { self, zero-nix }: | ||
zero-nix.lib.mkFlake { | ||
inherit self; | ||
src = ./.; | ||
|
||
devShells.default = zero-nix.devShells.default.override { | ||
shellHook = '' | ||
# Custom solana configuration | ||
solana config set --url https://api.mainnet-beta.solana.com | ||
|
||
# Project-specific setup | ||
echo "My Solana project initialized" | ||
''; | ||
}; | ||
}; | ||
} | ||
``` | ||
|
||
### Debug Mode | ||
|
||
Enable verbose output for debugging: | ||
|
||
```bash | ||
RUST_BACKTRACE=full anchor build | ||
``` | ||
|
||
## Integration with Existing Projects | ||
|
||
### Adding to Existing Rust Projects | ||
|
||
Add zero.nix to your `flake.nix`: | ||
|
||
```nix | ||
{ | ||
inputs = { | ||
zero-nix.url = "github:timewave-computer/zero.nix"; | ||
}; | ||
|
||
outputs = { self, zero-nix }: { | ||
devShells.default = zero-nix.devShells.default.override { | ||
buildInputs = with zero-nix.legacyPackages.${system}; [ | ||
solana-tools | ||
# Add your existing tools here | ||
]; | ||
}; | ||
}; | ||
} | ||
``` | ||
|
||
## Documentation | ||
|
||
- [Anchor Book](https://book.anchor-lang.com/) | ||
- [Solana program development](https://docs.solana.com/developing/programming-model/overview) | ||
- [Solana CLI reference](https://docs.solana.com/cli) | ||
|
||
## Version Information | ||
|
||
- **Solana CLI**: v2.0.22 | ||
- **Anchor CLI**: v0.31.1 | ||
- **Platform Tools**: v1.48 | ||
- **Rust**: Compatible with Solana (via platform tools) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.