Skip to content

Commit 1130b7b

Browse files
authored
feat: update to tauri v2 stable (#806)
* feat: update to tauri v2 stable - removed the --alpha, --beta, --rc flag - added a --version option to change tauri version - default to v2 stable * update ci * fix eq helper usage * fix test * not using handlebars * clippy * fix linux build * format * missing comma * fix template * fix template usage again * -t is already taken * fmt * fix no_bundle_flag
1 parent 04d1d5a commit 1130b7b

61 files changed

Lines changed: 221 additions & 172 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changes/tauri-v2-stable.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"create-tauri-app": minor
3+
"create-tauri-app-js": minor
4+
---
5+
6+
Update to v2 stable, meaning the `--alpha`, `--beta`, `--rc` flags are removed, and added a `--tauri-version [1|2]` option to change the Tauri version (defaults to latest stable - v2).

.github/workflows/templates-test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ jobs:
9797
- uses: dtolnay/rust-toolchain@stable
9898

9999
- run: cargo install tauri-cli --locked
100-
if: (matrix.settings.manager == 'cargo' || matrix.settings.manager == 'dotnet') && matrix.settings.rc != true
100+
if: (matrix.settings.manager == 'cargo' || matrix.settings.manager == 'dotnet') && matrix.settings.tauriVersion == 'latest'
101101

102-
- run: cargo install tauri-cli --version '^2.0.0-rc' --locked
103-
if: (matrix.settings.manager == 'cargo' || matrix.settings.manager == 'dotnet') && matrix.settings.rc == true
102+
- run: cargo install tauri-cli --version '^1.0.0' --locked
103+
if: (matrix.settings.manager == 'cargo' || matrix.settings.manager == 'dotnet') && matrix.settings.tauriVersion == 1
104104

105105
- run: |
106106
rustup target add wasm32-unknown-unknown
@@ -112,13 +112,13 @@ jobs:
112112
if: matrix.settings.install_dioxus_cli
113113
114114
- name: install system dependencies
115-
if: matrix.settings.rc != true
115+
if: matrix.settings.tauriVersion == 1
116116
run: |
117117
sudo apt-get update
118118
sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libayatana-appindicator3-dev librsvg2-dev patchelf
119119
120120
- name: install system dependencies (rc)
121-
if: matrix.settings.rc == true
121+
if: matrix.settings.tauriVersion == 'latest'
122122
run: |
123123
sudo apt-get update
124124
sudo apt-get install -y libgtk-3-dev webkit2gtk-4.1 libayatana-appindicator3-dev librsvg2-dev patchelf

.scripts/generate-templates-matrix.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ matrixConfig
7979
template: t,
8080
install_trunk: ["yew", "sycamore", "leptos"].includes(t),
8181
install_dioxus_cli: t === "dioxus",
82-
rc: false,
83-
no_bundle_flag: "-b none",
82+
tauriVersion: "latest",
83+
no_bundle_flag: "--no-bundle",
8484
...managerInfo,
8585
};
8686
outMatrix.push(jobInfo);
8787
outMatrix.push({
8888
...jobInfo,
89-
rc: true,
90-
no_bundle_flag: "--no-bundle",
91-
flags: "--rc",
89+
tauriVersion: 1,
90+
no_bundle_flag: "-b none",
91+
flags: "--tauri-version 1",
9292
});
9393
}
9494
}

src/args.rs

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,45 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use std::ffi::OsString;
5+
use std::{ffi::OsString, fmt::Display, str::FromStr};
66

77
use pico_args::Arguments;
88

99
use crate::{package_manager::PackageManager, template::Template, utils::colors::*};
1010

