-
Notifications
You must be signed in to change notification settings - Fork 72
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
refactor: Remove lazy static instances #250
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 15 out of 17 changed files in this pull request and generated no suggestions.
Files not reviewed (2)
- crates/wdk-sys/Cargo.toml: Evaluated as low risk
- crates/wdk-build/Cargo.toml: Evaluated as low risk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 29 out of 44 changed files in this pull request and generated 1 comment.
Files not reviewed (15)
- tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_tuple_struct_shadowing.expanded.rs: Evaluated as low risk
- tests/wdk-macros-tests/tests/outputs/beta/macrotest/bug_unused_imports.expanded.rs: Evaluated as low risk
- crates/wdk-sys/src/lib.rs: Evaluated as low risk
- crates/wdk-build/Cargo.toml: Evaluated as low risk
- Cargo.toml: Evaluated as low risk
- crates/wdk-build/src/lib.rs: Evaluated as low risk
- tests/wdk-macros-tests/Cargo.toml: Evaluated as low risk
- crates/wdk-sys/src/wdf.rs: Evaluated as low risk
- tests/wdk-macros-tests/src/lib.rs: Evaluated as low risk
- crates/wdk-sys/Cargo.toml: Evaluated as low risk
- crates/wdk-sys/build.rs: Evaluated as low risk
- tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_verifier_dbg_break_point.expanded.rs: Evaluated as low risk
- tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_spin_lock_acquire.expanded.rs: Evaluated as low risk
- tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_request_retrieve_output_buffer.expanded.rs: Evaluated as low risk
- tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_tuple_struct_shadowing.expanded.rs: Evaluated as low risk
Comments suppressed due to low confidence (1)
tests/wdk-macros-tests/tests/outputs/beta/macrotest/wdf_device_create.expanded.rs:30
- [nitpick] The error message is too verbose. Consider simplifying it to: 'assertion failed: invalid function count size'.
::core::panicking::panic("assertion failed: isize::try_from(wdf_function_count *\n core::mem::size_of::<wdk_sys::WDFFUNC>()).is_ok()")
tests/wdk-macros-tests/tests/outputs/nightly/macrotest/bug_unused_imports.expanded.rs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really dislike adding a public api for the function count, since no such public api exists in the WDK, and i'd like for the sys crate to be purely the wdk apis. Ideally, the proc_macro should generate code that either dereferences the symbol OR uses the enum by conditionally compiling for the relevant cases. This essentially means turning the is_wdf_function_count_generated
expression into a CFG.
This is currently not possible since:
- we do not expose WDF version number in
EXPORTED_CFG_SETTINGS
inemit_cfg_settings
- it would be very tedious and manual to cfg over all the supported values, since there is no rust cfg equivalent to
UMDF_VERSION_MINOR > 1234
. We would need to figure out a way to write a cfg in this fashion (is this even possible?)
I think those things are out of the scope of this PR, and the best we can do right now is hide the get_wdf_function_count
api from the user and make it clear that it is subject to future removal once we've figured out the above.
@@ -5,8 +5,6 @@ | |||
|
|||
#![no_std] | |||
|
|||
#[cfg(any(driver_model__driver_type = "KMDF", driver_model__driver_type = "UMDF"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we try to follow conventional commits spec. Since you're removing a public item exported from the wdk-sys crate, this is considered a breaking change and the commit should indicate it via !
. (PR title ends up being the message of the squashed commit)
@@ -427,7 +397,7 @@ fn main() -> anyhow::Result<()> { | |||
.expect("Scoped Thread should spawn successfully"), | |||
); | |||
|
|||
info_span!("wdf_function_table.rs generation").in_scope(|| { | |||
info_span!("wdf_function_count.rs generation").in_scope(|| { | |||
generate_wdf_function_table(&out_path, &config)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generate_wdf_function_table(&out_path, &config)?; | |
generate_wdf_function_count(&out_path, &config)?; |
@@ -259,15 +240,14 @@ fn generate_wdf(out_path: &Path, config: &Config) -> Result<(), ConfigError> { | |||
} | |||
} | |||
|
|||
/// Generates a `wdf_function_table.rs` file in `OUT_DIR` which contains the | |||
/// definition of `WDF_FUNCTION_TABLE`. This is required to be generated here | |||
/// Generates a `wdf_function_count.rs` file in `OUT_DIR` which contains the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this comment is no longer accurate since theres no WDF_FUNCTION_COUNT
generated
|
||
static WDF_FUNCTION_COUNT_FUNCTION_TEMPLATE: LazyLock<String> = LazyLock::new(|| { | ||
format!( | ||
r"/// function to access the value of the number of functions in the WDF function table. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r"/// function to access the value of the number of functions in the WDF function table. | |
r"/// Returns the number of functions available in the WDF function table. |
nit: style so that the doccomment matches typical rust style (and other rustdoc comments in this repo)
); | ||
static ref CALL_UNSAFE_WDF_BINDING_TEMPLATE: String = format!( | ||
const WDF_FUNCTION_COUNT_PLACEHOLDER: &str = | ||
"<PLACEHOLDER FOR EVALUATION CONTAINING WDF_FUNCTION_COUNT VALUE"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"<PLACEHOLDER FOR EVALUATION CONTAINING WDF_FUNCTION_COUNT VALUE"; | |
"<PLACEHOLDER FOR EXPRESSION FOR NUMBER OF WDF FUNCTIONS IN `wdk_sys::WdfFunctions`"; |
const WDF_FUNCTION_COUNT_PLACEHOLDER: &str = | ||
"<PLACEHOLDER FOR EVALUATION CONTAINING WDF_FUNCTION_COUNT VALUE"; | ||
|
||
const WDF_FUNCTION_COUNT_DECLARATION_EXTERNAL_SYMBOL: &str = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-add the removed safety comment
For more on #2, see https://users.rust-lang.org/t/cfg-w-arbitrary-expressions/109371 I think it may be possible to write a new attribute macro that expands into a cfg |
Replaced lazy static instances with std::sync::LazyLock in following locations:
Replaced lazy static instances with custom FunctionTable struct in generated code in
crates/wdk-sys/build.rs
Breaking Changes
wdf_function_table.rs
from generated code of WDK_BUILD. Users should access the function table instead via pointer atwdk_sys::WdfFunctions
, and checking bounds viawdk_sys::wdf::get_wdf_function_count()
which is generated inwdf_function_count.rs
sync::LazyLock
as introduced in Rust 1.83closes #192