diff --git a/Cargo.lock b/Cargo.lock index 2b57296..1abcfc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aho-corasick" @@ -246,6 +246,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + [[package]] name = "prettyplease" version = "0.2.16" @@ -314,6 +320,7 @@ dependencies = [ "etrace", "itertools", "num_cpus", + "pkg-config", "regex", ] diff --git a/Dockerfile b/Dockerfile index ba25f8b..7fb8059 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index 305b9ba..0e146bd 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/dpdk-sys/Cargo.toml b/dpdk-sys/Cargo.toml index 124d46f..263723e 100644 --- a/dpdk-sys/Cargo.toml +++ b/dpdk-sys/Cargo.toml @@ -23,6 +23,7 @@ cc = "1" etrace = "1" itertools = "0.10" crossbeam-queue = "0.3" +pkg-config = "0.3" [features] default = ["constants_cache"] diff --git a/dpdk-sys/build.rs b/dpdk-sys/build.rs index 2c250ca..c048b95 100644 --- a/dpdk-sys/build.rs +++ b/dpdk-sys/build.rs @@ -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; @@ -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")