Skip to content

Commit 6492f23

Browse files
authored
Merge pull request #75 from ANLAB-KAIST/feature-pkg-config
Using pkg-config
2 parents 08cc418 + b352f2b commit 6492f23

File tree

5 files changed

+31
-25
lines changed

5 files changed

+31
-25
lines changed

Cargo.lock

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ WORKDIR /
44
RUN echo "APT last updated: 2024/01/01"
55

66
RUN apt-get update -y && apt-get dist-upgrade -y && apt-get autoremove -y && apt-get autoclean -y
7-
RUN apt-get install -y linux-headers-generic build-essential libnuma-dev git meson python3-pyelftools curl libclang-dev clang llvm-dev libbsd-dev
7+
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
88
RUN apt-get install -y curl git tar
99

1010
ENV RTE_SDK=/usr/local/share/dpdk

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Commonly, following packages are required to build DPDK.
3131
```sh
3232
apt-get install -y curl git build-essential libnuma-dev meson python3-pyelftools # To download and build DPDK
3333
apt-get install -y linux-headers-`uname -r` # To build kernel drivers
34-
apt-get install -y libclang-dev clang llvm-dev # To analyze DPDK headers and create bindings
34+
apt-get install -y libclang-dev clang llvm-dev pkg-config # To analyze DPDK headers and create bindings
3535
```
3636

3737
DPDK can be installed by following commands:

dpdk-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ cc = "1"
2323
etrace = "1"
2424
itertools = "0.10"
2525
crossbeam-queue = "0.3"
26+
pkg-config = "0.3"
2627

2728
[features]
2829
default = ["constants_cache"]

dpdk-sys/build.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern crate clang;
44
extern crate etrace;
55
extern crate itertools;
66
extern crate num_cpus;
7+
extern crate pkg_config;
78
extern crate regex;
89

910
use etrace::some_or;
@@ -176,29 +177,26 @@ impl State {
176177
/// This function validates whether DPDK is installed.
177178
fn find_dpdk(&mut self) {
178179
// To find correct lib path of this platform.
179-
let output = Command::new("cc")
180-
.args(["-dumpmachine"])
181-
.output()
182-
.expect("failed obtain current machine");
183-
let machine_string = String::from(String::from_utf8(output.stdout).unwrap().trim());
184-
let config_header = PathBuf::from("/usr/local/include/rte_config.h");
185-
let build_config_header = PathBuf::from("/usr/local/include/rte_build_config.h");
186-
187-
if config_header.exists() && build_config_header.exists() {
188-
self.include_path = Some(PathBuf::from("/usr/local/include"));
189-
self.library_path = Some(PathBuf::from(format!("/usr/local/lib/{}", machine_string)));
180+
181+
let lib = pkg_config::probe_library("libdpdk").unwrap();
182+
183+
let include_path = if !lib.include_paths.is_empty() {
184+
lib.include_paths[0].clone()
190185
} else {
191-
panic!(
192-
"DPDK is not installed on your system! (Cannot find {} nor {})",
193-
config_header.to_str().unwrap(),
194-
build_config_header.to_str().unwrap()
195-
);
196-
}
197-
println!("cargo:rerun-if-changed={}", config_header.to_str().unwrap());
198-
println!(
199-
"cargo:rerun-if-changed={}",
200-
build_config_header.to_str().unwrap()
201-
);
186+
panic!("DPDK is not installed on your system! (Cannot find libdpdk)");
187+
};
188+
189+
let library_path = if !lib.link_paths.is_empty() {
190+
lib.link_paths[0].clone()
191+
} else {
192+
panic!("DPDK is not installed on your system! (Cannot find libdpdk)");
193+
};
194+
195+
println!("cargo:rerun-if-changed={}", include_path.to_str().unwrap());
196+
println!("cargo:rerun-if-changed={}", library_path.to_str().unwrap());
197+
let config_header = include_path.join("rte_config.h");
198+
self.include_path = Some(include_path);
199+
self.library_path = Some(library_path);
202200
for entry in self
203201
.project_path
204202
.join("gen")

0 commit comments

Comments
 (0)