11+
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
12+
pub enum TauriVersion {
13+
V1,
14+
#[default]
15+
V2,
16+
}
17+
18+
impl TauriVersion {
19+
pub fn all() -> &'static [TauriVersion] {
20+
&[TauriVersion::V1, TauriVersion::V2]
21+
}
22+
}
23+
24+
impl Display for TauriVersion {
25+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26+
match self {
27+
Self::V1 => write!(f, "1"),
28+
Self::V2 => write!(f, "2"),
29+
}
30+
}
31+
}
32+
33+
impl FromStr for TauriVersion {
34+
type Err = &'static str;
35+
fn from_str(s: &str) -> Result<Self, Self::Err> {
36+
match s {
37+
"1" => Ok(Self::V1),
38+
"2" => Ok(Self::V1),
39+
_ => Err("unknown Tauri version"),
40+
}
41+
}
42+
}
43+
1144
#[derive(Debug)]
1245
pub struct Args {
1346
pub project_name: Option<String>,
@@ -16,7 +49,7 @@ pub struct Args {
1649
pub identifier: Option<String>,
1750
pub skip: bool,
1851
pub force: bool,
19-
pub rc: bool,
52+
pub tauri_version: TauriVersion,
2053
}
2154

2255
impl Default for Args {
@@ -28,7 +61,7 @@ impl Default for Args {
2861
template: Some(Template::Vanilla),
2962
skip: false,
3063
force: false,
31-
rc: false,
64+
tauri_version: TauriVersion::default(),
3265
}
3366
}
3467
}
@@ -55,7 +88,7 @@ pub fn parse(argv: Vec<OsString>, bin_name: Option<String>) -> anyhow::Result<Ar
5588
{GREEN}--identifier <identifier>{RESET} Specify a unique identifier for your application
5689
{GREEN}-y{RESET}, {GREEN}--yes{RESET} Skip prompts and use defaults where applicable
5790
{GREEN}-f{RESET}, {GREEN}--force{RESET} Force create the directory even if it is not empty.
58-
{GREEN}--rc{RESET} Bootstraps a project using tauri@2.0-rc.
91+
{GREEN}--tauri-version [1 | 2]{RESET} Bootstrap a project using the provided Tauri version. Defaults to the latest stable release.
5992
{GREEN}-h{RESET}, {GREEN}--help{RESET} Prints help information
6093
{GREEN}-v{RESET}, {GREEN}--version{RESET} Prints version information
6194
"#,
@@ -83,27 +116,14 @@ pub fn parse(argv: Vec<OsString>, bin_name: Option<String>) -> anyhow::Result<Ar
83116
std::process::exit(0);
84117
}
85118

86-
// pargs.contains() consume the flag so we have to bind the bool to a variable.
87-
let rc = if pargs.contains("--alpha") {
88-
eprintln!(
89-
"{BOLD}{YELLOW}warning{RESET}: The `{GREEN}--alpha{RESET}` option is now an alias for `{GREEN}--rc{RESET}` and may be removed in the future."
90-
);
91-
true
92-
} else if pargs.contains("--beta") {
93-
eprintln!(
94-
"{BOLD}{YELLOW}warning{RESET}: The `{GREEN}--beta{RESET}` option is now an alias for `{GREEN}--rc{RESET}` and may be removed in the future."
95-
);
96-
true
97-
} else {
98-
pargs.contains("--rc")
99-
};
119+
let tauri_version: Option<TauriVersion> = pargs.opt_value_from_str("--tauri-version")?;
100120

101121
let args = Args {
102122
manager: pargs.opt_value_from_str(["-m", "--manager"])?,
103123
template: pargs.opt_value_from_str(["-t", "--template"])?,
104124
skip: pargs.contains(["-y", "--yes"]),
105125
force: pargs.contains(["-f", "--force"]),
106-
rc,
126+
tauri_version: tauri_version.unwrap_or_default(),
107127
identifier: pargs.opt_value_from_str("--identifier")?,
108128
project_name: pargs.opt_free_from_str()?,
109129
};

src/deps.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use template::Template;
22

3-
use crate::internal::template;
43
use crate::package_manager::PackageManager;
54
use crate::utils::colors::*;
5+
use crate::{args::TauriVersion, internal::template};
66
use std::process::{Command, Output};
77

