Skip to content

Commit

Permalink
improve implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
wmmc88 committed Sep 13, 2024
1 parent 4c80b12 commit 131dfd4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
11 changes: 10 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
[build]
rustflags = ["-C", "target-feature=+crt-static"]
rustflags = [
"-C",
"target-feature=+crt-static",

# Enable unstable cfg options:
# "--cfg", "wdk_build_unstable",

# Unstable cfg options:
# "--cfg", "skip_umdf_static_crt_check",
]
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ bindgen = "0.69.4"
camino = "1.1.7"
cargo_metadata = "0.18.1"
cc = "1.1.0"
cfg-if = "1.0.0"
clap = "4.5.9"
clap-cargo = "0.14.0"
itertools = "0.13.0"
Expand Down
5 changes: 5 additions & 0 deletions crates/wdk-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ anyhow.workspace = true
bindgen.workspace = true
camino.workspace = true
cargo_metadata.workspace = true
cfg-if.workspace = true
clap = { workspace = true, features = ["derive"] }
clap-cargo.workspace = true
lazy_static.workspace = true
Expand All @@ -33,6 +34,10 @@ windows = { workspace = true, features = [
[dev-dependencies]
windows = { workspace = true, features = ["Win32_UI_Shell"] }

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = ["cfg(wdk_build_unstable)", "cfg(skip_umdf_static_crt_check)"]

# Cannot inherit workspace lints since overriding them is not supported yet: https://github.com/rust-lang/cargo/issues/13157
# [lints]
# workspace = true
Expand Down
21 changes: 18 additions & 3 deletions crates/wdk-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,14 @@ pub enum ConfigError {
/// Error returned when the c runtime is not configured to be statically
/// linked
#[error(
"the C runtime is not properly configured to be statically linked. This is required for building kernel mode WDK drivers. The recommended solution is to add the following snippiet to a `.config.toml` file: [build]\n rustflags = [\"-C\", \"target-feature=+crt-static\"]\n\nSee https://doc.rust-lang.org/reference/linkage.html#static-and-dynamic-c-runtimes for more ways to enable static crt linkage."
"the C runtime is not properly configured to be statically linked. This is required for building WDK drivers. The recommended solution is to add the following snippet to a \
`.config.toml` file:
[build]
rustflags = [\"-C\", \"target-feature=+crt-static\"]
\
See https://doc.rust-lang.org/reference/linkage.html#static-and-dynamic-c-runtimes for more ways \
to enable static crt linkage."
)]
StaticCrtNotEnabled,

Expand Down Expand Up @@ -665,8 +672,16 @@ impl Config {
///
/// Panics if the invoked from outside a Cargo build environment
pub fn configure_binary_build(&self) -> Result<(), ConfigError> {
if !Self::is_crt_static_linked() && matches!(self.driver_config, DriverConfig::Umdf(_)) {
return Err(ConfigError::StaticCrtNotEnabled);
if !Self::is_crt_static_linked() {
cfg_if::cfg_if! {
if #[cfg(all(wdk_build_unstable, skip_umdf_static_crt_check))] {
if !matches!(self.driver_config, DriverConfig::Umdf(_)) {
return Err(ConfigError::StaticCrtNotEnabled);
}
} else {
return Err(ConfigError::StaticCrtNotEnabled);
}
};
}

let library_paths: Vec<PathBuf> = self.get_library_paths()?;
Expand Down
1 change: 1 addition & 0 deletions examples/sample-umdf-driver/Cargo.lock

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

0 comments on commit 131dfd4

Please sign in to comment.