Skip to content

Commit

Permalink
edriver-rust: easy build
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskaliX committed Aug 11, 2024
1 parent bdfd441 commit a5f18ec
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 20 deletions.
7 changes: 7 additions & 0 deletions plugins/edriver-rust/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[target.x86_64-unknown-linux-musl]
rustflags = ["-C","target-feature=+crt-static"]
linker = "x86_64-linux-musl-gcc"

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
rustflags = ["-C", "target-feature=+crt-static", "-L", "/usr/lib/aarch64-linux-gnu/", "-l", "zstd"]
6 changes: 3 additions & 3 deletions plugins/edriver-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ governor = "0.6.0"
lazy_static = "1.4.0"
twox-hash = "1.6"
hex = "0.4"
libbpf-rs = {version = "0.22.1", features=["static"]}
libbpf-sys = { version = "1.2.1" }
libbpf-rs = {version = "0.23.3", features = ["static"]}
libbpf-sys = { version = "1.4.3" }
sdk = { path = "../../SDK/rust" }

[build-dependencies]
libbpf-cargo = "0.22.1"
libbpf-cargo = "0.23.3"
10 changes: 6 additions & 4 deletions plugins/edriver-rust/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
CMD_CLANG ?= clang

LIB_PATH := ../libs
LIBBPF_CFLAGS = "-fPIC"
LIBBPF_LDLAGS =
LIBBPF_SRC = $(LIB_PATH)/libbpf/src
PLATFORM := $(shell uname -m)

headers/libbpf/libbpf.a: \
$(LIBBPF_SRC) \
Expand All @@ -25,14 +27,14 @@ build: \
headers/libbpf/libbpf.a

cargo fmt
RUSTFLAGS="-C target-feature=+crt-static -L /usr/lib/x86_64-linux-gnu/" cargo build --release --target x86_64-unknown-linux-gnu --features=static

cargo build --release --bin edrivers --target $(PLATFORM)-unknown-linux-gnu --features=static
debug: \
headers/libbpf/libbpf.a

cargo fmt
RUST_BACKTRACE=1 RUSTFLAGS="-C target-feature=+crt-static -L /usr/lib/x86_64-linux-gnu/" cargo build --release --target x86_64-unknown-linux-gnu --features=static,debug
cargo build --release --bin edrivers --target $(PLATFORM)-unknown-linux-gnu --features=static,debug

test:
cargo fmt
RUSTFLAGS="-C target-feature=+crt-static -L /usr/lib/x86_64-linux-gnu/" cargo test --target x86_64-unknown-linux-gnu --features=debug,static
cargo test --bin edrivers --target $(PLATFORM)-unknown-linux-gnu --features=static,debug
23 changes: 11 additions & 12 deletions plugins/edriver-rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ fn main() {

SkeletonBuilder::new()
.source(SRC)
.clang_args(
"-c
-D__BPF_TRACING__
-DCORE
-I src/bpf/headers/
-I../libs/core/
-I../libs/bpfheaders/
-I src/bpf/
-target bpf
-O2 -g
-march=bpf -mcpu=v2",
)
.clang_args([
"-c",
"-D__BPF_TRACING__",
"-DCORE",
"-Isrc/bpf/headers/",
"-I../libs/core/",
"-I../libs/bpfheaders/",
"-Isrc/bpf/",
"-O2 -g",
"-mcpu=v2",
])
.debug(false)
.build_and_generate(&out)
.unwrap();
Expand Down
Binary file modified plugins/edriver-rust/src/bpf/headers/libbpf/libbpf.a
Binary file not shown.
Binary file modified plugins/edriver-rust/src/bpf/headers/libbpf/obj/libbpf.a
Binary file not shown.
2 changes: 1 addition & 1 deletion plugins/edriver/bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ hades_ebpf_driver.bpf.core.o: \
-I $(LIB_PATH)/bpfheaders/ \
-target bpf \
-O2 -g \
-march=bpf -mcpu=v2 \
-mcpu=v2 \
-c $(HADES_SRC) \
-o $@

Expand Down
9 changes: 9 additions & 0 deletions plugins/libs/bpfheaders/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ static __always_inline __u64 *get_config(__u32 key)
return bpf_map_lookup_elem(&config_map, &key);
}

// compatibility for kernel version v6.4.x and higher
// iovec changed: iov to __iov
// referer: https://elixir.bootlin.com/linux/v6.4.16/source/include/linux/uio.h
// static __always_inline struct iovec hades_iter_iov(struct msghdr *msg)
// {
// struct iovec *iov = (struct iovec *)READ_KERN(msg->msg_iter.iov);
// return iov;
// }

/* config */
// #define DENY_BPF 0
#define STEXT 0
Expand Down

0 comments on commit a5f18ec

Please sign in to comment.