@@ -339,6 +339,8 @@ pub struct Settings {
339339 bundle_settings : BundleSettings ,
340340 /// the binaries to bundle.
341341 binaries : Vec < BundleBinary > ,
342+ /// The target triple.
343+ target : String ,
342344}
343345
344346/// A builder for [`Settings`].
@@ -350,6 +352,7 @@ pub struct SettingsBuilder {
350352 package_settings : Option < PackageSettings > ,
351353 bundle_settings : BundleSettings ,
352354 binaries : Vec < BundleBinary > ,
355+ target : Option < String > ,
353356}
354357
355358impl SettingsBuilder {
@@ -396,13 +399,24 @@ impl SettingsBuilder {
396399 self
397400 }
398401
402+ /// Sets the target triple.
403+ pub fn target ( mut self , target : String ) -> Self {
404+ self . target . replace ( target) ;
405+ self
406+ }
407+
399408 /// Builds a Settings from the CLI args.
400409 ///
401410 /// Package settings will be read from Cargo.toml.
402411 ///
403412 /// Bundle settings will be read from from $TAURI_DIR/tauri.conf.json if it exists and fallback to Cargo.toml's [package.metadata.bundle].
404413 pub fn build ( self ) -> crate :: Result < Settings > {
405- let bundle_settings = parse_external_bin ( self . bundle_settings ) ?;
414+ let target = if let Some ( t) = self . target {
415+ t
416+ } else {
417+ target_triple ( ) ?
418+ } ;
419+ let bundle_settings = parse_external_bin ( & target, self . bundle_settings ) ?;
406420
407421 Ok ( Settings {
408422 package : self . package_settings . expect ( "package settings is required" ) ,
@@ -413,6 +427,7 @@ impl SettingsBuilder {
413427 . expect ( "out directory is required" ) ,
414428 binaries : self . binaries ,
415429 bundle_settings,
430+ target,
416431 } )
417432 }
418433}
@@ -425,7 +440,17 @@ impl Settings {
425440
426441 /// Returns the architecture for the binary being bundled (e.g. "arm", "x86" or "x86_64").
427442 pub fn binary_arch ( & self ) -> & str {
428- std:: env:: consts:: ARCH
443+ if self . target . starts_with ( "x86_64" ) {
444+ "x86_64"
445+ } else if self . target . starts_with ( 'i' ) {
446+ "x86"
447+ } else if self . target . starts_with ( "arm" ) {
448+ "arm"
449+ } else if self . target . starts_with ( "aarch64" ) {
450+ "aarch64"
451+ } else {
452+ panic ! ( "Unexpected target triple {}" , self . target)
453+ }
429454 }
430455
431456 /// Returns the file name of the binary being bundled.
@@ -660,8 +685,10 @@ impl Settings {
660685}
661686
662687/// Parses the external binaries to bundle, adding the target triple suffix to each of them.
663- fn parse_external_bin ( bundle_settings : BundleSettings ) -> crate :: Result < BundleSettings > {
664- let target_triple = target_triple ( ) ?;
688+ fn parse_external_bin (
689+ target_triple : & str ,
690+ bundle_settings : BundleSettings ,
691+ ) -> crate :: Result < BundleSettings > {
665692 let mut win_paths = Vec :: new ( ) ;
666693 let external_bin = match bundle_settings. external_bin {
667694 Some ( paths) => {
0 commit comments