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

feat: add skip_umdf_static_crt_check unstable option to prevent static crt linkage check #217

Merged
merged 7 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
25 changes: 20 additions & 5 deletions crates/wdk-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub enum ConfigError {

/// Error returned when the WDK version string does not match the expected
/// format
#[error("The WDK version string provided ({version}) was not in a valid format.")]
#[error("the WDK version string provided ({version}) was not in a valid format")]
WdkVersionStringFormatError {
/// The incorrect WDK version string.
version: String,
Expand All @@ -173,8 +173,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 \
WDK drivers. The recommended solution is to add the following snippiet to a `.config.toml` file: See 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 @@ -658,14 +664,23 @@ impl Config {
///
/// This function will return an error if:
/// * any of the required WDK paths do not exist
/// * the C runtime is not configured to be statically linked
/// * the C runtime is not configured to be statically linked for a
/// kernel-mode driver
///
/// # Panics
///
/// Panics if the invoked from outside a Cargo build environment
pub fn configure_binary_build(&self) -> Result<(), ConfigError> {
if !Self::is_crt_static_linked() {
return Err(ConfigError::StaticCrtNotEnabled);
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
14 changes: 7 additions & 7 deletions crates/wdk-build/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,55 +467,55 @@ mod tests {
assert_eq!(
format!("{}", get_wdk_version_number(test_string).err().unwrap()),
format!(
"The WDK version string provided ({}) was not in a valid format.",
"the WDK version string provided ({}) was not in a valid format",
test_string
)
);
let test_string = "10.0.12345.0.0";
assert_eq!(
format!("{}", get_wdk_version_number(test_string).err().unwrap()),
format!(
"The WDK version string provided ({}) was not in a valid format.",
"the WDK version string provided ({}) was not in a valid format",
test_string
)
);
let test_string = "10.0.12345.a";
assert_eq!(
format!("{}", get_wdk_version_number(test_string).err().unwrap()),
format!(
"The WDK version string provided ({}) was not in a valid format.",
"the WDK version string provided ({}) was not in a valid format",
test_string
)
);
let test_string = "10.0.12345";
assert_eq!(
format!("{}", get_wdk_version_number(test_string).err().unwrap()),
format!(
"The WDK version string provided ({}) was not in a valid format.",
"the WDK version string provided ({}) was not in a valid format",
test_string
)
);
let test_string = "10.0.1234!5.0";
assert_eq!(
format!("{}", get_wdk_version_number(test_string).err().unwrap()),
format!(
"The WDK version string provided ({}) was not in a valid format.",
"the WDK version string provided ({}) was not in a valid format",
test_string
)
);
let test_string = "Not a real version!";
assert_eq!(
format!("{}", get_wdk_version_number(test_string).err().unwrap()),
format!(
"The WDK version string provided ({}) was not in a valid format.",
"the WDK version string provided ({}) was not in a valid format",
test_string
)
);
let test_string = "";
assert_eq!(
format!("{}", get_wdk_version_number(test_string).err().unwrap()),
format!(
"The WDK version string provided ({}) was not in a valid format.",
"the WDK version string provided ({}) was not in a valid format",
test_string
)
);
Expand Down
1 change: 1 addition & 0 deletions examples/sample-kmdf-driver/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 examples/sample-umdf-driver/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 examples/sample-wdm-driver/Cargo.lock

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

Loading