summaryrefslogtreecommitdiff
path: root/crates/windows-kernel-build/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/windows-kernel-build/src')
-rw-r--r--crates/windows-kernel-build/src/lib.rs32
1 files changed, 26 insertions, 6 deletions
diff --git a/crates/windows-kernel-build/src/lib.rs b/crates/windows-kernel-build/src/lib.rs
index f2f4680..29ca151 100644
--- a/crates/windows-kernel-build/src/lib.rs
+++ b/crates/windows-kernel-build/src/lib.rs
@@ -1,3 +1,12 @@
+#![deny(
+ warnings,
+ nonstandard_style,
+ unused,
+ future_incompatible,
+ rust_2018_idioms
+)]
+#![deny(clippy::all, clippy::nursery, clippy::pedantic)]
+
use std::path::PathBuf;
use thiserror::Error;
@@ -18,6 +27,9 @@ pub enum DirectoryType {
/// Retrieves the path to the Windows Kits directory. The default should be
/// `C:\Program Files (x86)\Windows Kits\10`.
+///
+/// # Errors
+/// if a key cannot be found.
pub fn get_windows_kits_dir() -> Result<PathBuf, Error> {
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
let key = r"SOFTWARE\Microsoft\Windows Kits\Installed Roots";
@@ -28,7 +40,10 @@ pub fn get_windows_kits_dir() -> Result<PathBuf, Error> {
/// Retrieves the path to the kernel mode libraries. The path may look something
/// like: `C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\km`.
-pub fn get_km_dir(dir_type: DirectoryType) -> Result<PathBuf, Error> {
+///
+/// # Errors
+/// if a directory cannot be found.
+pub fn get_km_dir(dir_type: &DirectoryType) -> Result<PathBuf, Error> {
// We first append lib to the path and read the directory..
let dir = get_windows_kits_dir()?
.join(match dir_type {
@@ -40,27 +55,32 @@ pub fn get_km_dir(dir_type: DirectoryType) -> Result<PathBuf, Error> {
// In the lib directory we may have one or more directories named after the
// version of Windows, we will be looking for the highest version number.
let dir = dir
- .filter_map(|dir| dir.ok())
+ .filter_map(std::result::Result::ok)
.map(|dir| dir.path())
.filter(|dir| {
dir
.components()
.last()
.and_then(|c| c.as_os_str().to_str())
- .map(|c| c.starts_with("10.") && dir.join("km").is_dir())
- .unwrap_or(false)
+ .map_or(false, |c| c.starts_with("10.") && dir.join("km").is_dir())
})
.max()
- // .ok_or_else(|| Error::DirectoryNotFound)?;
.ok_or(Error::DirectoryNotFound)?;
// Finally append km to the path to get the path to the kernel mode libraries.
Ok(dir.join("km"))
}
+/// # Panics
+/// if the `target` is currently not supported.
+///
+/// # Errors
+/// - if the kernel libraries cannot be found
+/// - if the `TARGET` environment variable is not present
+/// - if the link path cannot be converted to a &str
pub fn build() -> Result<(), Error> {
// Get the path to the kernel libraries.
- let dir = get_km_dir(DirectoryType::Library).unwrap();
+ let dir = get_km_dir(&DirectoryType::Library).unwrap();
// Append the architecture based on our target.
let target = std::env::var("TARGET").unwrap();