Cross-compiling aya-based programs
The instructions below show how to cross compile aya eBPF programs on Macs. Cross compiling on other systems is possible too and we're going to add instructions to do that soon (PRs welcome!).
Cross-compiling aya-based programs on Mac
Cross compilation should work on both Intel and Apple Silicon Macs.
- Install
rustup
following the instructions on https://rustup.rs/ - Install the stable and nightly rust toolchains:
- Install the rustup target for your Linux target platform:
-
Install LLVM with brew:
-
Install the musl cross compiler:
to cross-compile for only
to cross-compile for onlyx86_64
targets (the default in musl-cross):aarch64
targets: to cross-compile for bothx86_64
andaarch64
targets: See homebrew-musl-cross for additional platform-specific options. -
Install bpf-linker:
- Build BPF object files:
- Build the userspace code:
The cross-compiled program
RUSTFLAGS="-Clinker=${ARCH}-linux-musl-ld" cargo build --release --target=${ARCH}-unknown-linux-musl
target/${ARCH}-unknown-linux-musl/release/<program_name>
can be copied to a Linux server or VM and run there.