Skip to content

Conversation

@sftse
Copy link
Contributor

@sftse sftse commented Dec 17, 2025

Work on refactoring the globals in tauri-cli. I think this is beneficial as-is, but it is not quite finished.

This still is missing a full transition towards lazy initialized tauri_dir and frontend_dir while guaranteeing not to break anything, as discussed in this comment.
Completed.

Read commit-by-commit.

@sftse sftse requested a review from a team as a code owner December 17, 2025 15:31
@github-project-automation github-project-automation bot moved this to 📬Proposal in Roadmap Dec 17, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 17, 2025

Package Changes Through 1ee20a9

There are 8 changes which include tauri-utils with patch, tauri-build with patch, tauri-cli with patch, tauri-macos-sign with patch, @tauri-apps/cli with patch, tauri-runtime-wry with minor, tauri-runtime with minor, tauri with minor

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tauri-utils 2.8.1 2.8.2
tauri-macos-sign 2.3.2 2.3.3
tauri-bundler 2.7.5 2.7.6
tauri-runtime 2.9.2 2.10.0
tauri-runtime-wry 2.9.3 2.10.0
tauri-codegen 2.5.2 2.5.3
tauri-macros 2.5.2 2.5.3
tauri-plugin 2.5.2 2.5.3
tauri-build 2.5.3 2.5.4
tauri 2.9.5 2.10.0
@tauri-apps/cli 2.9.6 2.9.7
tauri-cli 2.9.6 2.9.7

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@sftse
Copy link
Contributor Author

sftse commented Dec 18, 2025

Any chance to run CI automatically on my PRs? Would make iteration much faster, I often miss things built only on other platforms.

@FabianLars
Copy link
Member

Any chance to run CI automatically on my PRs? Would make iteration much faster, I often miss things built only on other platforms.

That decision will probably take longer to discuss than your pr will be open x)

@sftse sftse force-pushed the less-statics branch 2 times, most recently from ee5a7b4 to a1b4415 Compare December 19, 2025 22:19
@sftse
Copy link
Contributor Author

sftse commented Dec 19, 2025

This is RFR

@sftse
Copy link
Contributor Author

sftse commented Dec 21, 2025

@FabianLars
I put effort into readable commits that compile individually. High-latency round trips reduce the quality of my contributions, here the last commits merge multiple unrelated things because it takes way too long to figure out what is related.

RFR

@sftse
Copy link
Contributor Author

sftse commented Dec 21, 2025

Fixed next errors

@FabianLars
Copy link
Member

I put effort into readable commits that compile individually. High-latency round trips reduce the quality of my contributions, here the last commits merge multiple unrelated things because it takes way too long to figure out what is related.

Yeah i totally get that. GitHub only offers us 2 options: Auto run workflows for everyone or only for those with write permissions. There's no way to give individuals workflow permissions without also giving write access to the repo. All in all very annoying.

