Skip to content
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: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version = "0.1.27"
authors = ["Max Resch <resch.max@gmail.com>"]
license = "MIT"
repository = "https://github.com/BenjaminRi/winresource"
documentation= "https://docs.rs/winresource/*/winresource/"
documentation = "https://docs.rs/winresource/*/winresource/"

[lib]
path = "lib.rs"
Expand All @@ -15,9 +15,12 @@ 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]
# used for tests
winapi = { version = "0.3", features = [ "winnt" ] }
windows = { version = "0.62", features = ["Win32_System_SystemServices"] }
64 changes: 22 additions & 42 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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?
///
Expand Down Expand Up @@ -645,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");
Expand All @@ -659,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",
));
}
Expand Down Expand Up @@ -701,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\"",
)),
}
Expand Down Expand Up @@ -760,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);
Expand All @@ -774,26 +763,20 @@ impl WindowsResource {

/// Find a Windows SDK
fn get_sdk() -> io::Result<Vec<PathBuf>> {
// 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")
.arg("/reg:32")
.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<PathBuf> = Vec::new();
let mut lines: Vec<&str> = lines.lines().collect();
lines.reverse();
Expand Down Expand Up @@ -833,10 +816,7 @@ fn get_sdk() -> io::Result<Vec<PathBuf>> {
}
}
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)
Expand Down