Skip to content

Commit 31c15cd

Browse files
authored
docs(config): enhance documentation for bundle targets, closes #3251 (#4418)
1 parent 384dc8c commit 31c15cd

File tree

6 files changed

+245
-45
lines changed

6 files changed

+245
-45
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": patch
3+
"cli.js": patch
4+
---
5+
6+
Warn if updater is enabled but not in the bundle target list.

.changes/config-targets.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-utils": patch
3+
---
4+
5+
Changed the `BundleConfig::targets` to a `BundleTarget` enum to enhance generated documentation.

core/tauri-utils/src/config.rs

Lines changed: 167 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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)]
72133
pub 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

79231
impl 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)]
310463
pub 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,

tooling/bundler/src/bundle/settings.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
use super::category::AppCategory;
66
use crate::bundle::{common, platform::target_triple};
7-
use tauri_utils::resources::{external_binaries, ResourcePaths};
7+
use tauri_utils::{
8+
config::BundleType,
9+
resources::{external_binaries, ResourcePaths},
10+
};
811

912
use std::{
1013
collections::HashMap,
@@ -33,6 +36,19 @@ pub enum PackageType {
3336
Updater,
3437
}
3538

39+
impl From<BundleType> for PackageType {
40+
fn from(bundle: BundleType) -> Self {
41+
match bundle {
42+
BundleType::Deb => Self::Deb,
43+
BundleType::AppImage => Self::AppImage,
44+
BundleType::Msi => Self::WindowsMsi,
45+
BundleType::App => Self::MacOsBundle,
46+
BundleType::Dmg => Self::Dmg,
47+
BundleType::Updater => Self::Updater,
48+
}
49+
}
50+
}
51+
3652
impl PackageType {
3753
/// Maps a short name to a PackageType.
3854
/// Possible values are "deb", "ios", "msi", "app", "rpm", "appimage", "dmg", "updater".

tooling/cli/schema.json

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
"macOS": {
130130
"minimumSystemVersion": "10.13"
131131
},
132+
"targets": "all",
132133
"windows": {
133134
"allowDowngrades": true,
134135
"certificateThumbprint": null,
@@ -259,6 +260,7 @@
259260
"macOS": {
260261
"minimumSystemVersion": "10.13"
261262
},
263+
"targets": "all",
262264
"windows": {
263265
"allowDowngrades": true,
264266
"certificateThumbprint": null,
@@ -896,18 +898,16 @@
896898
],
897899
"properties": {
898900
"active": {
899-
"description": "Whether we should build your app with tauri-bundler or plain `cargo build`",
901+
"description": "Whether Tauri should bundle your application or just output the executable.",
900902
"default": false,
901903
"type": "boolean"
902904
},
903905
"targets": {
904-
"description": "The bundle targets, currently supports [\"deb\", \"app\", \"msi\", \"appimage\", \"dmg\"] or \"all\"",
905-
"anyOf": [
906+
"description": "The bundle targets, currently supports [\"deb\", \"appimage\", \"msi\", \"app\", \"dmg\", \"updater\"] or \"all\".",
907+
"default": "all",
908+
"allOf": [
906909
{
907910
"$ref": "#/definitions/BundleTarget"
908-
},
909-
{
910-
"type": "null"
911911
}
912912
]
913913
},
@@ -1025,21 +1025,43 @@
10251025
"additionalProperties": false
10261026
},
10271027
"BundleTarget": {
1028-
"description": "Targets to bundle.",
1028+
"description": "Targets to bundle. Each value is case insensitive.",
10291029
"anyOf": [
1030+
{
1031+
"description": "Bundle all targets.",
1032+
"enum": [
1033+
"all"
1034+
]
1035+
},
10301036
{
10311037
"description": "A list of bundle targets.",
10321038
"type": "array",
10331039
"items": {
1034-
"type": "string"
1040+
"$ref": "#/definitions/BundleType"
10351041
}
10361042
},
10371043
{
10381044
"description": "A single bundle target.",
1039-
"type": "string"
1045+
"allOf": [
1046+
{
1047+
"$ref": "#/definitions/BundleType"
1048+
}
1049+
]
10401050
}
10411051
]
10421052
},
1053+
"BundleType": {
1054+
"description": "A bundle referenced by tauri-bundler.",
1055+
"type": "string",
1056+
"enum": [
1057+
"deb",
1058+
"appimage",
1059+
"msi",
1060+
"app",
1061+
"dmg",
1062+
"updater"
1063+
]
1064+
},
10431065
"AppImageConfig": {
10441066
"description": "Configuration for AppImage bundles.",
10451067
"type": "object",

0 commit comments

Comments
 (0)