This commit is contained in:
Rohit Singh 2026-02-02 20:15:39 +01:00 committed by GitHub
commit c6b64ddab3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 6 deletions

View File

@ -0,0 +1,12 @@
---
"tauri-utils": patch:enhance
---
Uses variables for targeting different operating systems.
Fixes: [#8501](https://github.com/tauri-apps/tauri/issues/8501)
{{target}} for os ("windows", "linux", "darwin")
{{arch}} for arch ("i686", "x86_64")
eg: before parse: `"../binaries/test/{{target}}/{{arch}}/*": "resources/test/"`
after parse: `"../binaries/test/darwin/aarch64/*": "resources/test/"`

View File

@ -9,7 +9,7 @@ use std::{
use walkdir::WalkDir;
use crate::platform::Target as TargetPlatform;
use crate::platform::{target_triple, Target as TargetPlatform};
/// Given a path (absolute or relative) to a resource file, returns the
/// relative path from the bundle resources directory where that resource
@ -42,6 +42,20 @@ fn normalize(path: &Path) -> PathBuf {
dest
}
fn replace_pattern_with_target(pattern: &str) -> String {
let target_triple = target_triple().unwrap();
// log::info!("USING LOCAL replace_pattern_with_target: {}", target_triple);
let parts: Vec<&str> = target_triple.split('-').collect();
let arch = parts[0];
let target = parts[2];
pattern
.replace("{{arch}}", arch)
.replace("{{target}}", &target)
}
/// Parses the external binaries to bundle, adding the target triple suffix to each of them.
pub fn external_binaries(
external_binaries: &[String],
@ -225,16 +239,20 @@ impl ResourcePathsIter<'_> {
self.current_pattern = None;
let pattern = match &mut self.pattern_iter {
PatternIter::Slice(iter) => iter.next()?,
PatternIter::Slice(iter) => {
let pattern = iter.next()?;
replace_pattern_with_target(pattern)
}
PatternIter::Map(iter) => {
let (pattern, dest) = iter.next()?;
self.current_pattern = Some((pattern.clone(), resource_relpath(Path::new(dest))));
pattern
let resolved_pattern = replace_pattern_with_target(pattern);
self.current_pattern = Some((resolved_pattern.clone(), resource_relpath(Path::new(dest))));
resolved_pattern
}
};
if pattern.contains('*') {
self.glob_iter = match glob::glob(pattern) {
self.glob_iter = match glob::glob(&pattern) {
Ok(glob) => Some(glob),
Err(error) => return Some(Err(error.into())),
};
@ -247,7 +265,7 @@ impl ResourcePathsIter<'_> {
}
}
self.next_current_path(normalize(Path::new(pattern)))
self.next_current_path(normalize(Path::new(&pattern)))
}
}
@ -342,6 +360,9 @@ mod tests {
"src/script.js",
"src/dir/another-dir/file1.txt",
"src/dir/another-dir2/file2.txt",
"src/dir/{{target}}/another-dir3/file1.txt",
"src/dir/{{target}}/another-dir3/{{arch}}/file2.txt",
"src/dir/another-dir3/{{arch}}/file3.txt",
];
for path in paths {