@@ -7,6 +7,7 @@ extern crate num_cpus;
7
7
extern crate pkg_config;
8
8
extern crate regex;
9
9
10
+ use etrace:: ok_or;
10
11
use etrace:: some_or;
11
12
use itertools:: Itertools ;
12
13
use regex:: Regex ;
@@ -68,6 +69,9 @@ struct State {
68
69
/// DPDK config file (will be included as a predefined macro file).
69
70
dpdk_config : Option < PathBuf > ,
70
71
72
+ // DPDK pkg-config result
73
+ dpdk : Option < pkg_config:: Library > ,
74
+
71
75
/// Use definitions for automatically found EAL APIs.
72
76
eal_function_use_defs : Vec < String > ,
73
77
@@ -96,6 +100,7 @@ impl State {
96
100
dpdk_headers : Default :: default ( ) ,
97
101
dpdk_links : Default :: default ( ) ,
98
102
dpdk_config : Default :: default ( ) ,
103
+ dpdk : Default :: default ( ) ,
99
104
eal_function_use_defs : Default :: default ( ) ,
100
105
global_eal_function_use_defs : Default :: default ( ) ,
101
106
static_functions : Default :: default ( ) ,
@@ -178,24 +183,33 @@ impl State {
178
183
fn find_dpdk ( & mut self ) {
179
184
// To find correct lib path of this platform.
180
185
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
+ ) ;
182
192
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
+ }
188
204
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 ( )
191
207
} 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 )" ) ;
193
209
} ;
194
210
195
- println ! ( "cargo:rerun-if-changed={}" , include_path. to_str( ) . unwrap( ) ) ;
196
211
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
+
199
213
self . library_path = Some ( library_path) ;
200
214
for entry in self
201
215
. project_path
@@ -216,7 +230,7 @@ impl State {
216
230
println ! ( "cargo:rerun-if-env-changed=RTE_SDK" ) ;
217
231
println ! ( "cargo:rerun-if-env-changed=RTE_TARGET" ) ;
218
232
219
- self . dpdk_config = Some ( config_header ) ;
233
+ self . dpdk = Some ( dpdk ) ;
220
234
}
221
235
222
236
/// Search through DPDK's link dir and extract library names.
@@ -411,12 +425,19 @@ impl State {
411
425
let mut use_def_map = HashMap :: new ( ) ;
412
426
let mut global_use_def_map = HashMap :: new ( ) ;
413
427
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();
415
429
{
416
430
let clang = clang:: Clang :: new ( ) . unwrap ( ) ;
417
431
let index = clang:: Index :: new ( & clang, true , true ) ;
418
432
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
+ // );
420
441
// Iterate through each EAL header files and extract function definitions.
421
442
' each_function: for f in trans_unit
422
443
. get_entity ( )
@@ -446,6 +467,7 @@ impl State {
446
467
if clang:: StorageClass :: Static != storage || !( is_decl && is_inline_fn) {
447
468
continue ;
448
469
}
470
+ /*
449
471
// println!("cargo:warning={} {} {} {}", name, f.has_attributes(), f.is_inline_function(), f.is_const_method());
450
472
let mut success = true;
451
473
let do_check;
@@ -462,46 +484,62 @@ impl State {
462
484
let builder = cc::Build::new();
463
485
let compiler = builder.get_compiler();
464
486
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();
469
495
let output_include = self.out_path.to_str().unwrap().to_string();
470
496
let out_path = self.out_path.clone();
471
497
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));
474
499
475
500
if target_bin_path.exists() {
476
501
fs::remove_file(target_bin_path.clone()).unwrap();
477
502
}
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();
492
526
if let Ok(ret) = ret {
493
527
if ret.status.success() {
494
528
success = true;
495
529
println!("cargo:warning={} compile success {}", name, success);
530
+ panic!("@@");
531
+ } else {
532
+ println!("cargo:warning={:?} compile failed", ret);
533
+ panic!("@@@");
496
534
}
497
535
}
498
536
is_always_inline_fn.insert(name.clone(), success);
499
537
}
500
538
if !success {
501
- println ! ( "cargo:warning={} compile failed" , name) ;
539
+ // println!("cargo:warning={} compile failed", name);
502
540
continue;
503
541
}
504
-
542
+ */
505
543
// Extract type names in C and Rust.
506
544
let c_return_type_string = return_type. get_display_name ( ) ;
507
545
let rust_return_type_string =
@@ -735,7 +773,7 @@ impl State {
735
773
. arg ( "-Wall" )
736
774
. arg ( "-Wextra" )
737
775
. arg ( "-Werror" )
738
- . arg ( "-std=c99 " )
776
+ . arg ( "-std=gnu11 " )
739
777
. arg ( format ! ( "-I{}" , dpdk_include) )
740
778
. arg ( format ! ( "-I{}" , output_include) )
741
779
. arg ( "-imacros" )
@@ -856,7 +894,7 @@ impl State {
856
894
total_string += "\n }\n " ;
857
895
self . static_constants = total_string;
858
896
}
859
- // gcc -S test.c -Wall -Wextra -std=c99 -Werror
897
+ // gcc -S test.c -Wall -Wextra -std=gnu11 -Werror
860
898
861
899
let header_path: PathBuf = self . out_path . join ( "static.h" ) ;
862
900
let header_template = self . project_path . join ( "gen/static.h.template" ) ;
0 commit comments