Skip to content

Commit

Permalink
optimize header generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Wanja Zaeske committed Sep 6, 2022
1 parent a28e44f commit e263377
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 19 deletions.
85 changes: 82 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,96 @@ extern crate bindgen;
use std::env;
use std::path::PathBuf;

const BASE_HEADER: &[(u8, &str)] = &[
(10, "xalCpuIfc.h"),
(10, "xalTypesIfc.h"),
(10, "xArchTypeIfc.h"),
(10, "xBoardTypeIfc.h"),
(10, "xcfTypeIfc.h"),
(10, "xCommPortIfc.h"),
(10, "xConsoleIfc.h"),
(10, "xLegacyIfc.h"),
(10, "xPartitionIfc.h"),
(10, "xQueuingPortIfc.h"),
(10, "xSamplingPortIfc.h"),
(10, "xScheduleIfc.h"),
(10, "xTraceIfc.h"),
(10, "xTypeIfc.h"),
(10, "xVClockIfc.h"),
(10, "xVCpuIfc.h"),
(10, "xVIrqCtrlIfc.h"),
(10, "xVTimerIfc.h"),
];

#[allow(dead_code)]
const SKE_HEADER: &[(u8, &str)] = &[
// "skeconfig.h",
// "ske_external_ifc.h",
// "ske_init.h",
// "ske_irq.h",
// "ske_partition.h",
// "ske_queuing_port.h",
// "ske_sampling_port.h",
// "ske_time.h",
// "ske_trace.h",
// "ske_types.h",
// "ske_yield.h",
(0, "types.h"),
(10, "xalStdio.h"),
(10, "xalString.h"),
(5, "xalTypes.h"),
];

#[allow(dead_code)]
const XNG_HEADER: &[(u8, &str)] = &[
(10, "xalSpinLockIfc.h"),
(10, "xArchHealthMonitorIfc.h"),
(10, "xArchLegacyIfc.h"),
(10, "xArchTraceIfc.h"),
(10, "xAsmIfc.h"),
(10, "xcfArchTypeIfc.h"),
(10, "xcfBoardTypeIfc.h"),
(10, "xConfigurationIfc.h"),
(10, "xc/xalDivIfc.h"),
(10, "xc/xalStdio.h"),
(10, "xc/xalString.h"),
(10, "xc/xalTypes.h"),
(10, "xIoPortIfc.h"),
(10, "xIpviIfc.h"),
(10, "xre-armv7a-vmsa-tz/xalCpuIfc.h"),
(10, "xre-armv7a-vmsa-tz/xalSpinLockIfc.h"),
(10, "xre-armv7a-vmsa-tz/xalTypesIfc.h"),
(10, "xSystemCfgIfc.h"),
// TODO these belongs to BASE_HEADER, but it includes xArchHealthMonitorIfc.h
// which is currently only provided by XNG, thus it breaks the compilation to
// have this in SKE builds
(10, "xHypervisorIfc.h"),
(5, "xHealthMonitorIfc.h"),
];

fn main() {
// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed=wrapper.h");
let headers_to_include = BASE_HEADER.iter();

#[cfg(feature = "std")]
let headers_to_include = headers_to_include.chain(SKE_HEADER.iter());

#[cfg(not(feature = "std"))]
let headers_to_include = headers_to_include.chain(XNG_HEADER.iter());

let mut sorted_includes: Vec<_> = headers_to_include.collect();
sorted_includes.sort();
let wrapper: String = sorted_includes
.into_iter()
.map(|(_, header)| format!("#include \"{header}\"\n"))
.collect();

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("wrapper.h")
.header_contents("wrapper.h", &wrapper)
.use_core()
.allowlist_function("(x|X).*")
.allowlist_type("(x|X).*")
Expand Down
16 changes: 0 additions & 16 deletions wrapper.h

This file was deleted.

0 comments on commit e263377

Please sign in to comment.