Skip to content

Commit

Permalink
fix(tauri-build): allow user to specify win sdk path (fix: #2871) (#2893
Browse files Browse the repository at this point in the history
)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
SyntaxRules and lucasfernog committed Nov 16, 2021
1 parent b9e9670 commit 59b6ee8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/build-specify-win-sdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-build": patch
---

Allow user to specify windows sdk path in build.rs.
21 changes: 21 additions & 0 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ pub use codegen::context::CodegenContext;
#[derive(Debug)]
pub struct WindowsAttributes {
window_icon_path: PathBuf,
/// The path to the sdk location. This can be a absolute or relative path. If not supplied
/// this defaults to whatever `winres` crate determines is the best. See the
/// [winres documentation](https://docs.rs/winres/*/winres/struct.WindowsResource.html#method.set_toolkit_path)
sdk_dir: Option<PathBuf>,
}

impl Default for WindowsAttributes {
fn default() -> Self {
Self {
window_icon_path: PathBuf::from("icons/icon.ico"),
sdk_dir: None,
}
}
}
Expand All @@ -42,6 +47,13 @@ impl WindowsAttributes {
self.window_icon_path = window_icon_path.as_ref().into();
self
}

/// Sets the sdk dir for windows. Currently only used on Windows. This must be a vaild UTF-8
/// path. Defaults to whatever the `winres` crate determines is best.
pub fn sdk_dir<P: AsRef<Path>>(mut self, sdk_dir: P) -> Self {
self.sdk_dir = Some(sdk_dir.as_ref().into());
self
}
}

/// The attributes used on the build.
Expand Down Expand Up @@ -112,6 +124,15 @@ pub fn try_build(attributes: Attributes) -> Result<()> {

if attributes.windows_attributes.window_icon_path.exists() {
let mut res = WindowsResource::new();
if let Some(sdk_dir) = &attributes.windows_attributes.sdk_dir {
if let Some(sdk_dir_str) = sdk_dir.to_str() {
res.set_toolkit_path(sdk_dir_str);
} else {
return Err(anyhow!(
"sdk_dir path is not valid; only UTF-8 characters are allowed"
));
}
}
if let Some(version) = &config.package.version {
res.set("FileVersion", version);
res.set("ProductVersion", version);
Expand Down

0 comments on commit 59b6ee8

Please sign in to comment.