@@ -65,23 +65,176 @@ impl Default for WindowUrl {
6565 }
6666}
6767
68- /// Targets to bundle.
69- #[ derive( Debug , PartialEq , Eq , Clone , Deserialize , Serialize ) ]
68+ /// A bundle referenced by tauri-bundler .
69+ #[ derive( Debug , PartialEq , Eq , Clone ) ]
7070#[ cfg_attr( feature = "schema" , derive( JsonSchema ) ) ]
71- #[ serde( untagged) ]
71+ #[ cfg_attr( feature = "schema" , schemars( rename_all = "lowercase" ) ) ]
72+ pub enum BundleType {
73+ /// The debian bundle (.deb).
74+ Deb ,
75+ /// The AppImage bundle (.appimage).
76+ AppImage ,
77+ /// The Microsoft Installer bundle (.msi).
78+ Msi ,
79+ /// The macOS application bundle (.app).
80+ App ,
81+ /// The Apple Disk Image bundle (.dmg).
82+ Dmg ,
83+ /// The Tauri updater bundle.
84+ Updater ,
85+ }
86+
87+ impl Display for BundleType {
88+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
89+ write ! (
90+ f,
91+ "{}" ,
92+ match self {
93+ Self :: Deb => "deb" ,
94+ Self :: AppImage => "appimage" ,
95+ Self :: Msi => "msi" ,
96+ Self :: App => "app" ,
97+ Self :: Dmg => "dmg" ,
98+ Self :: Updater => "updater" ,
99+ }
100+ )
101+ }
102+ }
103+
104+ impl Serialize for BundleType {
105+ fn serialize < S > ( & self , serializer : S ) -> std:: result:: Result < S :: Ok , S :: Error >
106+ where
107+ S : Serializer ,
108+ {
109+ serializer. serialize_str ( self . to_string ( ) . as_ref ( ) )
110+ }
111+ }
112+
113+ impl < ' de > Deserialize < ' de > for BundleType {
114+ fn deserialize < D > ( deserializer : D ) -> std:: result:: Result < Self , D :: Error >
115+ where
116+ D : Deserializer < ' de > ,
117+ {
118+ let s = String :: deserialize ( deserializer) ?;
119+ match s. to_lowercase ( ) . as_str ( ) {
120+ "deb" => Ok ( Self :: Deb ) ,
121+ "appimage" => Ok ( Self :: AppImage ) ,
122+ "msi" => Ok ( Self :: Msi ) ,
123+ "app" => Ok ( Self :: App ) ,
124+ "dmg" => Ok ( Self :: Dmg ) ,
125+ "updater" => Ok ( Self :: Updater ) ,
126+ _ => Err ( DeError :: custom ( format ! ( "unknown bundle target '{}'" , s) ) ) ,
127+ }
128+ }
129+ }
130+
131+ /// Targets to bundle. Each value is case insensitive.
132+ #[ derive( Debug , PartialEq , Eq , Clone ) ]
72133pub enum BundleTarget {
134+ /// Bundle all targets.
135+ All ,
73136 /// A list of bundle targets.
74- All ( Vec < String > ) ,
137+ List ( Vec < BundleType > ) ,
75138 /// A single bundle target.
76- One ( String ) ,
139+ One ( BundleType ) ,
140+ }
141+
142+ #[ cfg( feature = "schema" ) ]
143+ impl schemars:: JsonSchema for BundleTarget {
144+ fn schema_name ( ) -> std:: string:: String {
145+ "BundleTarget" . to_owned ( )
146+ }
147+
148+ fn json_schema ( gen : & mut schemars:: gen:: SchemaGenerator ) -> schemars:: schema:: Schema {
149+ let any_of = vec ! [
150+ schemars:: schema:: SchemaObject {
151+ enum_values: Some ( vec![ "all" . into( ) ] ) ,
152+ metadata: Some ( Box :: new( schemars:: schema:: Metadata {
153+ description: Some ( "Bundle all targets." . to_owned( ) ) ,
154+ ..Default :: default ( )
155+ } ) ) ,
156+ ..Default :: default ( )
157+ }
158+ . into( ) ,
159+ schemars:: _private:: apply_metadata(
160+ gen . subschema_for:: <Vec <BundleType >>( ) ,
161+ schemars:: schema:: Metadata {
162+ description: Some ( "A list of bundle targets." . to_owned( ) ) ,
163+ ..Default :: default ( )
164+ } ,
165+ ) ,
166+ schemars:: _private:: apply_metadata(
167+ gen . subschema_for:: <BundleType >( ) ,
168+ schemars:: schema:: Metadata {
169+ description: Some ( "A single bundle target." . to_owned( ) ) ,
170+ ..Default :: default ( )
171+ } ,
172+ ) ,
173+ ] ;
174+
175+ schemars:: schema:: SchemaObject {
176+ subschemas : Some ( Box :: new ( schemars:: schema:: SubschemaValidation {
177+ any_of : Some ( any_of) ,
178+ ..Default :: default ( )
179+ } ) ) ,
180+ metadata : Some ( Box :: new ( schemars:: schema:: Metadata {
181+ description : Some ( "Targets to bundle. Each value is case insensitive." . to_owned ( ) ) ,
182+ ..Default :: default ( )
183+ } ) ) ,
184+ ..Default :: default ( )
185+ }
186+ . into ( )
187+ }
188+ }
189+
190+ impl Default for BundleTarget {
191+ fn default ( ) -> Self {
192+ Self :: All
193+ }
194+ }
195+
196+ impl Serialize for BundleTarget {
197+ fn serialize < S > ( & self , serializer : S ) -> std:: result:: Result < S :: Ok , S :: Error >
198+ where
199+ S : Serializer ,
200+ {
201+ match self {
202+ Self :: All => serializer. serialize_str ( "all" ) ,
203+ Self :: List ( l) => l. serialize ( serializer) ,
204+ Self :: One ( t) => serializer. serialize_str ( t. to_string ( ) . as_ref ( ) ) ,
205+ }
206+ }
207+ }
208+
209+ impl < ' de > Deserialize < ' de > for BundleTarget {
210+ fn deserialize < D > ( deserializer : D ) -> std:: result:: Result < Self , D :: Error >
211+ where
212+ D : Deserializer < ' de > ,
213+ {
214+ #[ derive( Deserialize , Serialize ) ]
215+ #[ serde( untagged) ]
216+ pub enum BundleTargetInner {
217+ List ( Vec < BundleType > ) ,
218+ One ( BundleType ) ,
219+ All ( String ) ,
220+ }
221+
222+ match BundleTargetInner :: deserialize ( deserializer) ? {
223+ BundleTargetInner :: All ( s) if s. to_lowercase ( ) == "all" => Ok ( Self :: All ) ,
224+ BundleTargetInner :: All ( t) => Err ( DeError :: custom ( format ! ( "invalid bundle type {}" , t) ) ) ,
225+ BundleTargetInner :: List ( l) => Ok ( Self :: List ( l) ) ,
226+ BundleTargetInner :: One ( t) => Ok ( Self :: One ( t) ) ,
227+ }
228+ }
77229}
78230
79231impl BundleTarget {
80- /// Gets the bundle targets as a [`Vec`].
232+ /// Gets the bundle targets as a [`Vec`]. The vector is empty when set to [`BundleTarget::All`].
81233 #[ allow( dead_code) ]
82- pub fn to_vec ( & self ) -> Vec < String > {
234+ pub fn to_vec ( & self ) -> Vec < BundleType > {
83235 match self {
84- Self :: All ( list) => list. clone ( ) ,
236+ Self :: All => vec ! [ ] ,
237+ Self :: List ( list) => list. clone ( ) ,
85238 Self :: One ( i) => vec ! [ i. clone( ) ] ,
86239 }
87240 }
@@ -308,11 +461,12 @@ fn default_allow_downgrades() -> bool {
308461#[ cfg_attr( feature = "schema" , derive( JsonSchema ) ) ]
309462#[ serde( rename_all = "camelCase" , deny_unknown_fields) ]
310463pub struct BundleConfig {
311- /// Whether we should build your app with tauri-bundler or plain `cargo build`
464+ /// Whether Tauri should bundle your application or just output the executable.
312465 #[ serde( default ) ]
313466 pub active : bool ,
314- /// The bundle targets, currently supports ["deb", "app", "msi", "appimage", "dmg"] or "all"
315- pub targets : Option < BundleTarget > ,
467+ /// The bundle targets, currently supports ["deb", "appimage", "msi", "app", "dmg", "updater"] or "all".
468+ #[ serde( default ) ]
469+ pub targets : BundleTarget ,
316470 /// The application identifier in reverse domain name notation (e.g. `com.tauri.example`).
317471 /// This string must be unique across applications since it is used in system configurations like
318472 /// the bundle ID and path to the webview data directory.
@@ -2740,7 +2894,7 @@ mod build {
27402894 let identifier = str_lit ( & self . identifier ) ;
27412895 let icon = vec_lit ( & self . icon , str_lit) ;
27422896 let active = self . active ;
2743- let targets = quote ! ( None ) ;
2897+ let targets = quote ! ( Default :: default ( ) ) ;
27442898 let resources = quote ! ( None ) ;
27452899 let copyright = quote ! ( None ) ;
27462900 let category = quote ! ( None ) ;
@@ -3159,7 +3313,7 @@ mod test {
31593313 windows : vec ! [ ] ,
31603314 bundle : BundleConfig {
31613315 active : false ,
3162- targets : None ,
3316+ targets : Default :: default ( ) ,
31633317 identifier : String :: from ( "" ) ,
31643318 icon : Vec :: new ( ) ,
31653319 resources : None ,
0 commit comments