Skip to content

Commit 131e38b

Browse files
committed
refactor pkg-config
1 parent e1eff47 commit 131e38b

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

dpdk-sys/build.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern crate pkg_config;
88
extern crate regex;
99

1010
use etrace::some_or;
11+
use etrace::ok_or;
1112
use itertools::Itertools;
1213
use regex::Regex;
1314
use std::cmp::Ordering;
@@ -182,24 +183,30 @@ impl State {
182183
fn find_dpdk(&mut self) {
183184
// To find correct lib path of this platform.
184185

185-
let lib = pkg_config::Config::new().statik(true).probe("libdpdk").unwrap();
186-
187-
let include_path = if !lib.include_paths.is_empty() {
188-
lib.include_paths[0].clone()
189-
} else {
190-
panic!("DPDK is not installed on your system! (Cannot find libdpdk)");
191-
};
186+
let dpdk: std::result::Result<pkg_config::Library, pkg_config::Error> = pkg_config::Config::new().statik(true).probe("libdpdk");
187+
let dpdk = ok_or!(dpdk, panic!("DPDK is not installed on your system! (Cannot find libdpdk)"));
188+
189+
190+
for include_path in &dpdk.include_paths{
191+
let config_header = include_path.join("rte_config.h");
192+
if config_header.exists(){
193+
println!("cargo:rerun-if-changed={}", include_path.to_str().unwrap());
194+
self.include_path = Some(include_path.clone());
195+
self.dpdk_config = Some(config_header);
196+
}
197+
}
198+
if self.dpdk_config.is_none() || self.include_path.is_none(){
199+
panic!("DPDK is not installed on your system! (Cannot find rte_config.h)");
200+
}
192201

193-
let library_path = if !lib.link_paths.is_empty() {
194-
lib.link_paths[0].clone()
202+
let library_path = if !dpdk.link_paths.is_empty() {
203+
dpdk.link_paths[0].clone()
195204
} else {
196-
panic!("DPDK is not installed on your system! (Cannot find libdpdk)");
205+
panic!("DPDK is not installed on your system! (Cannot find library path)");
197206
};
198207

199-
println!("cargo:rerun-if-changed={}", include_path.to_str().unwrap());
200208
println!("cargo:rerun-if-changed={}", library_path.to_str().unwrap());
201-
let config_header = include_path.join("rte_config.h");
202-
self.include_path = Some(include_path);
209+
203210
self.library_path = Some(library_path);
204211
for entry in self
205212
.project_path
@@ -220,8 +227,7 @@ impl State {
220227
println!("cargo:rerun-if-env-changed=RTE_SDK");
221228
println!("cargo:rerun-if-env-changed=RTE_TARGET");
222229

223-
self.dpdk_config = Some(config_header);
224-
self.dpdk = Some(lib);
230+
self.dpdk = Some(dpdk);
225231
}
226232

227233
/// Search through DPDK's link dir and extract library names.

0 commit comments

Comments
 (0)