Skip to Content
Getting StartedBuild from Source

Building TOS Network from Source

This comprehensive guide covers building TOS Network software from source code. Building from source gives you access to the latest features, allows customization, and provides deeper understanding of the TOS Network architecture.

Why Build from Source?

Benefits

  • 🚀 Latest Features: Access cutting-edge developments before official releases
  • 🔧 Customization: Modify code for specific requirements
  • 🐛 Bug Fixes: Apply patches and fixes immediately
  • 📚 Learning: Understand TOS Network internals
  • Performance: Optimize builds for your specific hardware
  • 🔒 Security: Verify code integrity and build reproducibly

When to Build from Source

  • Development: Contributing to TOS Network or building applications
  • Research: Academic or commercial research projects
  • Custom Features: Need modifications not available in releases
  • Latest Updates: Want immediate access to new features
  • Security Auditing: Need to verify every line of code

Prerequisites

System Requirements

Minimum Requirements

  • CPU: 4 cores, 2.4GHz
  • RAM: 8GB (16GB recommended for parallel builds)
  • Storage: 20GB free space for build artifacts
  • Network: Stable internet connection for dependencies
  • CPU: 8+ cores, 3.0GHz+
  • RAM: 16GB+ for faster compilation
  • Storage: 50GB+ SSD for optimal build speed
  • Network: High-speed connection for large repositories

Development Tools

Linux (Ubuntu/Debian)

# Update system sudo apt update && sudo apt upgrade -y # Install build essentials sudo apt install -y \ build-essential \ git \ curl \ wget \ cmake \ pkg-config \ libssl-dev \ libclang-dev \ protobuf-compiler # Install Rust (latest stable) curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y source ~/.cargo/env # Install Node.js (for documentation tools) curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - sudo apt install -y nodejs # Verify installations rustc --version # Should show Rust 1.70+ cargo --version # Should show cargo 1.70+ node --version # Should show Node 20+ npm --version # Should show npm 10+

macOS

# Install Xcode command line tools xcode-select --install # Install Homebrew if not already installed /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # Install development tools brew install \ git \ cmake \ pkg-config \ openssl \ protobuf \ rust \ node # Verify installations rustc --version cargo --version node --version
# Enable WSL2 and install Ubuntu wsl --install -d Ubuntu-22.04 # Then follow Linux instructions inside WSL2 # Alternative: Native Windows build (advanced) # Install Visual Studio 2022 with C++ workload # Install Git for Windows # Install Rust from https://rustup.rs/ # Install Node.js from https://nodejs.org/

Repository Structure

TOS Network Structure

# TOS Network repository structure tos/ ├── daemon/ # Blockchain node daemon ├── wallet/ # Wallet implementation ├── miner/ # Mining software ├── ai_miner/ # AI mining implementation ├── common/ # Shared library code ├── docs/ # Technical documentation └── target/ # Build artifacts (generated)

Clone Repository

# Clone the main TOS repository git clone https://github.com/tos-network/tos.git cd tos # Check repository status git status git log --oneline -5

Building TOS Network

# Local build script (builds for current platform) ./build_local.sh # Check build artifacts ls -la build/local/ # Should show: tos_daemon, tos_miner, tos_wallet, tos_genesis, tos_ai_miner

Manual Build

# Development build cargo build # Release build (optimized) cargo build --release # Build specific components cargo build --release --bin tos_daemon cargo build --release --bin tos_miner cargo build --release --bin tos_wallet cargo build --release --bin tos_ai_miner cargo build --release --bin tos_genesis

Cross-Platform Build

# Install cross-compilation tool cargo install cross # Cross-compile for multiple platforms ./build_all.sh # Check cross-platform artifacts ls -la build/ # Should show platform-specific directories and archives

Advanced Build Options

# Development build with debug symbols cargo build --profile dev # Optimized release build cargo build --release # Build with specific features cargo build --release --features "gpu-mining,ai-processing,experimental" # Build for specific target cargo build --target x86_64-unknown-linux-gnu --release cargo build --target aarch64-apple-darwin --release cargo build --target x86_64-pc-windows-gnu --release

