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.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
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
Makefile Targets
| Target | Description |
|---|---|
make all | Build all components (current profile) |
make proto | Regenerate Protobuf definitions |
make sniffer | Build eBPF sniffer |
make ml-detector | Build ML detector |
make firewall | Build firewall agent |
make etcd-server | Build etcd server |
make tools | Build testing tools |
make clean | Clean current profile |
make clean-all | Clean ALL profiles |
make rebuild | Clean + build |
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)
.vscode/settings.json):
CLion
- Open project root
- Settings → Build → CMake:
- Build type:
Debug - CMake options:
-DCMAKE_BUILD_TYPE=Debug
- Build type:
- Settings → Tools → External Tools → Add Makefile targets
Vim/Neovim
Usecompile_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):feat, fix, refactor, test, docs, perf
Example Workflow
AI Collaboration Guidelines
ML Defender practices transparent AI collaboration (source/README.md:245-262).Principles
- Credit all AI assistants used in development
- Document AI contributions in commit messages
- Validate AI-generated code with tests
- 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
Development Scripts
Useful scripts inscripts/:
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