Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
28b3180
refactor(tauri-cli): introduce replacement functions
sftse Dec 8, 2025
c04fb1d
refactor(tauri-cli): apply replacement to remove.rs
sftse Dec 8, 2025
4f17fa6
refactor(tauri-cli): apply replacement to icon.rs
sftse Dec 8, 2025
7f91f0c
refactor(tauri-cli): apply replacement to bundle.rs
sftse Dec 8, 2025
906197c
refactor(tauri-cli): apply replacement to build.rs
sftse Dec 8, 2025
6d15f73
refactor(tauri-cli): apply replacement to add.rs
sftse Dec 8, 2025
ba9e32a
refactor(tauri-cli): apply replacement to dev.rs
sftse Dec 8, 2025
9957b4b
refactor(tauri-cli): less controlflow
sftse Dec 14, 2025
9cb6093
refactor(tauri-cli): split config loading from locking static
sftse Dec 14, 2025
404aae5
refactor(tauri-cli): remove duplicate checks covered by if let Some(t…
sftse Dec 14, 2025
b46f12d
fmt
sftse Dec 14, 2025
ad15416
refactor(tauri-cli): apply replacement to inspect.rs
sftse Dec 15, 2025
868cd09
refactor(tauri-cli): dont use statics for config
sftse Dec 16, 2025
16e534c
refactor(tauri-cli): finish threading directory paths through functions
sftse Dec 18, 2025
07ee190
fix: clippy
sftse Dec 19, 2025
fe02157
fixup CI
sftse Dec 19, 2025
ba9b468
refactor(tauri-cli): dont need mutex
sftse Dec 19, 2025
7ed305f
refactor(tauri-cli): rescope mutex use to minimal necessary
sftse Dec 19, 2025
07d51e7
fix CI, reduce mutex use
sftse Dec 21, 2025
fdbaf1f
fixup PR #14607
sftse Dec 29, 2025
06c9c34
fix: clippy
sftse Jan 1, 2026
97bec73
Merge branch 'dev' into less-statics
Legend-Master Jan 11, 2026
3cb10ad
refactor(tauri-cli): remove ConfigHandle
sftse Jan 12, 2026
87a332f
refactor(tauri-cli): remove more unwraps and panicing functions
sftse Jan 12, 2026
54cfbd9
refactor(tauri-cli): less mutexes
sftse Jan 12, 2026
a2575e4
refactor(tauri-cli): undo mistaken change, address review comment
sftse Jan 12, 2026
c2b29d8
Split android build to 2 functions
Legend-Master Jan 17, 2026
006b168
Pass in dirs to migration v1 like the v2 beta
Legend-Master Jan 17, 2026
0b1d3c4
Add change file
Legend-Master Jan 17, 2026
1ee20a9
Merge remote-tracking branch 'upstream/dev' into less-statics
Legend-Master Jan 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/reduce-internal-statics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tauri-apps/cli": patch:changes
"tauri-cli": patch:changes
---

Refactored internal use of static on config and directory resolvings, no user facing changes, please report any regressions if you encounter any
12 changes: 3 additions & 9 deletions crates/tauri-cli/src/acl/capability/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ use std::{collections::HashSet, path::PathBuf};
use clap::Parser;
use tauri_utils::acl::capability::{Capability, PermissionEntry};

use crate::{
acl::FileFormat,
error::ErrorExt,
helpers::{app_paths::tauri_dir, prompts},
Result,
};
use crate::{acl::FileFormat, error::ErrorExt, helpers::prompts, Result};

#[derive(Debug, Parser)]
#[clap(about = "Create a new permission file")]
Expand All @@ -37,7 +32,7 @@ pub struct Options {
}

pub fn command(options: Options) -> Result<()> {
crate::helpers::app_paths::resolve();
let dirs = crate::helpers::app_paths::resolve_dirs();

let identifier = match options.identifier {
Some(i) => i,
Expand Down Expand Up @@ -111,8 +106,7 @@ pub fn command(options: Options) -> Result<()> {
.canonicalize()
.fs_context("failed to canonicalize capability file path", o.clone())?,
None => {
let dir = tauri_dir();
let capabilities_dir = dir.join("capabilities");
let capabilities_dir = dirs.tauri.join("capabilities");
capabilities_dir.join(format!(
"{}.{}",
capability.identifier,
Expand Down
6 changes: 3 additions & 3 deletions crates/tauri-cli/src/acl/permission/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use clap::Parser;

use crate::{
error::{Context, ErrorExt},
helpers::app_paths::tauri_dir,
Result,
};
use colored::Colorize;
Expand All @@ -25,9 +24,10 @@ pub struct Options {
}

pub fn command(options: Options) -> Result<()> {
crate::helpers::app_paths::resolve();
let dirs = crate::helpers::app_paths::resolve_dirs();

let acl_manifests_path = tauri_dir()
let acl_manifests_path = dirs
.tauri
.join("gen")
.join("schemas")
.join("acl-manifests.json");
Expand Down
20 changes: 11 additions & 9 deletions crates/tauri-cli/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
acl,
error::ErrorExt,
helpers::{
app_paths::{resolve_frontend_dir, tauri_dir},
app_paths::{resolve_frontend_dir, Dirs},
cargo,
npm::PackageManager,
},
Expand Down Expand Up @@ -39,11 +39,11 @@ pub struct Options {
}

pub fn command(options: Options) -> Result<()> {
crate::helpers::app_paths::resolve();
run(options)
let dirs = crate::helpers::app_paths::resolve_dirs();
run(options, &dirs)
}

pub fn run(options: Options) -> Result<()> {
pub fn run(options: Options, dirs: &Dirs) -> Result<()> {
let (plugin, version) = options
.plugin
.split_once('@')
Expand Down Expand Up @@ -71,7 +71,6 @@ pub fn run(options: Options) -> Result<()> {
}

let frontend_dir = resolve_frontend_dir();
let tauri_dir = tauri_dir();

let target_str = metadata
.desktop_only
Expand All @@ -90,7 +89,7 @@ pub fn run(options: Options) -> Result<()> {
branch: options.branch.as_deref(),
rev: options.rev.as_deref(),
tag: options.tag.as_deref(),
cwd: Some(tauri_dir),
cwd: Some(dirs.tauri),
target: target_str,
})?;

Expand All @@ -117,7 +116,7 @@ pub fn run(options: Options) -> Result<()> {
(None, None, None, None) => npm_name,
_ => crate::error::bail!("Only one of --tag, --rev and --branch can be specified"),
};
manager.install(&[npm_spec], tauri_dir)?;
manager.install(&[npm_spec], dirs.tauri)?;
}

let _ = acl::permission::add::command(acl::permission::add::Options {
Expand All @@ -143,7 +142,10 @@ pub fn run(options: Options) -> Result<()> {
let plugin_init = format!(".plugin(tauri_plugin_{plugin_snake_case}::{plugin_init_fn})");

let re = Regex::new(r"(tauri\s*::\s*Builder\s*::\s*default\(\))(\s*)").unwrap();
for file in [tauri_dir.join("src/main.rs"), tauri_dir.join("src/lib.rs")] {
for file in [
dirs.tauri.join("src/main.rs"),
dirs.tauri.join("src/lib.rs"),
] {
let contents =
std::fs::read_to_string(&file).fs_context("failed to read Rust entry point", file.clone())?;

Expand All @@ -166,7 +168,7 @@ pub fn run(options: Options) -> Result<()> {
log::info!("Running `cargo fmt`...");
let _ = Command::new("cargo")
.arg("fmt")
.current_dir(tauri_dir)
.current_dir(dirs.tauri)
.status();
}

Expand Down
45 changes: 23 additions & 22 deletions crates/tauri-cli/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::{
error::{Context, ErrorExt},
helpers::{
self,
app_paths::{frontend_dir, tauri_dir},
config::{get as get_config, ConfigMetadata, FrontendDist},
app_paths::Dirs,
config::{get_config, ConfigMetadata, FrontendDist},
},
info::plugins::check_mismatched_packages,
interface::{rust::get_cargo_target_dir, AppInterface, Interface},
Expand Down Expand Up @@ -82,7 +82,7 @@ pub struct Options {
}

pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
crate::helpers::app_paths::resolve();
let dirs = crate::helpers::app_paths::resolve_dirs();

if options.no_sign {
log::warn!("--no-sign flag detected: Signing will be skipped.");
Expand All @@ -99,42 +99,38 @@ pub fn command(mut options: Options, verbosity: u8) -> Result<()> {
let config = get_config(
target,
&options.config.iter().map(|c| &c.0).collect::<Vec<_>>(),
dirs.tauri,
)?;

let mut interface = AppInterface::new(
config.lock().unwrap().as_ref().unwrap(),
options.target.clone(),
)?;

let config_guard = config.lock().unwrap();
let config_ = config_guard.as_ref().unwrap();
let mut interface = AppInterface::new(&config, options.target.clone(), dirs.tauri)?;

setup(&interface, &mut options, config_, false)?;
setup(&interface, &mut options, &config, false, &dirs)?;

if let Some(minimum_system_version) = &config_.bundle.macos.minimum_system_version {
if let Some(minimum_system_version) = &config.bundle.macos.minimum_system_version {
std::env::set_var("MACOSX_DEPLOYMENT_TARGET", minimum_system_version);
}

let app_settings = interface.app_settings();
let interface_options = options.clone().into();

let out_dir = app_settings.out_dir(&interface_options)?;
let out_dir = app_settings.out_dir(&interface_options, dirs.tauri)?;

let bin_path = interface.build(interface_options)?;
let bin_path = interface.build(interface_options, &dirs)?;

log::info!(action ="Built"; "application at: {}", tauri_utils::display_path(bin_path));

let app_settings = interface.app_settings();

if !options.no_bundle && (config_.bundle.active || options.bundles.is_some()) {
if !options.no_bundle && (config.bundle.active || options.bundles.is_some()) {
crate::bundle::bundle(
&options.into(),
verbosity,
ci,
&interface,
&*app_settings,
config_,
&config,
&out_dir,
&dirs,
)?;
}

Expand All @@ -146,21 +142,20 @@ pub fn setup(
options: &mut Options,
config: &ConfigMetadata,
mobile: bool,
dirs: &Dirs,
) -> Result<()> {
let tauri_path = tauri_dir();

// TODO: Maybe optimize this to run in parallel in the future
// see https://github.com/tauri-apps/tauri/pull/13993#discussion_r2280697117
log::info!("Looking up installed tauri packages to check mismatched versions...");
if let Err(error) = check_mismatched_packages(frontend_dir(), tauri_path) {
if let Err(error) = check_mismatched_packages(dirs.frontend, dirs.tauri) {
if options.ignore_version_mismatches {
log::error!("{error}");
} else {
return Err(error);
}
}

set_current_dir(tauri_path).context("failed to set current directory")?;
set_current_dir(dirs.tauri).context("failed to set current directory")?;

let bundle_identifier_source = config
.find_bundle_identifier_overwriter()
Expand Down Expand Up @@ -191,7 +186,13 @@ pub fn setup(
}

if let Some(before_build) = config.build.before_build_command.clone() {
helpers::run_hook("beforeBuildCommand", before_build, interface, options.debug)?;
helpers::run_hook(
"beforeBuildCommand",
before_build,
interface,
options.debug,
dirs.frontend,
)?;
}

if let Some(FrontendDist::Directory(web_asset_path)) = &config.build.frontend_dist {
Expand Down Expand Up @@ -219,7 +220,7 @@ pub fn setup(

// Issue #13287 - Allow the use of target dir inside frontendDist/distDir
// https://github.com/tauri-apps/tauri/issues/13287
let target_path = get_cargo_target_dir(&options.args)?;
let target_path = get_cargo_target_dir(&options.args, dirs.tauri)?;
let mut out_folders = Vec::new();
if let Ok(web_asset_canonical) = dunce::canonicalize(web_asset_path) {
if let Ok(relative_path) = target_path.strip_prefix(&web_asset_canonical) {
Expand Down
35 changes: 19 additions & 16 deletions crates/tauri-cli/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use crate::{
error::{Context, ErrorExt},
helpers::{
self,
app_paths::tauri_dir,
config::{get as get_config, ConfigMetadata},
app_paths::Dirs,
config::{get_config, ConfigMetadata},
updater_signature,
},
interface::{AppInterface, AppSettings, Interface},
Expand Down Expand Up @@ -118,7 +118,7 @@ impl From<crate::build::Options> for Options {
}

pub fn command(options: Options, verbosity: u8) -> crate::Result<()> {
crate::helpers::app_paths::resolve();
let dirs = crate::helpers::app_paths::resolve_dirs();

let ci = options.ci;

Expand All @@ -131,36 +131,31 @@ pub fn command(options: Options, verbosity: u8) -> crate::Result<()> {
let config = get_config(
target,
&options.config.iter().map(|c| &c.0).collect::<Vec<_>>(),
dirs.tauri,
)?;

let interface = AppInterface::new(
config.lock().unwrap().as_ref().unwrap(),
options.target.clone(),
)?;

let tauri_path = tauri_dir();
std::env::set_current_dir(tauri_path).context("failed to set current directory")?;
let interface = AppInterface::new(&config, options.target.clone(), dirs.tauri)?;

let config_guard = config.lock().unwrap();
let config_ = config_guard.as_ref().unwrap();
std::env::set_current_dir(dirs.tauri).context("failed to set current directory")?;

if let Some(minimum_system_version) = &config_.bundle.macos.minimum_system_version {
if let Some(minimum_system_version) = &config.bundle.macos.minimum_system_version {
std::env::set_var("MACOSX_DEPLOYMENT_TARGET", minimum_system_version);
}

let app_settings = interface.app_settings();
let interface_options = options.clone().into();

let out_dir = app_settings.out_dir(&interface_options)?;
let out_dir = app_settings.out_dir(&interface_options, dirs.tauri)?;

bundle(
&options,
verbosity,
ci,
&interface,
&*app_settings,
config_,
&config,
&out_dir,
&dirs,
)
}

Expand All @@ -173,6 +168,7 @@ pub fn bundle<A: AppSettings>(
app_settings: &A,
config: &ConfigMetadata,
out_dir: &Path,
dirs: &Dirs,
) -> crate::Result<()> {
let package_types: Vec<PackageType> = if let Some(bundles) = &options.bundles {
bundles.iter().map(|bundle| bundle.0).collect::<Vec<_>>()
Expand All @@ -198,12 +194,19 @@ pub fn bundle<A: AppSettings>(
before_bundle,
interface,
options.debug,
dirs.frontend,
)?;
}
}

let mut settings = app_settings
.get_bundler_settings(options.clone().into(), config, out_dir, package_types)
.get_bundler_settings(
options.clone().into(),
config,
out_dir,
package_types,
dirs.tauri,
)
.with_context(|| "failed to build bundler settings")?;
settings.set_no_sign(options.no_sign);

Expand Down
Loading
Loading