Skip to content

Make novendor feature the default #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- rust-target: x86_64-unknown-linux-gnu
os-target: x86_64-linux-gnu
os-arch: amd64
features: novendor
features: static

- rust-target: aarch64-unknown-linux-gnu
os-target: aarch64-linux-gnu
Expand Down Expand Up @@ -59,9 +59,17 @@ jobs:
zlib1g-dev:${{ matrix.os-arch }}

- name: Install libbpf-dev
if: matrix.features == 'novendor'
run: sudo apt-get install libbpf-dev:${{ matrix.os-arch }}

- name: Install Static Compilation dependencies
run: |
sudo apt-get install \
autopoint:${{ matrix.os-arch }} \
autoconf:${{ matrix.os-arch }} \
flex:${{ matrix.os-arch }} \
bison:${{ matrix.os-arch }} \
gawk:${{ matrix.os-arch }}

- name: Install linker for ${{ matrix.os-target }}
if: matrix.os-arch != 'amd64'
run: sudo apt-get install gcc-${{ matrix.os-target }}
Expand All @@ -84,7 +92,6 @@ jobs:
matrix:
features:
- ''
- novendor
env:
CARGO_TERM_VERBOSE: 'true'
steps:
Expand All @@ -105,7 +112,6 @@ jobs:
zlib-dev

- name: Install libbpf-dev
if: matrix.features == 'novendor'
run: apk add libbpf-dev
shell: alpine.sh --root {0}

Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ num_cpus = "^1.16.0"
crate-type = ["lib", "staticlib"]

[features]
novendor = []
static = []
vendored = ["static"]
novendor = [] # depricated, novendor is the default
18 changes: 6 additions & 12 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn main() {

generate_bindings(src_dir.clone());

if cfg!(feature = "novendor") {
if cfg!(not(feature = "static")) {
println!("cargo:rustc-link-lib={}bpf\n", library_prefix());
return;
}
Expand All @@ -107,13 +107,11 @@ fn main() {
// check for all necessary compilation tools
pkg_check("make");
pkg_check("pkg-config");
if cfg!(feature = "vendored") {
pkg_check("autoreconf");
pkg_check("autopoint");
pkg_check("flex");
pkg_check("bison");
pkg_check("gawk");
}
pkg_check("autoreconf");
pkg_check("autopoint");
pkg_check("flex");
pkg_check("bison");
pkg_check("gawk");

let compiler = match cc::Build::new().try_get_compiler() {
Ok(compiler) => compiler,
Expand All @@ -127,9 +125,7 @@ fn main() {
let _ = fs::create_dir(&obj_dir);

// compile static zlib and static libelf
#[cfg(feature = "vendored")]
make_zlib(&compiler, &src_dir, &out_dir);
#[cfg(feature = "vendored")]
make_elfutils(&compiler, &src_dir, &out_dir);

let cflags = if cfg!(feature = "vendored") {
Expand Down Expand Up @@ -187,7 +183,6 @@ fn main() {
}
}

#[cfg(feature = "vendored")]
fn make_zlib(compiler: &cc::Tool, src_dir: &path::PathBuf, out_dir: &path::PathBuf) {
use nix::fcntl;
use std::os::fd::AsRawFd;
Expand Down Expand Up @@ -232,7 +227,6 @@ fn make_zlib(compiler: &cc::Tool, src_dir: &path::PathBuf, out_dir: &path::PathB
assert!(status.success(), "make failed");
}

#[cfg(feature = "vendored")]
fn make_elfutils(compiler: &cc::Tool, src_dir: &path::PathBuf, out_dir: &path::PathBuf) {
use nix::fcntl;
use std::os::fd::AsRawFd;
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

include!("bindings.rs");

#[cfg(feature = "static")]
macro_rules! header {
($file:literal) => {
($file, include_str!(concat!("../libbpf/src/", $file)))
Expand All @@ -15,7 +16,7 @@ macro_rules! header {
/// Vendored libbpf headers
///
/// Tuple format is: (header filename, header contents)
#[cfg(not(feature = "novendor"))]
#[cfg(feature = "static")]
pub const API_HEADERS: [(&'static str, &'static str); 10] = [
header!("bpf.h"),
header!("libbpf.h"),
Expand Down