@@ -7,6 +7,7 @@ extern crate num_cpus;
77extern crate pkg_config;
88extern crate regex;
99
10+ use etrace:: ok_or;
1011use etrace:: some_or;
1112use itertools:: Itertools ;
1213use regex:: Regex ;
@@ -68,6 +69,9 @@ struct State {
6869 /// DPDK config file (will be included as a predefined macro file).
6970 dpdk_config : Option < PathBuf > ,
7071
72+ // DPDK pkg-config result
73+ dpdk : Option < pkg_config:: Library > ,
74+
7175 /// Use definitions for automatically found EAL APIs.
7276 eal_function_use_defs : Vec < String > ,
7377
@@ -96,6 +100,7 @@ impl State {
96100 dpdk_headers : Default :: default ( ) ,
97101 dpdk_links : Default :: default ( ) ,
98102 dpdk_config : Default :: default ( ) ,
103+ dpdk : Default :: default ( ) ,
99104 eal_function_use_defs : Default :: default ( ) ,
100105 global_eal_function_use_defs : Default :: default ( ) ,
101106 static_functions : Default :: default ( ) ,
@@ -178,24 +183,33 @@ impl State {
178183 fn find_dpdk ( & mut self ) {
179184 // To find correct lib path of this platform.
180185
181- let lib = pkg_config:: probe_library ( "libdpdk" ) . unwrap ( ) ;
186+ let dpdk: std:: result:: Result < pkg_config:: Library , pkg_config:: Error > =
187+ pkg_config:: Config :: new ( ) . statik ( true ) . probe ( "libdpdk" ) ;
188+ let dpdk = ok_or ! (
189+ dpdk,
190+ panic!( "DPDK is not installed on your system! (Cannot find libdpdk)" )
191+ ) ;
182192
183- let include_path = if !lib. include_paths . is_empty ( ) {
184- lib. include_paths [ 0 ] . clone ( )
185- } else {
186- panic ! ( "DPDK is not installed on your system! (Cannot find libdpdk)" ) ;
187- } ;
193+ for include_path in & dpdk. include_paths {
194+ let config_header = include_path. join ( "rte_config.h" ) ;
195+ if config_header. exists ( ) {
196+ println ! ( "cargo:rerun-if-changed={}" , include_path. to_str( ) . unwrap( ) ) ;
197+ self . include_path = Some ( include_path. clone ( ) ) ;
198+ self . dpdk_config = Some ( config_header) ;
199+ }
200+ }
201+ if self . dpdk_config . is_none ( ) || self . include_path . is_none ( ) {
202+ panic ! ( "DPDK is not installed on your system! (Cannot find rte_config.h)" ) ;
203+ }
188204
189- let library_path = if !lib . link_paths . is_empty ( ) {
190- lib . link_paths [ 0 ] . clone ( )
205+ let library_path = if !dpdk . link_paths . is_empty ( ) {
206+ dpdk . link_paths [ 0 ] . clone ( )
191207 } else {
192- panic ! ( "DPDK is not installed on your system! (Cannot find libdpdk )" ) ;
208+ panic ! ( "DPDK is not installed on your system! (Cannot find library path )" ) ;
193209 } ;
194210
195- println ! ( "cargo:rerun-if-changed={}" , include_path. to_str( ) . unwrap( ) ) ;
196211 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) ;
212+
199213 self . library_path = Some ( library_path) ;
200214 for entry in self
201215 . project_path
@@ -216,7 +230,7 @@ impl State {
216230 println ! ( "cargo:rerun-if-env-changed=RTE_SDK" ) ;
217231 println ! ( "cargo:rerun-if-env-changed=RTE_TARGET" ) ;
218232
219- self . dpdk_config = Some ( config_header ) ;
233+ self . dpdk = Some ( dpdk ) ;
220234 }
221235
222236 /// Search through DPDK's link dir and extract library names.
@@ -411,12 +425,19 @@ impl State {
411425 let mut use_def_map = HashMap :: new ( ) ;
412426 let mut global_use_def_map = HashMap :: new ( ) ;
413427 let target_path = self . out_path . join ( "dpdk.h" ) ;
414- let mut is_always_inline_fn: HashMap < String , bool > = HashMap :: new ( ) ;
428+ // let mut is_always_inline_fn: HashMap<String, bool> = HashMap::new();
415429 {
416430 let clang = clang:: Clang :: new ( ) . unwrap ( ) ;
417431 let index = clang:: Index :: new ( & clang, true , true ) ;
418432 let trans_unit = self . trans_unit_from_header ( & index, target_path, false ) ;
419-
433+ // panic!(
434+ // "{:#?}",
435+ // trans_unit
436+ // .get_entity()
437+ // .get_children()
438+ // .into_iter()
439+ // .collect::<Vec<_>>()
440+ // );
420441 // Iterate through each EAL header files and extract function definitions.
421442 ' each_function: for f in trans_unit
422443 . get_entity ( )
@@ -446,6 +467,7 @@ impl State {
446467 if clang:: StorageClass :: Static != storage || !( is_decl && is_inline_fn) {
447468 continue ;
448469 }
470+ /*
449471 // println!("cargo:warning={} {} {} {}", name, f.has_attributes(), f.is_inline_function(), f.is_const_method());
450472 let mut success = true;
451473 let do_check;
@@ -462,46 +484,62 @@ impl State {
462484 let builder = cc::Build::new();
463485 let compiler = builder.get_compiler();
464486 let cc_name = compiler.path().to_str().unwrap().to_string();
465-
466- let dpdk_include_path = self . include_path . as_ref ( ) . unwrap ( ) ;
467- let dpdk_config_path = self . dpdk_config . as_ref ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
468- let dpdk_include = dpdk_include_path. to_str ( ) . unwrap ( ) . to_string ( ) ;
487+
488+ let dpdk_config_path = self
489+ .dpdk_config
490+ .as_ref()
491+ .unwrap()
492+ .to_str()
493+ .unwrap()
494+ .to_string();
469495 let output_include = self.out_path.to_str().unwrap().to_string();
470496 let out_path = self.out_path.clone();
471497
472- let target_bin_path =
473- out_path. join ( format ! ( "inline_test_{}" , name) ) ;
498+ let target_bin_path = out_path.join(format!("inline_test_{}", name));
474499
475500 if target_bin_path.exists() {
476501 fs::remove_file(target_bin_path.clone()).unwrap();
477502 }
478- let ret = Command :: new ( cc_name. clone ( ) )
479- . arg ( "-Wall" )
480- . arg ( "-Wextra" )
481- . arg ( "-std=c99" )
482- . arg ( format ! ( "-I{}" , dpdk_include) )
483- . arg ( format ! ( "-I{}" , output_include) )
484- . arg ( "-imacros" )
485- . arg ( dpdk_config_path)
486- . arg ( "-march=native" )
487- . arg ( format ! ( "-D__CHECK_FN={}" , name) )
488- . arg ( "-o" )
489- . arg ( target_bin_path. clone ( ) )
490- . arg ( test_template. clone ( ) )
491- . output ( ) ;
503+ let dpdk = self.dpdk.as_ref().unwrap();
504+ let includes = dpdk
505+ .include_paths
506+ .iter()
507+ .map(|x| format!("-I{}", x.to_str().unwrap()));
508+ // let libs = dpdk.libs.iter().map(|x| format!("-l{}", x));
509+ // NOTE: do not link libs here. The point of below is to check compilation without symbols
510+ let ret: std::result::Result<std::process::Output, Error> =
511+ Command::new(cc_name.clone())
512+ .arg("-Wall")
513+ .arg("-Wextra")
514+ .arg("-std=gnu11")
515+ .args(includes)
516+ .arg(format!("-I{}", output_include))
517+ .arg("-include")
518+ .arg(dpdk_config_path)
519+ .arg("-march=native")
520+ .arg(format!("-D__CHECK_FN={}", name))
521+ .arg("-o")
522+ .arg(target_bin_path.clone())
523+ // .args(libs)
524+ .arg(test_template.clone())
525+ .output();
492526 if let Ok(ret) = ret {
493527 if ret.status.success() {
494528 success = true;
495529 println!("cargo:warning={} compile success {}", name, success);
530+ panic!("@@");
531+ } else {
532+ println!("cargo:warning={:?} compile failed", ret);
533+ panic!("@@@");
496534 }
497535 }
498536 is_always_inline_fn.insert(name.clone(), success);
499537 }
500538 if !success {
501- println ! ( "cargo:warning={} compile failed" , name) ;
539+ // println!("cargo:warning={} compile failed", name);
502540 continue;
503541 }
504-
542+ */
505543 // Extract type names in C and Rust.
506544 let c_return_type_string = return_type. get_display_name ( ) ;
507545 let rust_return_type_string =
@@ -735,7 +773,7 @@ impl State {
735773 . arg ( "-Wall" )
736774 . arg ( "-Wextra" )
737775 . arg ( "-Werror" )
738- . arg ( "-std=c99 " )
776+ . arg ( "-std=gnu11 " )
739777 . arg ( format ! ( "-I{}" , dpdk_include) )
740778 . arg ( format ! ( "-I{}" , output_include) )
741779 . arg ( "-imacros" )
@@ -856,7 +894,7 @@ impl State {
856894 total_string += "\n }\n " ;
857895 self . static_constants = total_string;
858896 }
859- // gcc -S test.c -Wall -Wextra -std=c99 -Werror
897+ // gcc -S test.c -Wall -Wextra -std=gnu11 -Werror
860898
861899 let header_path: PathBuf = self . out_path . join ( "static.h" ) ;
862900 let header_template = self . project_path . join ( "gen/static.h.template" ) ;
0 commit comments