Skip to content

Commit 4a86e30

Browse files
authored
Merge pull request #76 from ANLAB-KAIST/leeopop-upgrade-bindgen
Fix always inline
2 parents 6492f23 + f2df642 commit 4a86e30

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

dpdk-sys/build.rs

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ impl State {
303303
];
304304

305305
// Remove blacklist headers
306-
let blacklist_prefix = vec!["rte_acc_"];
306+
let blacklist_prefix = vec!["rte_acc_", "rte_dmadev", "power_"];
307+
let blacklist_postfix = vec!["_adaptor", "_adapter"];
307308
let mut name_set: Vec<String> = vec![];
308309
for file in &headers {
309310
let file_name = String::from(file.file_stem().unwrap().to_str().unwrap());
@@ -327,6 +328,12 @@ impl State {
327328
continue 'outer;
328329
}
329330
}
331+
for black in &blacklist_postfix {
332+
// println!("cargo:warning=header-name: {} {}", file_name, black);
333+
if file_name.ends_with(black) {
334+
continue 'outer;
335+
}
336+
}
330337
// println!("cargo:warning=header-name: {}", file_name);
331338
new_vec.push(file.clone());
332339
}
@@ -404,6 +411,7 @@ impl State {
404411
let mut use_def_map = HashMap::new();
405412
let mut global_use_def_map = HashMap::new();
406413
let target_path = self.out_path.join("dpdk.h");
414+
let mut is_always_inline_fn: HashMap<String, bool> = HashMap::new();
407415
{
408416
let clang = clang::Clang::new().unwrap();
409417
let index = clang::Index::new(&clang, true, true);
@@ -438,7 +446,61 @@ impl State {
438446
if clang::StorageClass::Static != storage || !(is_decl && is_inline_fn) {
439447
continue;
440448
}
441-
// println!("cargo:warning={} {} {} {:?}", name, is_decl, f.is_inline_function(), storage);
449+
// println!("cargo:warning={} {} {} {}", name, f.has_attributes(), f.is_inline_function(), f.is_const_method());
450+
let mut success = true;
451+
let do_check;
452+
if let Some(true) = is_always_inline_fn.get(&name) {
453+
do_check = false;
454+
success = false;
455+
} else {
456+
do_check = true;
457+
}
458+
if do_check {
459+
success = false;
460+
// Should check whether __always_inline is used.
461+
let test_template = self.project_path.join("gen/inline_test.c");
462+
let builder = cc::Build::new();
463+
let compiler = builder.get_compiler();
464+
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();
469+
let output_include = self.out_path.to_str().unwrap().to_string();
470+
let out_path = self.out_path.clone();
471+
472+
let target_bin_path =
473+
out_path.join(format!("inline_test_{}", name));
474+
475+
if target_bin_path.exists() {
476+
fs::remove_file(target_bin_path.clone()).unwrap();
477+
}
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();
492+
if let Ok(ret) = ret {
493+
if ret.status.success() {
494+
success = true;
495+
println!("cargo:warning={} compile success {}", name, success);
496+
}
497+
}
498+
is_always_inline_fn.insert(name.clone(), success);
499+
}
500+
if !success {
501+
println!("cargo:warning={} compile failed", name);
502+
continue;
503+
}
442504

443505
// Extract type names in C and Rust.
444506
let c_return_type_string = return_type.get_display_name();

dpdk-sys/gen/inline_test.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdio.h>
2+
#include <stdint.h>
3+
#include <stddef.h>
4+
#include <sys/types.h>
5+
#include <inttypes.h>
6+
#include "dpdk.h"
7+
8+
void __attribute__ ((noinline)) test_fn()
9+
{
10+
void* __unused = __CHECK_FN;
11+
}
12+
13+
int main() {
14+
test_fn();
15+
return 0;
16+
}

0 commit comments

Comments
 (0)