Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/cargo/thiserror-1.0.55
Browse files Browse the repository at this point in the history
Signed-off-by: Melvin Wang <[email protected]>
  • Loading branch information
wmmc88 authored Jan 5, 2024
2 parents 77398d0 + 16cc3a0 commit 5800055
Show file tree
Hide file tree
Showing 12 changed files with 3,668 additions and 222 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

*.rs text diff=rust
*.toml text diff=toml
Cargo.lock text
Cargo.lock text diff=toml
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
rust_toolchain:
- stable
- beta
- nightly
# - nightly

cargo_profile:
- dev
Expand Down
21 changes: 4 additions & 17 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
rust_toolchain:
- stable
- beta
- nightly
# - nightly

cargo_profile:
- dev
Expand All @@ -45,27 +45,14 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust_toolchain }}
components: clippy

- name: Run Cargo Clippy
uses: giraffate/clippy-action@v1
with:
tool_name: Clippy
clippy_flags: --locked --profile ${{ matrix.cargo_profile }} --all-targets -- -D warnings
reporter: ${{ github.event_name == 'pull_request' && 'github-pr-review' || 'github-check' }}
github_token: ${{ secrets.GITHUB_TOKEN }}
filter_mode: nofilter
fail_on_error: true
run: cargo clippy --locked --profile ${{ matrix.cargo_profile }} --all-targets -- -D warnings

- name: Run Cargo Clippy (--features nightly)
if: matrix.rust_toolchain == 'nightly'
uses: giraffate/clippy-action@v1
with:
tool_name: Clippy (--features nightly)
clippy_flags: --locked --profile ${{ matrix.cargo_profile }} --all-targets --features nightly -- -D warnings
reporter: ${{ github.event_name == 'pull_request' && 'github-pr-review' || 'github-check' }}
github_token: ${{ secrets.GITHUB_TOKEN }}
filter_mode: nofilter
fail_on_error: true
run: cargo clippy --locked --profile ${{ matrix.cargo_profile }} --all-targets --features nightly -- -D warnings

udeps:
name: Detect Unused Cargo Dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
rust_toolchain:
- stable
- beta
- nightly
# - nightly

cargo_profile:
- dev
Expand Down
58 changes: 55 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions crates/wdk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,33 @@ pub fn call_unsafe_wdf_function_binding(input_tokens: TokenStream) -> TokenStrea
}

struct CallUnsafeWDFFunctionInput {
function_pointer_type: Ident,
function_table_index: Ident,
function_arguments: syn::punctuated::Punctuated<Expr, Token![,]>,
pointer_type: Ident,
table_index: Ident,
arguments: syn::punctuated::Punctuated<Expr, Token![,]>,
}

