Skip to content

Using pkg-config #75

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 3 commits into from
Feb 20, 2025
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
9 changes: 8 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /
RUN echo "APT last updated: 2024/01/01"

RUN apt-get update -y && apt-get dist-upgrade -y && apt-get autoremove -y && apt-get autoclean -y
RUN apt-get install -y linux-headers-generic build-essential libnuma-dev git meson python3-pyelftools curl libclang-dev clang llvm-dev libbsd-dev
RUN apt-get install -y linux-headers-generic build-essential libnuma-dev git meson python3-pyelftools curl libclang-dev clang llvm-dev libbsd-dev pkg-config
RUN apt-get install -y curl git tar

ENV RTE_SDK=/usr/local/share/dpdk
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Commonly, following packages are required to build DPDK.
```sh
apt-get install -y curl git build-essential libnuma-dev meson python3-pyelftools # To download and build DPDK
apt-get install -y linux-headers-`uname -r` # To build kernel drivers
apt-get install -y libclang-dev clang llvm-dev # To analyze DPDK headers and create bindings
apt-get install -y libclang-dev clang llvm-dev pkg-config # To analyze DPDK headers and create bindings
```

DPDK can be installed by following commands:
Expand Down
1 change: 1 addition & 0 deletions dpdk-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cc = "1"
etrace = "1"
itertools = "0.10"
crossbeam-queue = "0.3"
pkg-config = "0.3"

[features]
default = ["constants_cache"]
Expand Down
42 changes: 20 additions & 22 deletions dpdk-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate clang;
extern crate etrace;
extern crate itertools;
extern crate num_cpus;
extern crate pkg_config;
extern crate regex;

use etrace::some_or;
Expand Down Expand Up @@ -176,29 +177,26 @@ impl State {
/// This function validates whether DPDK is installed.
fn find_dpdk(&mut self) {
// To find correct lib path of this platform.
let output = Command::new("cc")
.args(["-dumpmachine"])
.output()
.expect("failed obtain current machine");
let machine_string = String::from(String::from_utf8(output.stdout).unwrap().trim());
let config_header = PathBuf::from("/usr/local/include/rte_config.h");
let build_config_header = PathBuf::from("/usr/local/include/rte_build_config.h");

if config_header.exists() && build_config_header.exists() {
self.include_path = Some(PathBuf::from("/usr/local/include"));
self.library_path = Some(PathBuf::from(format!("/usr/local/lib/{}", machine_string)));

let lib = pkg_config::probe_library("libdpdk").unwrap();

let include_path = if !lib.include_paths.is_empty() {
lib.include_paths[0].clone()
} else {
panic!(
"DPDK is not installed on your system! (Cannot find {} nor {})",
config_header.to_str().unwrap(),
build_config_header.to_str().unwrap()
);
}
println!("cargo:rerun-if-changed={}", config_header.to_str().unwrap());
println!(
"cargo:rerun-if-changed={}",
build_config_header.to_str().unwrap()
);
panic!("DPDK is not installed on your system! (Cannot find libdpdk)");
};

let library_path = if !lib.link_paths.is_empty() {
lib.link_paths[0].clone()
} else {
panic!("DPDK is not installed on your system! (Cannot find libdpdk)");
};

println!("cargo:rerun-if-changed={}", include_path.to_str().unwrap());
println!("cargo:rerun-if-changed={}", library_path.to_str().unwrap());
let config_header = include_path.join("rte_config.h");
self.include_path = Some(include_path);
self.library_path = Some(library_path);
for entry in self
.project_path
.join("gen")
Expand Down