You could however enable workflow runs in your own fork (free of charge since it's open source) and open a second PR from your branch against your own fork's dev branch.

@sftse
Copy link
Contributor Author

sftse commented Dec 22, 2025

You could however enable workflow runs in your own fork (free of charge since it's open source) and open a second PR from your branch against your own fork's dev branch.

Didn't think of that, I'm not familiar with the workflows.
I might take that for a spin, thanks.

@FabianLars
Copy link
Member

whoops sorry, didn't mean to click on button...

@sftse
Copy link
Contributor Author

sftse commented Dec 28, 2025

To add more context to this PR, it's a bit tersely described, there is an overuse of statics in the code base which lead to verbose code patterns like Mutex<Option<ConfigMetadata>> or OnceLock<Mutex<ConfigMetadata>> to initialize the config in the static. This is better solved with locals, and in most cases successfully removes both the Mutex and the Option, replacing it with just ConfigMetadata. Leaning more heavily into borrowing reduces the chance for deadlocks.

In quantitative terms, this change removes 43% (76/178) of all unwraps in the tauri-cli crate.
It might be possible to remove all statics and further reduce the scope where Mutexes are used, but that's how far I got.

@sftse sftse force-pushed the less-statics branch 3 times, most recently from 6e3672f to 93401e3 Compare December 29, 2025 17:47
@sftse
Copy link
Contributor Author

sftse commented Jan 1, 2026

Fixed CI

@Legend-Master
Copy link
Contributor

Sorry about the late reply. I am a bit skeptical about this change since this means we now need to pass those arguments all the way down

The dependency is much more clear though, but I honestly wonder if that really makes a difference if we always initialize the config and directories at he beginning of a command

@sftse
Copy link
Contributor Author

sftse commented Jan 11, 2026

I don't disagree that the amount of arguments passed to some functions is starting to get unwieldy. I think we can do something about it by redrawing the function boundaries but this PR had to make a judgement call whether to stop at a point where it is still reasonably obvious that the behavior hasn't changed or to continue with less conservative changes.

but I honestly wonder if that really makes a difference if we always initialize the config and directories at he beginning of a command

We actually don't, see the resolve command in info/mod.rs wrapped in an if block. Not that I'd have been able to guess it from just reading the code, but that block is always useless since the path is never read from the global after that. The config too is initialized in a more different way than the other commands.

I think the code is much more defensive this way, apart from the substantial reduction of unwraps, it also increases the confidence there are no deadlocks. The pattern of having a mutex in a static is always a bit dangerous, because it can always be accessed and locked from anywhere, and it isn't clear if it has been locked in a parent scope. If we refactor to remove the locks it is a static proof we don't have any deadlocks. Other mutexes that are not in a static coupled with callbacks already led to deadlocks before, see #14694

@Legend-Master
Copy link
Contributor

I am much more convinced now, thanks for the explanation

Looking back, I had quite a few times struggling to understand where is a function looking the directories from, this is definitely a good improvement

Copy link
Contributor

@Legend-Master Legend-Master left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from an initial look

My monitor's in repair right now and it's really difficult for me to look at the huge diffs, so this may need to wait until then

Also cc @FabianLars @lucasfernog what you guys think of about this change?

Copy link
Contributor

@Legend-Master Legend-Master left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking at the code more closely, this is definitely a great improvement to readability, awesome work!

So happy my monitor's finally back today 😁

@Legend-Master Legend-Master merged commit 7f7d9aa into tauri-apps:dev Jan 17, 2026
16 checks passed
@github-project-automation github-project-automation bot moved this from 📬Proposal to 🔎 In audit in Roadmap Jan 17, 2026
@sftse
Copy link
Contributor Author

sftse commented Jan 17, 2026

As always, thanks for taking the time to review my PRs, much appreciated.

More coming up soon..

@sftse sftse deleted the less-statics branch January 17, 2026 16:21
lucasfernog added a commit that referenced this pull request Jan 21, 2026
regression from #14668
when running the tauri CLI via cargo, the CWD is changed by the xcode-script command - moves from src-tauri/gen/apple to src-tauri so the CLI can resolve the app path properly
resolving early breaks this, so we must be careful with the #14668 change
iamxiaojianzheng pushed a commit to iamxiaojianzheng/tauri that referenced this pull request Jan 26, 2026
* refactor(tauri-cli): introduce replacement functions

* refactor(tauri-cli): apply replacement to remove.rs

* refactor(tauri-cli): apply replacement to icon.rs

* refactor(tauri-cli): apply replacement to bundle.rs

* refactor(tauri-cli): apply replacement to build.rs

* refactor(tauri-cli): apply replacement to add.rs

* refactor(tauri-cli): apply replacement to dev.rs

* refactor(tauri-cli): less controlflow

* refactor(tauri-cli): split config loading from locking static

* refactor(tauri-cli): remove duplicate checks covered by if let Some(tauri_dir) = tauri_dir

tauri_dir.is_some() must be true, otherwise the entire block is not run, so the frontend_dir check
is irrelevant

* fmt

* refactor(tauri-cli): apply replacement to inspect.rs

* refactor(tauri-cli): dont use statics for config

* refactor(tauri-cli): finish threading directory paths through functions

* fix: clippy

* fixup CI

* refactor(tauri-cli): dont need mutex

* refactor(tauri-cli): rescope mutex use to minimal necessary

* fix CI, reduce mutex use

* fixup PR tauri-apps#14607

* fix: clippy

* refactor(tauri-cli): remove ConfigHandle

* refactor(tauri-cli): remove more unwraps and panicing functions

* refactor(tauri-cli): less mutexes

* refactor(tauri-cli): undo mistaken change, address review comment

* Split android build to 2 functions

* Pass in dirs to migration v1 like the v2 beta

* Add change file

---------

Co-authored-by: Tony <[email protected]>
@sftse sftse mentioned this pull request Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 In audit

Development

Successfully merging this pull request may close these issues.

3 participants