Skip to content

Commit

Permalink
Expose libbpf-sys' static feature
Browse files Browse the repository at this point in the history
To statically link elfutils and libz

Tested on [rbperf](https://github.com/javierhonduco/rbperf) compiled
with `RUSTFLAGS="-L /usr/lib -L /usr/lib64" cargo b`

**With the feature disabled (the default)**

```
[javierhonduco@fedora rbperf]$ ldd target/debug/rbperf
        linux-vdso.so.1 (0x00007fffa8de3000)
        libelf.so.1 => /lib/libelf.so.1 (0x00007ff9a5727000)
        libz.so.1 => /lib64/libz.so.1 (0x00007ff9a570d000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007ff9a56ed000)
        libm.so.6 => /lib64/libm.so.6 (0x00007ff9a560f000)
        libc.so.6 => /lib64/libc.so.6 (0x00007ff9a540e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff9a5fa2000)
```

**With the static feature**
```
[javierhonduco@fedora rbperf]$ ldd target/debug/rbperf
        linux-vdso.so.1 (0x00007ffc5ed6a000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007ff391800000)
        libm.so.6 => /lib64/libm.so.6 (0x00007ff391722000)
        libc.so.6 => /lib64/libc.so.6 (0x00007ff391521000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff392098000)
```
  • Loading branch information
javierhonduco authored and insearchoflosttime committed Jul 15, 2022
1 parent 64b17ca commit 5bed52a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ jobs:
components: rustfmt, clippy
override: true
- name: Install deps
run: sudo apt-get install -y clang-12 libelf-dev
run: sudo apt-get install -y clang-12 libelf-dev zlib1g-dev
- name: Symlink clang
run: sudo rm -f /bin/clang && sudo ln -s /usr/bin/clang-12 /bin/clang
- name: Build
run: cargo build --verbose --workspace --exclude runqslower
- name: Build capable example with static libelf and libz
run: RUSTFLAGS='-L /usr/lib/x86_64-linux-gnu' cargo b --package capable --features=static
- name: Run tests
# Skip BTF tests which require sudo
# Skip BTF dump float test for now, we can enable it when we have access to clang 13+
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/capable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ clap = { version = "3.1", default-features = false, features = ["std", "derive"]

[build-dependencies]
libbpf-cargo = { path = "../../libbpf-cargo" }

[features]
static = ["libbpf-rs/static"]
2 changes: 1 addition & 1 deletion libbpf-cargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ novendor = ["libbpf-sys/novendor"]
[dependencies]
anyhow = "1.0"
cargo_metadata = "0.14"
libbpf-sys = { version = "0.8.0" }
libbpf-sys = { version = "0.8.1" }
memmap2 = "0.5"
num_enum = "0.5"
regex = "1.5"
Expand Down
3 changes: 2 additions & 1 deletion libbpf-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ maintenance = { status = "actively-developed" }
# When turned on, link against system-installed libbpf instead of building
# and linking against vendored libbpf sources
novendor = ["libbpf-sys/novendor"]
static = ["libbpf-sys/static"]

[dependencies]
bitflags = "1.3"
lazy_static = "1.4"
libbpf-sys = { version = "0.8.0" }
libbpf-sys = { version = "0.8.1" }
nix = { version = "0.24", default-features = false, features = ["net", "user"] }
num_enum = "0.5"
strum_macros = "0.23"
Expand Down

0 comments on commit 5bed52a

Please sign in to comment.