Skip to content

Commit

Permalink
feat: update to tauri v2 stable (#806)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lucasfernog authored Oct 2, 2024
1 parent 04d1d5a commit 1130b7b
Show file tree
Hide file tree
Showing 61 changed files with 221 additions and 172 deletions.
6 changes: 6 additions & 0 deletions .changes/tauri-v2-stable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"create-tauri-app": minor
"create-tauri-app-js": minor
---

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).
10 changes: 5 additions & 5 deletions .github/workflows/templates-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ jobs:
- uses: dtolnay/rust-toolchain@stable

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

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

- run: |
rustup target add wasm32-unknown-unknown
Expand All @@ -112,13 +112,13 @@ jobs:
if: matrix.settings.install_dioxus_cli
- name: install system dependencies
if: matrix.settings.rc != true
if: matrix.settings.tauriVersion == 1
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libayatana-appindicator3-dev librsvg2-dev patchelf
- name: install system dependencies (rc)
if: matrix.settings.rc == true
if: matrix.settings.tauriVersion == 'latest'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev webkit2gtk-4.1 libayatana-appindicator3-dev librsvg2-dev patchelf
Expand Down
10 changes: 5 additions & 5 deletions .scripts/generate-templates-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ matrixConfig
template: t,
install_trunk: ["yew", "sycamore", "leptos"].includes(t),
install_dioxus_cli: t === "dioxus",
rc: false,
no_bundle_flag: "-b none",
tauriVersion: "latest",
no_bundle_flag: "--no-bundle",
...managerInfo,
};
outMatrix.push(jobInfo);
outMatrix.push({
...jobInfo,
rc: true,
no_bundle_flag: "--no-bundle",
flags: "--rc",
tauriVersion: 1,
no_bundle_flag: "-b none",
flags: "--tauri-version 1",
});
}
}
Expand Down
58 changes: 39 additions & 19 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,45 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use std::ffi::OsString;
use std::{ffi::OsString, fmt::Display, str::FromStr};

use pico_args::Arguments;

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

#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
pub enum TauriVersion {
V1,
#[default]
V2,
}

impl TauriVersion {
pub fn all() -> &'static [TauriVersion] {
&[TauriVersion::V1, TauriVersion::V2]
}
}

impl Display for TauriVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::V1 => write!(f, "1"),
Self::V2 => write!(f, "2"),
}
}
}

impl FromStr for TauriVersion {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"1" => Ok(Self::V1),
"2" => Ok(Self::V1),
_ => Err("unknown Tauri version"),
}
}
}

#[derive(Debug)]
pub struct Args {
pub project_name: Option<String>,
Expand All @@ -16,7 +49,7 @@ pub struct Args {
pub identifier: Option<String>,
pub skip: bool,
pub force: bool,
pub rc: bool,
pub tauri_version: TauriVersion,
}

impl Default for Args {
Expand All @@ -28,7 +61,7 @@ impl Default for Args {
template: Some(Template::Vanilla),
skip: false,
force: false,
rc: false,
tauri_version: TauriVersion::default(),
}
}
}
Expand All @@ -55,7 +88,7 @@ pub fn parse(argv: Vec<OsString>, bin_name: Option<String>) -> anyhow::Result<Ar
{GREEN}--identifier <identifier>{RESET} Specify a unique identifier for your application
{GREEN}-y{RESET}, {GREEN}--yes{RESET} Skip prompts and use defaults where applicable
{GREEN}-f{RESET}, {GREEN}--force{RESET} Force create the directory even if it is not empty.
{GREEN}--rc{RESET} Bootstraps a project using [email protected].
{GREEN}--tauri-version [1 | 2]{RESET} Bootstrap a project using the provided Tauri version. Defaults to the latest stable release.
{GREEN}-h{RESET}, {GREEN}--help{RESET} Prints help information
{GREEN}-v{RESET}, {GREEN}--version{RESET} Prints version information
"#,
Expand Down Expand Up @@ -83,27 +116,14 @@ pub fn parse(argv: Vec<OsString>, bin_name: Option<String>) -> anyhow::Result<Ar
std::process::exit(0);
}

// pargs.contains() consume the flag so we have to bind the bool to a variable.
let rc = if pargs.contains("--alpha") {
eprintln!(
"{BOLD}{YELLOW}warning{RESET}: The `{GREEN}--alpha{RESET}` option is now an alias for `{GREEN}--rc{RESET}` and may be removed in the future."
);
true
} else if pargs.contains("--beta") {
eprintln!(
"{BOLD}{YELLOW}warning{RESET}: The `{GREEN}--beta{RESET}` option is now an alias for `{GREEN}--rc{RESET}` and may be removed in the future."
);
true
} else {
pargs.contains("--rc")
};
let tauri_version: Option<TauriVersion> = pargs.opt_value_from_str("--tauri-version")?;

let args = Args {
manager: pargs.opt_value_from_str(["-m", "--manager"])?,
template: pargs.opt_value_from_str(["-t", "--template"])?,
skip: pargs.contains(["-y", "--yes"]),
force: pargs.contains(["-f", "--force"]),
rc,
tauri_version: tauri_version.unwrap_or_default(),
identifier: pargs.opt_value_from_str("--identifier")?,
project_name: pargs.opt_free_from_str()?,
};
Expand Down
53 changes: 26 additions & 27 deletions src/deps.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use template::Template;

use crate::internal::template;
use crate::package_manager::PackageManager;
use crate::utils::colors::*;
use crate::{args::TauriVersion, internal::template};
use std::process::{Command, Output};

