From 93bc6d604b84b7503b1052f68451609d518b8ee9 Mon Sep 17 00:00:00 2001 From: dtzxporter Date: Fri, 28 Nov 2025 19:07:03 -0500 Subject: [PATCH 1/3] Limit toml features. --- Cargo.toml | 2 +- lib.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6c29934..0c275b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ path = "lib.rs" default = ["toml"] [dependencies] -toml = { version = "0.9", optional = true } +toml = { version = "0.9", optional = true, default-features = false, features = ["std", "parse", "serde"] } version_check = "0.9" [dev-dependencies] diff --git a/lib.rs b/lib.rs index 6c379b5..9941a5d 100644 --- a/lib.rs +++ b/lib.rs @@ -774,7 +774,6 @@ impl WindowsResource { /// Find a Windows SDK fn get_sdk() -> io::Result> { - // use the reg command, so we don't need a winapi dependency let output = process::Command::new("reg") .arg("query") .arg(r"HKLM\SOFTWARE\Microsoft\Windows Kits\Installed Roots") From f552f0f11d9e054510a30b9febb205b41ea5ce9a Mon Sep 17 00:00:00 2001 From: dtzxporter Date: Fri, 28 Nov 2025 22:00:02 -0500 Subject: [PATCH 2/3] Update deps and documentation. --- Cargo.toml | 11 +++++++---- lib.rs | 27 ++++++++++++--------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0c275b5..67558fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ version = "0.1.27" authors = ["Max Resch "] license = "MIT" repository = "https://github.com/BenjaminRi/winresource" -documentation= "https://docs.rs/winresource/*/winresource/" +documentation = "https://docs.rs/winresource/*/winresource/" [lib] path = "lib.rs" @@ -15,9 +15,12 @@ path = "lib.rs" default = ["toml"] [dependencies] -toml = { version = "0.9", optional = true, default-features = false, features = ["std", "parse", "serde"] } +toml = { version = "0.9", optional = true, default-features = false, features = [ + "std", + "parse", + "serde", +] } version_check = "0.9" [dev-dependencies] -# used for tests -winapi = { version = "0.3", features = [ "winnt" ] } +windows = { version = "0.62", features = ["Win32_System_SystemServices"] } diff --git a/lib.rs b/lib.rs index 9941a5d..bf04505 100644 --- a/lib.rs +++ b/lib.rs @@ -322,26 +322,26 @@ impl WindowsResource { /// # Example /// /// ```no_run - /// extern crate winapi; + /// extern crate windows; /// extern crate winresource; /// # use std::io; /// fn main() { /// if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" { + /// let primary = windows::Win32::System::SystemServices::LANG_ENGLISH; + /// let secondary = windows::Win32::System::SystemServices::SUBLANG_ENGLISH_US; + /// let lang_id = ((secondary as u16) << 10) | (primary as u16); + /// /// let mut res = winresource::WindowsResource::new(); - /// # res.set_output_directory("."); - /// res.set_language(winapi::um::winnt::MAKELANGID( - /// winapi::um::winnt::LANG_ENGLISH, - /// winapi::um::winnt::SUBLANG_ENGLISH_US - /// )); + /// res.set_output_directory("."); + /// res.set_language(lang_id); /// res.compile().unwrap(); /// } /// } /// ``` - /// For possible values look at the `winapi::um::winnt` constants, specifically those + /// For possible values look at the `windows::Win32::System::SystemServices` constants, specifically those /// starting with `LANG_` and `SUBLANG_`. /// - /// [`MAKELANGID`]: https://docs.rs/winapi/0.3/x86_64-pc-windows-msvc/winapi/um/winnt/fn.MAKELANGID.html - /// [`winapi::um::winnt`]: https://docs.rs/winapi/0.3/x86_64-pc-windows-msvc/winapi/um/winnt/index.html#constants + /// [`windows::Win32::System::SystemServices`]: https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/System/SystemServices/index.html /// /// # Table /// Sometimes it is just simpler to specify the numeric constant directly @@ -397,7 +397,7 @@ impl WindowsResource { /// When the name ID is an integer, the icon can be loaded at runtime with /// /// ```ignore - /// LoadIconW(h_instance, MAKEINTRESOURCEW(name_id_as_integer)) + /// LoadIconW(h_instance, PWSTR::from_raw(name_id_as_integer as _)) /// ``` /// /// Otherwise, it can be loaded with @@ -407,11 +407,8 @@ impl WindowsResource { /// ``` /// /// Where `h_instance` is the module handle of the current executable - /// ([`GetModuleHandleW`](https://docs.rs/winapi/0.3.8/winapi/um/libloaderapi/fn.GetModuleHandleW.html)`(null())`), - /// [`LoadIconW`](https://docs.rs/winapi/0.3.8/winapi/um/winuser/fn.LoadIconW.html) - /// and - /// [`MAKEINTRESOURCEW`](https://docs.rs/winapi/0.3.8/winapi/um/winuser/fn.MAKEINTRESOURCEW.html) - /// are defined in winapi. + /// ([`GetModuleHandleW`](https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/System/LibraryLoader/fn.GetModuleHandleW.html)`(null())`), + /// see [`LoadIconW`](https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/UI/WindowsAndMessaging/fn.LoadIconW.html) for more details. /// /// ## Multiple Icons, Which One is Application Icon? /// From 1239b7b59e9c1931ac6fa3b16c6ff05c4b7a0791 Mon Sep 17 00:00:00 2001 From: dtzxporter Date: Fri, 28 Nov 2025 22:02:30 -0500 Subject: [PATCH 3/3] Fix clippy warnings. --- lib.rs | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/lib.rs b/lib.rs index bf04505..5fa2048 100644 --- a/lib.rs +++ b/lib.rs @@ -642,10 +642,7 @@ impl WindowsResource { .arg(format!("{}", output.display())) .status()?; if !status.success() { - return Err(io::Error::new( - io::ErrorKind::Other, - "Could not compile resource file", - )); + return Err(io::Error::other("Could not compile resource file")); } let libname = PathBuf::from(output_dir).join("libresource.a"); @@ -656,8 +653,7 @@ impl WindowsResource { .arg(format!("{}", output.display())) .status()?; if !status.success() { - return Err(io::Error::new( - io::ErrorKind::Other, + return Err(io::Error::other( "Could not create static library for resource file", )); } @@ -698,8 +694,7 @@ impl WindowsResource { match target_env.as_str() { "gnu" => self.compile_with_toolkit_gnu(rc.as_str(), &self.output_directory), "msvc" => self.compile_with_toolkit_msvc(rc.as_str(), &self.output_directory), - _ => Err(io::Error::new( - io::ErrorKind::Other, + _ => Err(io::Error::other( "Can only compile resource file when target_env is \"gnu\" or \"msvc\"", )), } @@ -757,10 +752,7 @@ impl WindowsResource { String::from_utf8_lossy(&status.stderr) ); if !status.status.success() { - return Err(io::Error::new( - io::ErrorKind::Other, - "Could not compile resource file", - )); + return Err(io::Error::other("Could not compile resource file")); } println!("cargo:rustc-link-search=native={}", output_dir); @@ -778,18 +770,13 @@ fn get_sdk() -> io::Result> { .output()?; if !output.status.success() { - return Err(io::Error::new( - io::ErrorKind::Other, - format!( - "Querying the registry failed with error message:\n{}", - String::from_utf8(output.stderr) - .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))? - ), - )); + return Err(io::Error::other(format!( + "Querying the registry failed with error message:\n{}", + String::from_utf8(output.stderr).map_err(|e| io::Error::other(e.to_string()))? + ))); } - let lines = String::from_utf8(output.stdout) - .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))?; + let lines = String::from_utf8(output.stdout).map_err(|e| io::Error::other(e.to_string()))?; let mut kits: Vec = Vec::new(); let mut lines: Vec<&str> = lines.lines().collect(); lines.reverse(); @@ -829,10 +816,7 @@ fn get_sdk() -> io::Result> { } } if kits.is_empty() { - return Err(io::Error::new( - io::ErrorKind::Other, - "Can not find Windows SDK", - )); + return Err(io::Error::other("Can not find Windows SDK")); } Ok(kits)