88
fn is_rustc_installed() -> bool {
@@ -45,11 +45,11 @@ fn is_dioxus_cli_installed() -> bool {
4545
.unwrap_or(false)
4646
}
4747

48-
fn is_appropriate_tauri_cli_installed(rc: bool) -> bool {
48+
fn is_appropriate_tauri_cli_installed(tauri_version: TauriVersion) -> bool {
4949
let check = |o: Output| match o.status.success() {
5050
true => String::from_utf8_lossy(&o.stdout)
5151
.split_once(' ')
52-
.map(|(_, v)| v.starts_with(if rc { '2' } else { '1' }))
52+
.map(|(_, v)| v.starts_with(&tauri_version.to_string()))
5353
.unwrap_or(false),
5454
s => s,
5555
};
@@ -119,12 +119,11 @@ fn is_webview2_installed() -> bool {
119119
target_os = "openbsd",
120120
target_os = "netbsd"
121121
))]
122-
fn is_webkit2gtk_installed(rc: bool) -> bool {
122+
fn is_webkit2gtk_installed(tauri_version: TauriVersion) -> bool {
123123
Command::new("pkg-config")
124-
.arg(if rc {
125-
"webkit2gtk-4.1"
126-
} else {
127-
"webkit2gtk-4.0"
124+
.arg(match tauri_version {
125+
TauriVersion::V1 => "webkit2gtk-4.0",
126+
TauriVersion::V2 => "webkit2gtk-4.1",
128127
})
129128
.output()
130129
.map(|o| o.status.success())
@@ -171,7 +170,11 @@ struct Dep<'a> {
171170
}
172171

173172
/// Print missing deps in a table and returns whether there was any missing deps.
174-
pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: bool) -> bool {
173+
pub fn print_missing_deps(
174+
pkg_manager: PackageManager,
175+
template: Template,
176+
tauri_version: TauriVersion,
177+
) -> bool {
175178
let rustc_installed = is_rustc_installed();
176179
let cargo_installed = is_cargo_installed();
177180

@@ -183,7 +186,7 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: b
183186
target_os = "netbsd"
184187
))]
185188
let (webkit2gtk_installed, rsvg2_installed) =
186-
(is_webkit2gtk_installed(rc), is_rsvg2_installed());
189+
(is_webkit2gtk_installed(tauri_version), is_rsvg2_installed());
187190

188191
let deps: &[Dep<'_>] = &[
189192
Dep {
@@ -206,12 +209,11 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: b
206209
},
207210
Dep {
208211
name: "Tauri CLI",
209-
instruction: if rc {
210-
format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^2.0.0-rc' --locked{RESET}`")
211-
} else {
212-
format!("Run `{BLUE}{BOLD}cargo install tauri-cli{RESET} --locked`")
212+
instruction: match tauri_version {
213+
TauriVersion::V1 => format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^2.0.0' --locked{RESET}`"),
214+
TauriVersion::V2 => format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^1.0.0' --locked{RESET}`"),
213215
},
214-
exists: &|| is_appropriate_tauri_cli_installed(rc),
216+
exists: &|| is_appropriate_tauri_cli_installed(tauri_version),
215217
skip: pkg_manager.is_node() || !template.needs_tauri_cli(),
216218
},
217219
Dep {
@@ -254,10 +256,9 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: b
254256
))]
255257
Dep {
256258
name: "webkit2gtk & rsvg2",
257-
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if rc {
258-
"https://v2.tauri.app/guides/prerequisites/#linux"
259-
} else {
260-
"https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
259+
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", match tauri_version {
260+
TauriVersion::V1 => "https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux",
261+
TauriVersion::V2 => "https://v2.tauri.app/guides/prerequisites/#linux",
261262
}),
262263
exists: &|| webkit2gtk_installed && rsvg2_installed,
263264
skip: webkit2gtk_installed || rsvg2_installed,
@@ -271,10 +272,9 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: b
271272
))]
272273
Dep {
273274
name: "webkit2gtk",
274-
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if rc {
275-
"https://v2.tauri.app/guides/prerequisites/#linux"
276-
} else {
277-
"https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
275+
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", match tauri_version {
276+
TauriVersion::V1 => "https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux",
277+
TauriVersion::V2 => "https://v2.tauri.app/guides/prerequisites/#linux",
278278
}),
279279
exists: &|| webkit2gtk_installed,
280280
skip: !rsvg2_installed && !webkit2gtk_installed,
@@ -288,10 +288,9 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: b
288288
))]
289289
Dep {
290290
name: "rsvg2",
291-
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if rc {
292-
"https://v2.tauri.app/guides/prerequisites/#linux"
293-
} else {
294-
"https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
291+
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", match tauri_version {
292+
TauriVersion::V2 => "https://v2.tauri.app/guides/prerequisites/#linux",
293+
TauriVersion::V1 => "https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
295294
}),
296295
exists: &|| rsvg2_installed,
297296
skip: !rsvg2_installed && !webkit2gtk_installed,

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use dialoguer::{Confirm, Input, Select};
77
use std::{ffi::OsString, fs, process::exit};
88

99
use crate::{
10+
args::TauriVersion,
1011
category::Category,
1112
deps::print_missing_deps,
1213
package_manager::PackageManager,
@@ -66,7 +67,7 @@ where
6667
let defaults = args::Args::default();
6768
let args::Args {
6869
skip,
69-
rc,
70+
tauri_version,
7071
manager,
7172
project_name,
7273
template,
@@ -328,13 +329,13 @@ where
328329
&project_name,
329330
&package_name,
330331
&identifier,
331-
rc,
332+
tauri_version,
332333
)?;
333334

334335
// Print post-render instructions
335336
println!();
336337
print!("Template created!");
337-
let has_missing = print_missing_deps(pkg_manager, template, rc);
338+
let has_missing = print_missing_deps(pkg_manager, template, tauri_version);
338339
if has_missing {
339340
println!("Make sure you have installed the prerequisites for your OS: {BLUE}{BOLD}https://tauri.app/v1/guides/getting-started/prerequisites{RESET}, then run:");
340341
} else {
@@ -353,7 +354,7 @@ where
353354
if let Some(cmd) = pkg_manager.install_cmd() {
354355
println!(" {cmd}");
355356
}
356-
if !rc {
357+
if matches!(tauri_version, TauriVersion::V1) {
357358
println!(" {} tauri dev", pkg_manager.run_cmd());
358359
} else {
359360
println!(" {} tauri android init", pkg_manager.run_cmd());

0 commit comments

Comments
 (0)