Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build perf: Make calls to bindgen run in parallel #159

Merged
merged 7 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/wdk-build/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub trait BuilderExt {
///
/// Implementation may return `wdk_build::ConfigError` if it fails to create
/// a builder
fn wdk_default(c_header_files: Vec<&str>, config: Config) -> Result<Builder, ConfigError>;
fn wdk_default(c_header_files: Vec<&str>, config: &Config) -> Result<Builder, ConfigError>;
}

impl BuilderExt for Builder {
Expand All @@ -26,7 +26,7 @@ impl BuilderExt for Builder {
///
/// Will return `wdk_build::ConfigError` if any of the resolved include or
/// library paths do not exist
fn wdk_default(c_header_files: Vec<&str>, config: Config) -> Result<Self, ConfigError> {
fn wdk_default(c_header_files: Vec<&str>, config: &Config) -> Result<Self, ConfigError> {
NateD-MSFT marked this conversation as resolved.
Show resolved Hide resolved
let mut builder = Self::default();

for c_header in c_header_files {
Expand Down
29 changes: 21 additions & 8 deletions crates/wdk-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use std::{
env,
path::{Path, PathBuf},
thread::{self, JoinHandle},
};

use bindgen::CodegenConfig;
Expand All @@ -21,7 +22,7 @@ use wdk_build::{BuilderExt, Config, ConfigError, DriverConfig, KMDFConfig};
// "2.0", "2.15", "2.17", "2.19", "2.21", "2.23", "2.25", "2.27", "2.31",
// "2.33", ];

fn generate_constants(out_path: &Path, config: Config) -> Result<(), ConfigError> {
fn generate_constants(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
Ok(
bindgen::Builder::wdk_default(vec!["src/ntddk-input.h", "src/wdf-input.h"], config)?
.with_codegen_config(CodegenConfig::VARS)
Expand All @@ -31,7 +32,7 @@ fn generate_constants(out_path: &Path, config: Config) -> Result<(), ConfigError
)
}

fn generate_types(out_path: &Path, config: Config) -> Result<(), ConfigError> {
fn generate_types(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
Ok(
bindgen::Builder::wdk_default(vec!["src/ntddk-input.h", "src/wdf-input.h"], config)?
.with_codegen_config(CodegenConfig::TYPES)
Expand All @@ -41,7 +42,7 @@ fn generate_types(out_path: &Path, config: Config) -> Result<(), ConfigError> {
)
}

fn generate_ntddk(out_path: &Path, config: Config) -> Result<(), ConfigError> {
fn generate_ntddk(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
Ok(
bindgen::Builder::wdk_default(vec!["src/ntddk-input.h"], config)?
.with_codegen_config((CodegenConfig::TYPES | CodegenConfig::VARS).complement())
Expand All @@ -51,7 +52,7 @@ fn generate_ntddk(out_path: &Path, config: Config) -> Result<(), ConfigError> {
)
}

fn generate_wdf(out_path: &Path, config: Config) -> Result<(), ConfigError> {
fn generate_wdf(out_path: &Path, config: &Config) -> Result<(), ConfigError> {
// As of NI WDK, this may generate an empty file due to no non-type and non-var
// items in the wdf headers(i.e. functions are all inlined). This step is
// intentionally left here in case older WDKs have non-inlined functions or new
Expand Down Expand Up @@ -135,11 +136,23 @@ fn main() -> anyhow::Result<()> {
),
];

let mut handles = Vec::<JoinHandle<Result<(), ConfigError>>>::new();
for out_path in out_paths {
generate_constants(&out_path, config.clone())?;
generate_types(&out_path, config.clone())?;
generate_ntddk(&out_path, config.clone())?;
generate_wdf(&out_path, config.clone())?;
let temp_config = config.clone();
let handle: JoinHandle<Result<(), ConfigError>> = thread::spawn(move || {
generate_constants(&out_path, &temp_config)?;
NateD-MSFT marked this conversation as resolved.
Show resolved Hide resolved
generate_types(&out_path, &temp_config)?;
generate_ntddk(&out_path, &temp_config)?;
generate_wdf(&out_path, &temp_config)?;
Ok(())
});
handles.push(handle);
}

for handle in handles {
if let Err(e) = handle.join().unwrap() {
return Err(e.into());
}
}

Ok(config.export_config()?)
Expand Down
Loading