Building Individual Components

TOS Daemon

# Build daemon cargo build --release --bin tos_daemon # Verify build ./target/release/tos_daemon --version ./target/release/tos_daemon --help

TOS Wallet

# Build wallet cargo build --release --bin tos_wallet # Verify build ./target/release/tos_wallet --version ./target/release/tos_wallet --help

TOS Miner

# Build miner cargo build --release --bin tos_miner # Verify build ./target/release/tos_miner --version ./target/release/tos_miner --help

AI Miner

# Build AI miner cargo build --release --bin tos_ai_miner # Verify build ./target/release/tos_ai_miner --version ./target/release/tos_ai_miner --help

Build Optimization

Performance Tuning

# Set environment variables for faster builds export CARGO_BUILD_JOBS=8 export CARGO_TARGET_DIR=/tmp/cargo-target # Use local cache export CARGO_HOME=~/.cargo # Parallel compilation export RUSTFLAGS="-C target-cpu=native"

Build Configuration

Create .cargo/config.toml:

[build] jobs = 8 rustflags = ["-C", "target-cpu=native"] [target.x86_64-unknown-linux-gnu] linker = "clang" rustflags = ["-C", "link-arg=-fuse-ld=lld"] [profile.release] lto = true codegen-units = 1 panic = "abort"

Testing

Run Tests

# Run all tests cargo test # Run tests with verbose output cargo test --verbose # Run specific test suite cargo test --bin tos_daemon cargo test --bin tos_wallet # Run integration tests cargo test --test '*'

Benchmarks

# Run performance benchmarks cargo bench # Run specific benchmarks cargo bench --bench mining cargo bench --bench consensus

Troubleshooting

Common Issues

  1. Rust Version Compatibility

    Error: requires rustc 1.70+

    Solution: Update Rust toolchain

    rustup update stable
  2. Missing Dependencies

    Error: could not find system library 'openssl'

    Solution: Install system dependencies

    sudo apt install libssl-dev pkg-config
  3. Build Cache Issues

    Error: incremental compilation cache

    Solution: Clean and rebuild

    cargo clean cargo build --release

Build Performance Issues

# Clean build cache cargo clean # Check dependencies cargo check # Force rebuild cargo build --release --force-rebuild

Debugging Build Issues

# Verbose build output cargo build --verbose # Check specific warnings cargo clippy --all-targets --all-features

Development Environment

VS Code Setup

Install recommended extensions:

  • rust-analyzer: Rust language support
  • CodeLLDB: Debugging support
  • Better TOML: TOML file support
  • GitLens: Git integration

Development Tools

# Install useful tools cargo install rustfmt # Code formatting cargo install clippy # Linting cargo install cargo-watch # Auto rebuild cargo install cargo-tarpaulin # Coverage cargo install mdbook # Documentation # Format code cargo fmt # Run linter cargo clippy # Auto-rebuild on changes cargo watch -x build

IDE Configuration

VS Code Settings

{ "rust-analyzer.cargo.buildScripts.enable": true, "rust-analyzer.procMacro.enable": true, "rust-analyzer.cargo.features": "all" }

Next Steps

For Developers

  1. Set up IDE: Configure your development environment
  2. Read Documentation: Explore Developer API guides
  3. Run Tests: Ensure everything works correctly
  4. Start Contributing: Check our Contributing Guide

For Miners

  1. Build Miner: Use cargo build --release --bin tos_miner
  2. Configure Mining: Set up your mining configuration
  3. Join Network: Connect to TOS testnet or mainnet
  4. Monitor Performance: Track your mining statistics

For Researchers

  1. Build All Components: Use ./build_all.sh for complete build
  2. Explore AI Mining: Build and test AI mining functionality
  3. Analyze Code: Use built-in profiling and debugging tools
  4. Contribute Research: Share findings with the community

License

TOS Network is licensed under the BSD 3-Clause License. See the LICENSE  file for details.


TOS Network - Next Generation Blockchain Network 🚀

Last updated on