Loki-RS Build Guide

March 11, 2026 · View on GitHub

This guide provides step-by-step instructions for building Loki-RS on different platforms.

Table of Contents


Linux Build

Prerequisites

Required Tools

  1. Rust Toolchain

    # Install Rust using rustup (recommended)
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    source $HOME/.cargo/env
    
    # Verify installation
    rustc --version
    cargo --version
    
  2. System Dependencies

    # Debian/Ubuntu
    sudo apt-get update
    sudo apt-get install -y build-essential pkg-config libssl-dev
    
    # Fedora/RHEL/CentOS
    sudo dnf install -y gcc openssl-devel
    
    # Arch Linux
    sudo pacman -S base-devel openssl
    

Optional: Development Tools

# Install clippy (linter) and rustfmt (formatter)
rustup component add clippy rustfmt

# Install cargo-audit (security audit)
cargo install cargo-audit

Build Steps

  1. Clone the Repository

    git clone https://github.com/Neo23x0/Loki-RS.git
    cd Loki-RS
    
  2. Build Release Version

    cargo build --release
    

    Main binary: target/release/loki Utility binary: target/release/loki-util

  3. Fetch Signatures

    ./target/release/loki-util update
    

    This downloads the latest signatures to ./signatures.

  4. Build Debug Version (Optional)

    cargo build
    

    Binary will be at: target/debug/loki

  5. Run Tests

    cargo test
    
  6. Code Quality Checks

    # Format code
    cargo fmt
    
    # Lint code
    cargo clippy
    
    # Security audit
    cargo audit
    

Build Output

  • Debug build: target/debug/loki (~10-20 MB, unoptimized, with debug symbols)
  • Release build: target/release/loki (~5-10 MB, optimized, stripped)

Cross-Platform Build

Prerequisites

  1. Install Rust Cross-Compilation Targets

    # Add target for Windows (x86_64)
    rustup target add x86_64-pc-windows-gnu
    
    # Add target for Windows (ARM64)
    rustup target add aarch64-pc-windows-msvc
    
    # Add target for macOS (x86_64)
    rustup target add x86_64-apple-darwin
    
    # Add target for macOS (ARM64/Apple Silicon)
    rustup target add aarch64-apple-darwin
    
    # Add target for Linux (ARM64)
    rustup target add aarch64-unknown-linux-gnu
    
  2. Install Cross-Compilation Tools

    For Windows builds:

    # Debian/Ubuntu
    sudo apt-get install -y mingw-w64
    
    # Fedora
    sudo dnf install -y mingw64-gcc
    
    # Arch Linux
    sudo pacman -S mingw-w64-gcc
    

    For macOS builds:

    • Requires macOS SDK (only available on macOS)
    • Or use osxcross (complex setup)

    For Linux ARM builds:

    # Debian/Ubuntu
    sudo apt-get install -y gcc-aarch64-linux-gnu
    
    # Fedora
    sudo dnf install -y gcc-aarch64-linux-gnu
    

Build Commands

# Build for Windows (from Linux)
cargo build --release --target x86_64-pc-windows-gnu

# Build for Windows ARM64 (from Windows)
cargo build --release --target aarch64-pc-windows-msvc

# Build for macOS x86_64 (from macOS)
cargo build --release --target x86_64-apple-darwin

# Build for macOS ARM64 (from macOS)
cargo build --release --target aarch64-apple-darwin

# Build for Linux ARM64
cargo build --release --target aarch64-unknown-linux-gnu

Cross-Compilation Notes

  • Windows x86_64 (x86_64-pc-windows-gnu): Requires mingw-w64 toolchain.
  • Windows ARM64 (aarch64-pc-windows-msvc): Build on Windows with Visual Studio C++ build tools (MSVC/ARM64 libraries).
  • macOS: Cross-compilation from Linux is complex. Best done on macOS itself or using CI/CD.
  • ARM: Requires appropriate cross-compiler toolchain.

Windows Build

Prerequisites

  1. Install Rust

  2. Install Visual Studio Build Tools

  3. Install Git

Build Steps

  1. Open Developer Command Prompt

    • Start Menu → Visual Studio → Developer Command Prompt
    • Or use PowerShell/CMD with Visual Studio environment
  2. Clone and Build

    git clone https://github.com/Neo23x0/Loki-RS.git
    cd Loki-RS
    cargo build --release
    
  3. Binary Location

    target\release\loki.exe
    

