Skip to main content

Build System Architecture

ML Defender uses a hierarchical build system with a single source of truth for compiler flags and build profiles.

Design Principles

  1. Single Source of Truth: All compiler flags in root Makefile (lines 50-98)
  2. Profile-Aware Builds: Separate build directories per profile
  3. No Flag Hardcoding: CMakeLists.txt files receive flags from Makefile
  4. Reproducible Builds: Same profile = same binary

Build Profiles

Profile Definitions

From source/Makefile:50-98:

Build Directory Structure


CMake Configuration

Correct Flag Handling

❌ WRONG - Do not hardcode flags:
✅ CORRECT - Receive flags from Makefile:
From source/sniffer/CMakeLists.txt:12-28:

Component CMake Flow

From source/Makefile:277-290:

Makefile Targets Reference

Core Build Targets

Library Targets

Note: Libraries are always built in Release mode (no sanitizers) to avoid linking issues.

Clean Targets


Debian Packaging

Package Build

From source/debian/control:

Package Structure

Debian Control File

From source/debian/control:

Installation


Docker Builds

Multi-Service Architecture

From source/ directory:

Docker Compose

docker-compose.yaml

Running


Build Dependencies

Dependency Graph

Build Order

Critical: Dependencies must be built in this order:
  1. Protobuf: make proto
  2. crypto-transport: make crypto-transport-build
  3. etcd-client: make etcd-client-build
  4. Components: make sniffer ml-detector firewall
Automated:

Verifying Dependencies


Cross-Compilation

ARM64 Build (for Raspberry Pi)

Toolchain file (cmake/aarch64-toolchain.cmake):

Optimization Flags

Production Build Flags

From source/Makefile:60-61:

Performance Impact


TSAN/ASAN Builds

ThreadSanitizer

From source/Makefile:465-529:
TSAN flags (source/Makefile:66-68):
Environment:

AddressSanitizer


Troubleshooting

Build Fails with Undefined References

Symptom: undefined reference to 'bpf_ringbuf_reserve' Solution:

Protobuf Mismatch

Symptom: protobuf version mismatch Solution:

Stale Build Cache


Next Steps

Testing

Run tests and validate builds

eBPF/XDP

Understand eBPF program compilation

Deployment

Deploy production builds

Performance

Optimize and benchmark