mirror of
https://github.com/tauri-apps/tauri.git
synced 2025-01-05 09:52:50 +03:00
Merge remote-tracking branch 'origin/dev' into next
This commit is contained in:
commit
11d50e8474
5
.changes/codegen-check-target.md
Normal file
5
.changes/codegen-check-target.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri-codegen": patch
|
||||
---
|
||||
|
||||
Use `TARGET` environment variable for code generation inside build scripts.
|
@ -28,6 +28,7 @@ pub struct ContextData {
|
||||
|
||||
fn map_core_assets(
|
||||
options: &AssetOptions,
|
||||
target: Target,
|
||||
) -> impl Fn(&AssetKey, &Path, &mut Vec<u8>, &mut CspHashes) -> Result<(), EmbeddedAssetsError> {
|
||||
#[cfg(feature = "isolation")]
|
||||
let pattern = tauri_utils::html::PatternObject::from(&options.pattern);
|
||||
@ -40,8 +41,9 @@ fn map_core_assets(
|
||||
|
||||
#[allow(clippy::collapsible_if)]
|
||||
if csp {
|
||||
#[cfg(target_os = "linux")]
|
||||
if target == Target::Linux {
|
||||
::tauri_utils::html::inject_csp_token(&mut document);
|
||||
}
|
||||
|
||||
inject_nonce_token(&mut document, &dangerous_disable_asset_csp_modification);
|
||||
|
||||
@ -106,6 +108,16 @@ fn map_isolation(
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
enum Target {
|
||||
Linux,
|
||||
Windows,
|
||||
Darwin,
|
||||
Android,
|
||||
// iOS.
|
||||
Ios,
|
||||
}
|
||||
|
||||
/// Build a `tauri::Context` for including in application code.
|
||||
pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsError> {
|
||||
let ContextData {
|
||||
@ -115,6 +127,34 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
root,
|
||||
} = data;
|
||||
|
||||
let target = if let Ok(target) = std::env::var("TARGET") {
|
||||
if target.contains("unknown-linux") {
|
||||
Target::Linux
|
||||
} else if target.contains("pc-windows") {
|
||||
Target::Windows
|
||||
} else if target.contains("apple-darwin") {
|
||||
Target::Darwin
|
||||
} else if target.contains("android") {
|
||||
Target::Android
|
||||
} else if target.contains("apple-ios") {
|
||||
Target::Ios
|
||||
} else {
|
||||
panic!("unknown codegen target {}", target);
|
||||
}
|
||||
} else if cfg!(target_os = "linux") {
|
||||
Target::Linux
|
||||
} else if cfg!(windows) {
|
||||
Target::Windows
|
||||
} else if cfg!(target_os = "macos") {
|
||||
Target::Darwin
|
||||
} else if cfg!(target_os = "android") {
|
||||
Target::Android
|
||||
} else if cfg!(target_os = "ios") {
|
||||
Target::Ios
|
||||
} else {
|
||||
panic!("unknown codegen target");
|
||||
};
|
||||
|
||||
let mut options = AssetOptions::new(config.tauri.pattern.clone())
|
||||
.freeze_prototype(config.tauri.security.freeze_prototype)
|
||||
.dangerous_disable_asset_csp_modification(
|
||||
@ -162,7 +202,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
path
|
||||
)
|
||||
}
|
||||
EmbeddedAssets::new(assets_path, &options, map_core_assets(&options))?
|
||||
EmbeddedAssets::new(assets_path, &options, map_core_assets(&options, target))?
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
},
|
||||
@ -172,7 +212,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
.map(|p| config_parent.join(p))
|
||||
.collect::<Vec<_>>(),
|
||||
&options,
|
||||
map_core_assets(&options),
|
||||
map_core_assets(&options, target),
|
||||
)?,
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
@ -189,9 +229,9 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
out_dir
|
||||
};
|
||||
|
||||
// handle default window icons for Windows targets
|
||||
#[cfg(windows)]
|
||||
let default_window_icon = {
|
||||
if target == Target::Windows {
|
||||
// handle default window icons for Windows targets
|
||||
let icon_path = find_icon(
|
||||
&config,
|
||||
&config_parent,
|
||||
@ -209,9 +249,8 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
);
|
||||
png_icon(&root, &out_dir, icon_path)?
|
||||
}
|
||||
};
|
||||
#[cfg(target_os = "linux")]
|
||||
let default_window_icon = {
|
||||
} else if target == Target::Linux {
|
||||
// handle default window icons for Linux targets
|
||||
let icon_path = find_icon(
|
||||
&config,
|
||||
&config_parent,
|
||||
@ -219,12 +258,12 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
"icons/icon.png",
|
||||
);
|
||||
png_icon(&root, &out_dir, icon_path)?
|
||||
} else {
|
||||
quote!(None)
|
||||
}
|
||||
};
|
||||
#[cfg(not(any(windows, target_os = "linux")))]
|
||||
let default_window_icon = quote!(None);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let app_icon = if dev {
|
||||
let app_icon = if target == Target::Darwin && dev {
|
||||
let mut icon_path = find_icon(
|
||||
&config,
|
||||
&config_parent,
|
||||
@ -243,8 +282,6 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
} else {
|
||||
quote!(None)
|
||||
};
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let app_icon = quote!(None);
|
||||
|
||||
let package_name = if let Some(product_name) = &config.package.product_name {
|
||||
quote!(#product_name.to_string())
|
||||
@ -283,8 +320,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let info_plist = {
|
||||
if dev {
|
||||
let info_plist = if target == Target::Darwin && dev {
|
||||
let info_plist_path = config_parent.join("Info.plist");
|
||||
let mut info_plist = if info_plist_path.exists() {
|
||||
plist::Value::from_file(&info_plist_path)
|
||||
@ -314,12 +350,10 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
|
||||
let info_plist_path = out_path.display().to_string();
|
||||
quote!({
|
||||
#[cfg(desktop)]
|
||||
tauri::embed_plist::embed_info_plist!(#info_plist_path);
|
||||
})
|
||||
} else {
|
||||
quote!(())
|
||||
}
|
||||
};
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
let info_plist = quote!(());
|
||||
@ -443,7 +477,6 @@ fn ico_icon<P: AsRef<Path>>(
|
||||
Ok(icon)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
fn raw_icon<P: AsRef<Path>>(out_dir: &Path, path: P) -> Result<TokenStream, EmbeddedAssetsError> {
|
||||
let path = path.as_ref();
|
||||
let bytes = std::fs::read(&path)
|
||||
@ -508,7 +541,6 @@ fn write_if_changed(out_path: &Path, data: &[u8]) -> std::io::Result<()> {
|
||||
out_file.write_all(data)
|
||||
}
|
||||
|
||||
#[cfg(any(windows, target_os = "macos", target_os = "linux"))]
|
||||
fn find_icon<F: Fn(&&String) -> bool>(
|
||||
config: &Config,
|
||||
config_parent: &Path,
|
||||
|
Loading…
Reference in New Issue
Block a user