Skip to content

Compiling Guide

TehPig edited this page Jun 7, 2026 · 1 revision

Compiling Guide

This guide covers setting up the development environment, the project's codebase architecture, and common development workflows for T_Music_Bot RPC (Rust).


πŸ› οΈ Environment Setup

1. Prerequisites

To compile and run this project, you need the Rust toolchain and build dependencies:

  • rustup: Download and run the installer from rustup.rs.
  • Windows Only: Visual Studio Build Tools with C++ compiler packages.
  • macOS Only: Xcode Command Line Tools installed via xcode-select --install.
  • Linux Only: Development headers for ALSA and GTK (e.g. libasound2-dev libgtk-3-dev libappindicator3-dev).

2. Initial Setup

Clone the repository and compile the dependencies:

cargo build

πŸ—οΈ Codebase Architecture

The project consists of a native Rust backend that hosts an Axum web server and drives the Discord RPC client + CPAL-based audio capture loop.

πŸ“‚ Directory Layout

  • src/: Rust backend implementation.
    • main.rs: Entry point. Initializes state, tray icon, and runtime loops.
    • models.rs: Serialization structures and default configuration schemas.
    • config.rs: Helper utilities for reading/writing configuration files.
    • server/: Axum web server configuration and request handlers.
      • mod.rs: Axum router setup and static asset loader.
      • handlers.rs: Endpoints for settings update, client discovery, and audio device listing.
      • templates.rs: Dynamic canvas rendering and overlay HTML generators.
    • rpc/: Discord Rich Presence connection and status synchronization.
    • visualizer/: Real-time CPAL audio loopback capture thread and FFT (Fast Fourier Transform) math engine.
    • ui/: Embedded Web UI layouts and static styling/scripts.
  • ui/: Root UI source templates (development duplicates/references).
  • docs/: Feature tours, setup guides, and benchmarks.

πŸ”„ UI Development Workflow

Static File Embedding

For maximum performance and self-containment, the HTML/CSS/JS frontend files are compiled directly into the final executable using Rust's include_str! and include_bytes! macros.

  • Changing files under src/ui/ requires recompiling the Rust binary.

To test changes to UI templates or scripts:

  1. Edit the source files (e.g., gui.html or gui.css).
  2. Recompile and run:
    cargo run
  3. Refresh your web browser.

πŸ§‘β€πŸ’» Verification & Build Checks

Before making a contribution, verify that everything compiles correctly.

Check Syntax & Borrow Checker

cargo check

Apply Code Formatting

cargo fmt --all

Run Linter

cargo clippy --all-targets --all-features

Create Release Binary

To compile the highly optimized standalone executable:

cargo build --release

The compiled output is located at: target/release/t-music-bot-rpc.exe (on Windows).