Building from Source
Complete instructions for building Two-Face on all supported platforms.
Prerequisites
Rust Toolchain
Install Rust via rustup:
# Install rustup (Linux/macOS)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Or on Windows, download from https://rustup.rs/
Verify installation:
rustc --version # Should be 1.70+
cargo --version
Platform-Specific Dependencies
Windows
Option 1: Visual Studio Build Tools
- Install Visual Studio Build Tools
- Select “Desktop development with C++”
Option 2: vcpkg for OpenSSL
# Clone vcpkg
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.bat
# Install OpenSSL
./vcpkg install openssl:x64-windows
# Set environment variable
set VCPKG_ROOT=C:\path\to\vcpkg
macOS
# Install Xcode Command Line Tools
xcode-select --install
# Install OpenSSL via Homebrew
brew install openssl
# Set OpenSSL path (add to ~/.zshrc or ~/.bashrc)
export OPENSSL_DIR=$(brew --prefix openssl)
Linux (Debian/Ubuntu)
sudo apt update
sudo apt install build-essential pkg-config libssl-dev
Linux (Fedora/RHEL)
sudo dnf install gcc openssl-devel pkg-config
Linux (Arch)
sudo pacman -S base-devel openssl pkg-config
Basic Build
Clone Repository
git clone https://github.com/your-repo/two-face.git
cd two-face
Debug Build
For development with debug symbols:
cargo build
Binary location: target/debug/two-face
Release Build
For optimized production build:
cargo build --release
Binary location: target/release/two-face
Run Directly
Without building separately:
# Debug mode
cargo run -- --help
# Release mode
cargo run --release -- --host 127.0.0.1 --port 8000
Build Profiles
Debug Profile (default)
# Cargo.toml [profile.dev]
opt-level = 0
debug = true
Fast compilation, slow execution, large binary.
Release Profile
# Cargo.toml [profile.release]
opt-level = 3
lto = true
codegen-units = 1
Slow compilation, fast execution, small binary.
Custom Profile
Create a custom profile in Cargo.toml:
[profile.release-with-debug]
inherits = "release"
debug = true
Build with: cargo build --profile release-with-debug
Feature Flags
Two-Face may have optional features:
# Build with specific features
cargo build --features "feature1,feature2"
# Build with all features
cargo build --all-features
# Build without default features
cargo build --no-default-features
Check Cargo.toml for available features.
Cross-Compilation
Setup
Install cross-compilation targets:
# List available targets
rustup target list
# Add a target
rustup target add x86_64-unknown-linux-gnu
rustup target add x86_64-pc-windows-gnu
rustup target add aarch64-apple-darwin
Build for Target
cargo build --release --target x86_64-unknown-linux-gnu
Using cross
For easier cross-compilation with Docker:
# Install cross
cargo install cross
# Build for Linux from any platform
cross build --release --target x86_64-unknown-linux-gnu
Build Optimization
Link-Time Optimization (LTO)
Already enabled in release profile:
[profile.release]
lto = true
Strip Symbols
Reduce binary size:
# After building
strip target/release/two-face
Or configure in Cargo.toml:
[profile.release]
strip = true
Size Optimization
For minimal binary size:
[profile.release]
opt-level = "z" # Optimize for size
lto = true
strip = true
panic = "abort"
codegen-units = 1
Dependency Management
Update Dependencies
# Check for outdated dependencies
cargo outdated
# Update all dependencies
cargo update
# Update specific dependency
cargo update -p package_name
Audit Dependencies
# Install cargo-audit
cargo install cargo-audit
# Check for security vulnerabilities
cargo audit
Build Troubleshooting
OpenSSL Not Found
Error: Could not find directory of OpenSSL installation
Windows Solution:
# Set vcpkg root
set VCPKG_ROOT=C:\path\to\vcpkg
# Or set OpenSSL dir directly
set OPENSSL_DIR=C:\path\to\openssl
macOS Solution:
export OPENSSL_DIR=$(brew --prefix openssl)
export OPENSSL_INCLUDE_DIR=$OPENSSL_DIR/include
export OPENSSL_LIB_DIR=$OPENSSL_DIR/lib
Linux Solution:
# Debian/Ubuntu
sudo apt install libssl-dev pkg-config
# Ensure pkg-config can find it
pkg-config --libs openssl
Linker Errors
Error: linking with cc failed
Solutions:
- Install build tools for your platform
- Check library paths are correct
- Ensure all dependencies are installed
Out of Memory
Error: out of memory during compilation
Solutions:
- Use fewer codegen units:
[profile.release] codegen-units = 1 - Reduce parallel jobs:
cargo build -j 2 - Close other applications
Slow Builds
Improve build times:
-
Use
sccache:cargo install sccache export RUSTC_WRAPPER=sccache -
Use
moldlinker (Linux):# Install mold sudo apt install mold # Configure in .cargo/config.toml [target.x86_64-unknown-linux-gnu] linker = "clang" rustflags = ["-C", "link-arg=-fuse-ld=mold"] -
Incremental compilation (default in debug)
CI/CD
GitHub Actions Example
name: Build
on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-action@stable
- name: Build
run: cargo build --release
- name: Test
run: cargo test
Verification
Run Tests
cargo test
Run Application
# Show help
./target/release/two-face --help
# Test connection
./target/release/two-face --host 127.0.0.1 --port 8000
Check Binary
# File type
file target/release/two-face
# Dependencies (Linux)
ldd target/release/two-face
# Size
ls -lh target/release/two-face
See Also
- Project Structure - Codebase overview
- Testing - Test patterns
- Contributing - Contribution guide