Skip to main content

Prerequisites

ML Defender requires a Linux environment with modern tooling. Development is optimized for Vagrant/VirtualBox workflow but can run on bare metal.

Required Tools

  • Operating System: Debian 12 (Bookworm) or Ubuntu 22.04+
  • Kernel: Linux 6.1+ (for eBPF CO-RE support)
  • Compiler: Clang 14+ and GCC 11+
  • Build System: CMake 3.20+, Make 4.3+
  • Version Control: Git 2.30+

System Dependencies

Hardware Recommendations

  • CPU: 4+ cores (6 recommended for parallel builds)
  • RAM: 8 GB minimum (16 GB recommended)
  • Storage: 50 GB SSD
  • Network: Gigabit Ethernet for packet capture testing

Building from Source

ML Defender uses a unified build system controlled by a single Makefile at the project root.
1

Clone Repository

2

Build All Components

The root Makefile provides profile-aware builds:
Build profiles are defined in Makefile (lines 50-98):
  • production: -O3 -march=native -DNDEBUG -flto
  • debug: -g -O0 -fno-omit-frame-pointer
  • tsan: -fsanitize=thread -g -O1
  • asan: -fsanitize=address -fsanitize=undefined -g -O1
3

Verify Build

Expected output:
4

Install (Optional)

For Debian package installation:

Build System Architecture

Component Structure

Each component builds to profile-specific directories:

CMake Configuration

All compiler flags are controlled by the root Makefile (source/Makefile:75-93). Individual CMakeLists.txt files MUST NOT hardcode optimization flags.
Example: sniffer/CMakeLists.txt
See source/sniffer/CMakeLists.txt:12-23 for the correct approach.

Makefile Targets


IDE Setup

Visual Studio Code

Recommended extensions:
  • C/C++ (ms-vscode.cpptools)
  • CMake Tools (ms-vscode.cmake-tools)
  • clangd (llvm-vs-code-extensions.vscode-clangd)
Workspace settings (.vscode/settings.json):

CLion

  1. Open project root
  2. Settings → Build → CMake:
    • Build type: Debug
    • CMake options: -DCMAKE_BUILD_TYPE=Debug
  3. Settings → Tools → External Tools → Add Makefile targets

Vim/Neovim

Use compile_commands.json for LSP:

Git Workflow

Branching Strategy

  • main: Production-ready code
  • develop: Integration branch
  • feature/: New features (feature/day52-config-driven)
  • fix/: Bug fixes (fix/crypto-pipeline-leak)
  • test/: Experimental tests

Commit Message Format

Follow the project’s style (see source/README.md:373-397):
Types: feat, fix, refactor, test, docs, perf

Example Workflow


AI Collaboration Guidelines

ML Defender practices transparent AI collaboration (source/README.md:245-262).

Principles

  1. Credit all AI assistants used in development
  2. Document AI contributions in commit messages
  3. Validate AI-generated code with tests
  4. Report actual results, not inflated claims

Commit Message Disclosure

AI Tools Used in This Project

  • Claude (Anthropic): Architecture design, code review
  • DeepSeek: Algorithm optimization, debugging
  • Grok: Performance analysis
  • ChatGPT: Research and documentation
  • Qwen: Code review and testing
See source/README.md:412-420 for full acknowledgments.

Development Scripts

Useful scripts in scripts/:

Troubleshooting

Build Fails with “libbpf not found"

"BPF map bug” Error

This is fixed in libbpf 1.2.0+ (see Makefile:645-665 for diagnostics).

Protobuf Version Mismatch

CMake Cache Issues


Next Steps

Testing Guide

Learn how to run tests and validate changes

Build System

Deep dive into CMake and Makefile configuration

Architecture

Understand the system design

Contributing

Submit your first contribution