Fix FreeBSD build by making libbpf-cargo optional

- Make libbpf-cargo an optional build dependency
- Include it in ebpf feature to only build when needed
- Add test workflow for FreeBSD builds that can be manually triggered
- This prevents libbpf-sys from being built when cross-compiling to FreeBSD
This commit is contained in:
Marco Cadetg
2025-11-22 17:58:36 +01:00
parent 68ab2a1b57
commit 99a7cbd033
2 changed files with 62 additions and 2 deletions

60
.github/workflows/test-freebsd.yml vendored Normal file
View File

@@ -0,0 +1,60 @@
name: Test FreeBSD Build
on:
workflow_dispatch:
pull_request:
paths:
- 'Cargo.toml'
- 'build.rs'
- 'src/**'
- '.github/workflows/test-freebsd.yml'
env:
RUST_BACKTRACE: 1
jobs:
test-freebsd-build:
name: Test FreeBSD x64 Build
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Linux dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y libpcap-dev pkg-config
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: x86_64-unknown-freebsd
- name: Install cross
run: cargo install cross@0.2.5
- name: Build for FreeBSD (without eBPF)
env:
RUSTFLAGS: "-C strip=symbols"
run: |
echo "Building for FreeBSD target without default features (no eBPF)"
cross build --verbose --release --target x86_64-unknown-freebsd --no-default-features
- name: Verify binary was created
run: |
if [ -f "target/x86_64-unknown-freebsd/release/rustnet" ]; then
echo "✅ FreeBSD binary successfully built"
ls -lh target/x86_64-unknown-freebsd/release/rustnet
else
echo "❌ FreeBSD binary not found"
exit 1
fi
- name: Upload binary as artifact
uses: actions/upload-artifact@v5
with:
name: rustnet-freebsd-x64
path: target/x86_64-unknown-freebsd/release/rustnet
if-no-files-found: error

View File

@@ -85,7 +85,7 @@ windows = { version = "0.62", features = [
] }
[target.'cfg(target_os = "linux")'.build-dependencies]
libbpf-cargo = "0.25"
libbpf-cargo = { version = "0.25", optional = true }
[features]
# eBPF is enabled by default for enhanced performance on Linux.
@@ -93,7 +93,7 @@ libbpf-cargo = "0.25"
# and dependencies are Linux-specific (guarded by target_os checks).
default = ["ebpf"]
linux-default = ["ebpf"] # Deprecated: kept for backwards compatibility
ebpf = ["libbpf-rs", "bytes", "libc"]
ebpf = ["libbpf-rs", "bytes", "libc", "dep:libbpf-cargo"]
# Minimal cross configuration to override dependency conflicts
[workspace.metadata.cross.build.env]