소스 검색

fix(tauri-build): allow user to specify win sdk path (fix: #2871) (#2893)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Devyn S 3 년 전
부모
커밋
59b6ee8793
2개의 변경된 파일26개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      .changes/build-specify-win-sdk.md
  2. 21 0
      core/tauri-build/src/lib.rs

+ 5 - 0
.changes/build-specify-win-sdk.md

@@ -0,0 +1,5 @@
+---
+"tauri-build": patch
+---
+
+Allow user to specify windows sdk path in build.rs.

+ 21 - 0
core/tauri-build/src/lib.rs

@@ -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,
     }
   }
 }
@@ -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.
@@ -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);