44// SPDX-License-Identifier: MIT
55
66mod category;
7- #[ cfg( any( target_os = "linux" , target_os = "windows" ) ) ]
87mod kmp;
98#[ cfg( target_os = "linux" ) ]
109mod linux;
@@ -17,26 +16,16 @@ mod windows;
1716
1817use tauri_utils:: { display_path, platform:: Target as TargetPlatform } ;
1918
20- #[ cfg( any( target_os = "linux" , target_os = "windows" ) ) ]
2119const BUNDLE_VAR_TOKEN : & [ u8 ] = b"__TAURI_BUNDLE_TYPE_VAR_UNK" ;
2220/// Patch a binary with bundle type information
23- #[ cfg( any( target_os = "linux" , target_os = "windows" ) ) ]
2421fn patch_binary ( binary : & PathBuf , package_type : & PackageType ) -> crate :: Result < ( ) > {
25- log:: info!(
26- "Patching {} with bundle type information: {}" ,
27- display_path( binary) ,
28- package_type. short_name( )
29- ) ;
30-
31- let mut file_data = std:: fs:: read ( binary) . expect ( "Could not read binary file." ) ;
32-
33- let bundle_var_index =
34- kmp:: index_of ( BUNDLE_VAR_TOKEN , & file_data) . ok_or ( crate :: Error :: MissingBundleTypeVar ) ?;
3522 #[ cfg( target_os = "linux" ) ]
3623 let bundle_type = match package_type {
3724 crate :: PackageType :: Deb => b"__TAURI_BUNDLE_TYPE_VAR_DEB" ,
3825 crate :: PackageType :: Rpm => b"__TAURI_BUNDLE_TYPE_VAR_RPM" ,
3926 crate :: PackageType :: AppImage => b"__TAURI_BUNDLE_TYPE_VAR_APP" ,
27+ // NSIS installers can be built in linux using cargo-xwin
28+ crate :: PackageType :: Nsis => b"__TAURI_BUNDLE_TYPE_VAR_NSS" ,
4029 _ => {
4130 return Err ( crate :: Error :: InvalidPackageType (
4231 package_type. short_name ( ) . to_owned ( ) ,
@@ -55,7 +44,31 @@ fn patch_binary(binary: &PathBuf, package_type: &PackageType) -> crate::Result<(
5544 ) )
5645 }
5746 } ;
47+ #[ cfg( target_os = "macos" ) ]
48+ let bundle_type = match package_type {
49+ // NSIS installers can be built in macOS using cargo-xwin
50+ crate :: PackageType :: Nsis => b"__TAURI_BUNDLE_TYPE_VAR_NSS" ,
51+ crate :: PackageType :: MacOsBundle | crate :: PackageType :: Dmg => {
52+ // skip patching for macOS-native bundles
53+ return Ok ( ( ) ) ;
54+ }
55+ _ => {
56+ return Err ( crate :: Error :: InvalidPackageType (
57+ package_type. short_name ( ) . to_owned ( ) ,
58+ "macOS" . to_owned ( ) ,
59+ ) )
60+ }
61+ } ;
5862
63+ log:: info!(
64+ "Patching {} with bundle type information: {}" ,
65+ display_path( binary) ,
66+ package_type. short_name( )
67+ ) ;
68+
69+ let mut file_data = std:: fs:: read ( binary) . expect ( "Could not read binary file." ) ;
70+ let bundle_var_index =
71+ kmp:: index_of ( BUNDLE_VAR_TOKEN , & file_data) . ok_or ( crate :: Error :: MissingBundleTypeVar ) ?;
5972 file_data[ bundle_var_index..bundle_var_index + BUNDLE_VAR_TOKEN . len ( ) ]
6073 . copy_from_slice ( bundle_type) ;
6174
@@ -133,7 +146,6 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<Bundle>> {
133146 continue ;
134147 }
135148
136- #[ cfg( any( target_os = "linux" , target_os = "windows" ) ) ]
137149 if let Err ( e) = patch_binary ( & main_binary_path, package_type) {
138150 log:: warn!( "Failed to add bundler type to the binary: {e}. Updater plugin may not be able to update this package. This shouldn't normally happen, please report it to https://github.com/tauri-apps/tauri/issues" ) ;
139151 }
@@ -163,7 +175,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<Bundle>> {
163175
164176 #[ cfg( target_os = "windows" ) ]
165177 PackageType :: WindowsMsi => windows:: msi:: bundle_project ( settings, false ) ?,
166- // note: don't restrict to windows as NSIS installers can be built in linux using cargo-xwin
178+ // don't restrict to windows as NSIS installers can be built in linux+macOS using cargo-xwin
167179 PackageType :: Nsis => windows:: nsis:: bundle_project ( settings, false ) ?,
168180
169181 #[ cfg( target_os = "linux" ) ]
0 commit comments