Alternative: Using WSL

If you have Windows Subsystem for Linux (WSL):

# In WSL
sudo apt-get update
sudo apt-get install -y build-essential
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
cd /mnt/c/path/to/Loki-RS
cargo build --release

macOS Build

Prerequisites

  1. Install Xcode Command Line Tools

    xcode-select --install
    
  2. Install Rust

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    source $HOME/.cargo/env
    
  3. Install Homebrew (optional, for additional tools)

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    

Build Steps

# Clone repository
git clone https://github.com/Neo23x0/Loki-RS.git
cd Loki-RS

# Build release
cargo build --release

# Binary location
./target/release/loki

Apple Silicon (M1/M2/M3) Notes

  • Rust automatically detects ARM64 architecture
  • No special configuration needed
  • Use aarch64-apple-darwin target if explicitly needed:
    cargo build --release --target aarch64-apple-darwin
    

Release Builds

Creating Release Binaries

  1. Clean Build

    cargo clean
    cargo build --release
    
  2. Strip Binary (reduce size)

    # Linux
    strip target/release/loki
    
    # macOS
    strip target/release/loki
    
    # Windows (using strip from MinGW or Visual Studio)
    strip target/release/loki.exe
    
  3. Verify Binary

    # Check binary info
    file target/release/loki
    
    # Test run
    ./target/release/loki --version
    

Release Package Structure

For distribution, create a package with:

loki-release-v2.0.0/
├── loki (or loki.exe)
├── README.md
├── LICENSE
└── signatures/
    ├── yara/     (YARA rules from YARA Forge)
    └── iocs/     (optional custom IOC files)

Automated Release Builds

See .github/workflows/release.yml for automated release builds on Git tags.


Troubleshooting

Common Issues

1. "linker cc not found"

Solution:

# Debian/Ubuntu
sudo apt-get install build-essential

# Fedora
sudo dnf install gcc

# macOS
xcode-select --install

2. "OpenSSL not found"

Solution:

# Debian/Ubuntu
sudo apt-get install libssl-dev pkg-config

# Fedora
sudo dnf install openssl-devel

# macOS (with Homebrew)
brew install openssl
export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"

3. "Permission denied" when running binary

Solution:

chmod +x target/release/loki

4. "Signatures not found"

Solution:

# Use loki-util to download signatures
./loki-util update

# Or manually create structure and download
mkdir -p ./signatures/yara ./signatures/iocs
# Download YARA rules from YARA Forge and optionally add custom IOC files

5. Build fails with "out of memory"

Solution:

  • Use cargo build --release (release builds use less memory)
  • Increase swap space
  • Build on a machine with more RAM

6. Cross-compilation fails

Solution:

  • Ensure all cross-compilation toolchains are installed
  • Check .cargo/config.toml for target-specific settings
  • Some crates may not support all targets

Getting Help

  • Check Rust Installation Guide
  • Review Cargo Book
  • Check crate-specific documentation for dependencies
  • Open an issue on GitHub with:
    • OS and version
    • Rust version (rustc --version)
    • Full error message
    • Build command used

Build Configuration

Environment Variables

  • RUSTFLAGS: Additional flags for rustc

    export RUSTFLAGS="-C target-cpu=native"  # Optimize for current CPU
    
  • CARGO_TARGET_DIR: Custom target directory

    export CARGO_TARGET_DIR=/custom/path
    

Cargo Configuration

Create .cargo/config.toml for project-specific settings:

[build]
# Use specific linker
target = "x86_64-unknown-linux-gnu"
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"

Performance Tips

  1. Use Release Builds: Always use --release for production
  2. Enable LTO: Add to Cargo.toml:
    [profile.release]
    lto = true
    
  3. Optimize for Size: Add to Cargo.toml:
    [profile.release]
    opt-level = "z"  # Optimize for size
    
  4. Parallel Compilation: Cargo uses all CPU cores by default

Next Steps

After building:

  1. Run tests: cargo test
  2. Check code quality: cargo clippy
  3. Format code: cargo fmt
  4. Review README.md for usage instructions