From 99a7cbd0330ac1be7be18f6caaf1d94c89fdc721 Mon Sep 17 00:00:00 2001 From: Marco Cadetg Date: Sat, 22 Nov 2025 17:58:36 +0100 Subject: [PATCH] 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 --- .github/workflows/test-freebsd.yml | 60 ++++++++++++++++++++++++++++++ Cargo.toml | 4 +- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test-freebsd.yml diff --git a/.github/workflows/test-freebsd.yml b/.github/workflows/test-freebsd.yml new file mode 100644 index 0000000..22b656f --- /dev/null +++ b/.github/workflows/test-freebsd.yml @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 95bc512..b5ad7b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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]