fn is_rustc_installed() -> bool {
Expand Down Expand Up @@ -45,11 +45,11 @@ fn is_dioxus_cli_installed() -> bool {
.unwrap_or(false)
}

fn is_appropriate_tauri_cli_installed(rc: bool) -> bool {
fn is_appropriate_tauri_cli_installed(tauri_version: TauriVersion) -> bool {
let check = |o: Output| match o.status.success() {
true => String::from_utf8_lossy(&o.stdout)
.split_once(' ')
.map(|(_, v)| v.starts_with(if rc { '2' } else { '1' }))
.map(|(_, v)| v.starts_with(&tauri_version.to_string()))
.unwrap_or(false),
s => s,
};
Expand Down Expand Up @@ -119,12 +119,11 @@ fn is_webview2_installed() -> bool {
target_os = "openbsd",
target_os = "netbsd"
))]
fn is_webkit2gtk_installed(rc: bool) -> bool {
fn is_webkit2gtk_installed(tauri_version: TauriVersion) -> bool {
Command::new("pkg-config")
.arg(if rc {
"webkit2gtk-4.1"
} else {
"webkit2gtk-4.0"
.arg(match tauri_version {
TauriVersion::V1 => "webkit2gtk-4.0",
TauriVersion::V2 => "webkit2gtk-4.1",
})
.output()
.map(|o| o.status.success())
Expand Down Expand Up @@ -171,7 +170,11 @@ struct Dep<'a> {
}

/// Print missing deps in a table and returns whether there was any missing deps.
pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: bool) -> bool {
pub fn print_missing_deps(
pkg_manager: PackageManager,
template: Template,
tauri_version: TauriVersion,
) -> bool {
let rustc_installed = is_rustc_installed();
let cargo_installed = is_cargo_installed();

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

let deps: &[Dep<'_>] = &[
Dep {
Expand All @@ -206,12 +209,11 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: b
},
Dep {
name: "Tauri CLI",
instruction: if rc {
format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^2.0.0-rc' --locked{RESET}`")
} else {
format!("Run `{BLUE}{BOLD}cargo install tauri-cli{RESET} --locked`")
instruction: match tauri_version {
TauriVersion::V1 => format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^2.0.0' --locked{RESET}`"),
TauriVersion::V2 => format!("Run `{BLUE}{BOLD}cargo install tauri-cli --version '^1.0.0' --locked{RESET}`"),
},
exists: &|| is_appropriate_tauri_cli_installed(rc),
exists: &|| is_appropriate_tauri_cli_installed(tauri_version),
skip: pkg_manager.is_node() || !template.needs_tauri_cli(),
},
Dep {
Expand Down Expand Up @@ -254,10 +256,9 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: b
))]
Dep {
name: "webkit2gtk & rsvg2",
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if rc {
"https://v2.tauri.app/guides/prerequisites/#linux"
} else {
"https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", match tauri_version {
TauriVersion::V1 => "https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux",
TauriVersion::V2 => "https://v2.tauri.app/guides/prerequisites/#linux",
}),
exists: &|| webkit2gtk_installed && rsvg2_installed,
skip: webkit2gtk_installed || rsvg2_installed,
Expand All @@ -271,10 +272,9 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: b
))]
Dep {
name: "webkit2gtk",
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if rc {
"https://v2.tauri.app/guides/prerequisites/#linux"
} else {
"https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", match tauri_version {
TauriVersion::V1 => "https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux",
TauriVersion::V2 => "https://v2.tauri.app/guides/prerequisites/#linux",
}),
exists: &|| webkit2gtk_installed,
skip: !rsvg2_installed && !webkit2gtk_installed,
Expand All @@ -288,10 +288,9 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, rc: b
))]
Dep {
name: "rsvg2",
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", if rc {
"https://v2.tauri.app/guides/prerequisites/#linux"
} else {
"https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
instruction: format!("Visit {BLUE}{BOLD}{}{RESET}", match tauri_version {
TauriVersion::V2 => "https://v2.tauri.app/guides/prerequisites/#linux",
TauriVersion::V1 => "https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
}),
exists: &|| rsvg2_installed,
skip: !rsvg2_installed && !webkit2gtk_installed,
Expand Down
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use dialoguer::{Confirm, Input, Select};
use std::{ffi::OsString, fs, process::exit};

use crate::{
args::TauriVersion,
category::Category,
deps::print_missing_deps,
package_manager::PackageManager,
Expand Down Expand Up @@ -66,7 +67,7 @@ where
let defaults = args::Args::default();
let args::Args {
skip,
rc,
tauri_version,
manager,
project_name,
template,
Expand Down Expand Up @@ -328,13 +329,13 @@ where
&project_name,
&package_name,
&identifier,
rc,
tauri_version,
)?;

// Print post-render instructions
println!();
print!("Template created!");
let has_missing = print_missing_deps(pkg_manager, template, rc);
let has_missing = print_missing_deps(pkg_manager, template, tauri_version);
if has_missing {
println!("Make sure you have installed the prerequisites for your OS: {BLUE}{BOLD}https://tauri.app/v1/guides/getting-started/prerequisites{RESET}, then run:");
} else {
Expand All @@ -353,7 +354,7 @@ where
if let Some(cmd) = pkg_manager.install_cmd() {
println!(" {cmd}");
}
if !rc {
if matches!(tauri_version, TauriVersion::V1) {
println!(" {} tauri dev", pkg_manager.run_cmd());
} else {
println!(" {} tauri android init", pkg_manager.run_cmd());
Expand Down
Loading

0 comments on commit 1130b7b

Please sign in to comment.