diff --git a/.changes/codegen-check-target.md b/.changes/codegen-check-target.md new file mode 100644 index 000000000..3156b592a --- /dev/null +++ b/.changes/codegen-check-target.md @@ -0,0 +1,5 @@ +--- +"tauri-codegen": patch +--- + +Use `TARGET` environment variable for code generation inside build scripts. diff --git a/core/tauri-codegen/src/context.rs b/core/tauri-codegen/src/context.rs index 18b5d3680..d5e5cd578 100644 --- a/core/tauri-codegen/src/context.rs +++ b/core/tauri-codegen/src/context.rs @@ -28,6 +28,7 @@ pub struct ContextData { fn map_core_assets( options: &AssetOptions, + target: Target, ) -> impl Fn(&AssetKey, &Path, &mut Vec, &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")] - ::tauri_utils::html::inject_csp_token(&mut document); + 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 { let ContextData { @@ -115,6 +127,34 @@ pub fn context_codegen(data: ContextData) -> Result Result unimplemented!(), }, @@ -172,7 +212,7 @@ pub fn context_codegen(data: ContextData) -> Result>(), &options, - map_core_assets(&options), + map_core_assets(&options, target), )?, _ => unimplemented!(), }; @@ -189,18 +229,28 @@ pub fn context_codegen(data: ContextData) -> Result Result Result Result>( Ok(icon) } -#[cfg(target_os = "macos")] fn raw_icon>(out_dir: &Path, path: P) -> Result { 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 bool>( config: &Config, config_parent: &Path,