@@ -4,6 +4,7 @@ extern crate clang;
44extern crate etrace;
55extern crate itertools;
66extern crate num_cpus;
7+ extern crate pkg_config;
78extern crate regex;
89
910use 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