impl Parse for CallUnsafeWDFFunctionInput {
fn parse(input: ParseStream) -> Result<Self, Error> {
let c_function_name: String = input.parse::<Ident>()?.to_string();
input.parse::<Token![,]>()?;
let function_arguments = input.parse_terminated(Expr::parse, Token![,])?;
let arguments = input.parse_terminated(Expr::parse, Token![,])?;

Ok(Self {
function_pointer_type: format_ident!(
pointer_type: format_ident!(
"PFN_{uppercase_c_function_name}",
uppercase_c_function_name = c_function_name.to_uppercase()
),
function_table_index: format_ident!("{c_function_name}TableIndex"),
function_arguments,
table_index: format_ident!("{c_function_name}TableIndex"),
arguments,
})
}
}

fn call_unsafe_wdf_function_binding_impl(input_tokens: TokenStream2) -> TokenStream2 {
let CallUnsafeWDFFunctionInput {
function_pointer_type,
function_table_index,
function_arguments,
pointer_type,
table_index,
arguments,
} = match parse2::<CallUnsafeWDFFunctionInput>(input_tokens) {
Ok(syntax_tree) => syntax_tree,
Err(err) => return err.to_compile_error(),
Expand All @@ -129,7 +129,7 @@ fn call_unsafe_wdf_function_binding_impl(input_tokens: TokenStream2) -> TokenStr
force_unsafe();

// Get handle to WDF function from the function table
let wdf_function: wdk_sys::#function_pointer_type = Some(
let wdf_function: wdk_sys::#pointer_type = Some(
// SAFETY: This `transmute` from a no-argument function pointer to a function pointer with the correct
// arguments for the WDF function is safe befause WDF maintains the strict mapping between the
// function table index and the correct function pointer type.
Expand All @@ -138,7 +138,7 @@ fn call_unsafe_wdf_function_binding_impl(input_tokens: TokenStream2) -> TokenStr
unsafe {
core::mem::transmute(
// FIXME: investigate why _WDFFUNCENUM does not have a generated type alias without the underscore prefix
wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::#function_table_index as usize],
wdk_sys::WDF_FUNCTION_TABLE[wdk_sys::_WDFFUNCENUM::#table_index as usize],
)
}
);
Expand All @@ -147,15 +147,15 @@ fn call_unsafe_wdf_function_binding_impl(input_tokens: TokenStream2) -> TokenStr
// the various wdf headers(ex. wdfdriver.h)
if let Some(wdf_function) = wdf_function {
// SAFETY: The WDF function pointer is always valid because its an entry in
// `wdk_sys::WDF_FUNCTION_TABLE` indexed by `function_table_index` and guarded by the type-safety of
// `function_pointer_type`. The passed arguments are also guaranteed to be of a compatible type due to
// `function_pointer_type`.
// `wdk_sys::WDF_FUNCTION_TABLE` indexed by `table_index` and guarded by the type-safety of
// `pointer_type`. The passed arguments are also guaranteed to be of a compatible type due to
// `pointer_type`.
#[allow(unused_unsafe)]
#[allow(clippy::multiple_unsafe_ops_per_block)]
unsafe {
(wdf_function)(
wdk_sys::WdfDriverGlobals,
#function_arguments
#arguments
)
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion crates/wdk-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ categories = [
bindgen.workspace = true
wdk-build.workspace = true
thiserror = "1.0.55"
tracing-subscriber = "0.3.17"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
anyhow = "1.0.79"

[dependencies]
wdk-macros.workspace = true
Expand Down
50 changes: 48 additions & 2 deletions crates/wdk-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
};

use bindgen::CodegenConfig;
use tracing_subscriber::{filter::LevelFilter, EnvFilter};
use wdk_build::{BuilderExt, Config, ConfigError, DriverConfig, KMDFConfig};

// FIXME: feature gate the WDF version
Expand Down Expand Up @@ -64,8 +65,53 @@ fn generate_wdf(out_path: &Path, config: Config) -> Result<(), ConfigError> {
)
}

fn main() -> Result<(), ConfigError> {
tracing_subscriber::fmt::init();
fn main() -> anyhow::Result<()> {
let tracing_filter = EnvFilter::default()
// Show errors and warnings by default
.add_directive(LevelFilter::WARN.into())
// Silence various warnings originating from bindgen that are not currently actionable
// FIXME: this currently sets the minimum log level to error for the listed modules. It should actually be turning off logging (level=off) for specific warnings in these modules, but a bug in the tracing crate's filtering is preventing this from working as expected. See https://github.com/tokio-rs/tracing/issues/2843.
.add_directive("bindgen::codegen::helpers[{message}]=error".parse()?)
.add_directive("bindgen::codegen::struct_layout[{message}]=error".parse()?)
.add_directive("bindgen::ir::comp[{message}]=error".parse()?)
.add_directive("bindgen::ir::context[{message}]=error".parse()?)
.add_directive("bindgen::ir::ty[{message}]=error".parse()?)
.add_directive("bindgen::ir::var[{message}]=error".parse()?);

// Allow overriding tracing behaviour via `EnvFilter::DEFAULT_ENV` env var
let tracing_filter =
if let Ok(filter_directives_from_env_var) = env::var(EnvFilter::DEFAULT_ENV) {
// Append each directive from the env var to the filter
filter_directives_from_env_var.split(',').fold(
tracing_filter,
|tracing_filter, filter_directive| {
match filter_directive.parse() {
Ok(parsed_filter_directive) => {
tracing_filter.add_directive(parsed_filter_directive)
}
Err(parsing_error) => {
// Must use eprintln!() here as tracing is not yet initialized
eprintln!(
"Skipping filter directive, {}, which failed to be parsed from {} \
obtained from {} with the following error: {}",
filter_directive,
filter_directives_from_env_var,
EnvFilter::DEFAULT_ENV,
parsing_error
);
tracing_filter
}
}
},
)
} else {
tracing_filter
};

tracing_subscriber::fmt()
.pretty()
.with_env_filter(tracing_filter)
.init();

let config = Config {
// FIXME: this should be based off of Cargo feature version
Expand Down
Loading

0 comments on commit 5800055

Please sign in to comment.