↗ Building Linux eBPF/XDP Applications on macOS with Colima, Docker, Clang, and Go

eBPF and XDP are increasingly used for network traffic filtering, observability, abuse protection, and performing extremely cheap packet inspections before traffic reaches the regular Linux networking stack.
There is one practical problem, though: if your primary workstation is a Mac — especially an Apple Silicon Mac — you cannot build and test Linux eBPF programs exactly the same way you build a normal Go application.
For a reproducible build environment, we need:
- Go
- Clang and LLVM
- Linux headers
- libbpf headers
bpf2go- Docker
- a Linux runtime provided by Colima
In this guide, we will build a minimal XDP application using the following pipeline:
macOS
↓
Colima
↓
Docker Linux/arm64
↓
clang -target bpf
↓
eBPF bytecode
↓
bpf2go
↓
Go application
↓
Linux/amd64 binary
↓
Linux kernel
↓
XDP
The XDP program itself will intentionally do nothing dangerous:
return XDP_PASS;
It will see incoming packets and immediately allow them to continue through the normal Linux networking stack.
That makes it a good first test of the complete eBPF/XDP development lifecycle without introducing packet filtering into the experiment.
How XDP Fits into the Linux Networking Path
XDP stands for eXpress Data Path.
It allows eBPF programs to execute very early in the packet receive path.
A simplified packet flow looks like this:
NIC
↓
XDP / eBPF
↓
Linux networking stack
↓
nftables / routing
↓
socket
↓
application
An XDP program can return several actions, including:
XDP_PASSXDP_DROPXDP_TXXDP_REDIRECT
For this guide, we will use only:
XDP_PASS
So our program will not alter the machine's network behavior.
Preparing macOS for Linux eBPF Builds
Install Homebrew
If Homebrew is already installed, skip this section.
Install it using:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
On Apple Silicon systems, Homebrew normally installs under:
/opt/homebrew
Verify the installation:
brew --version
If macOS requires the Xcode Command Line Tools, install them with:
xcode-select --install
