Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a new option to remove unused commands #12890

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from

Conversation

Legend-Master
Copy link
Contributor

@Legend-Master Legend-Master commented Mar 4, 2025

Reference: #12820 (comment)

Introducing a new CLI option --remove-unused-commands on build command to pass in an environment variable to let the build script of tauri-plugin and tauri to generate a list of allowed commands from the ACL, this will then be used by the generate_handler macro to remove unused commands

Note: this won't be accounting for dynamically added ACLs so make sure to check it when using this
Note: didn't do this for tauri-build yet, so inlined plugins and the app's generate_handler won't be affected yet

Some results:

  • Release build of the helloworld example in the repo gone from 3.92 MB to 1.91 MB on Windows (it doesn't use any plugin commands, so the improvement is quite big, also the basic executable contains the image dependency, it's around 2.67 MB if that's removed, but still a great improvement!)

Copy link
Contributor

github-actions bot commented Mar 4, 2025

Package Changes Through a9dead4

There are 11 changes which include tauri with minor, @tauri-apps/api with minor, tauri-runtime-wry with minor, tauri-bundler with patch, tauri-cli with minor, @tauri-apps/cli with patch, tauri-build with minor, tauri-codegen with minor, tauri-macros with minor, tauri-plugin with minor, tauri-utils 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-apps/api 2.3.0 2.4.0
tauri-utils 2.2.0 2.3.0
tauri-bundler 2.2.4 2.2.5
tauri-runtime 2.4.0 2.4.1
tauri-runtime-wry 2.4.1 2.5.0
tauri-codegen 2.0.5 2.1.0
tauri-macros 2.0.5 2.1.0
tauri-plugin 2.0.5 2.1.0
tauri-build 2.0.6 2.1.0
tauri 2.3.1 2.4.0
@tauri-apps/cli 2.3.1 2.3.2
tauri-cli 2.3.1 2.4.0

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


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

@WSH032
Copy link
Contributor

WSH032 commented Mar 4, 2025

Hi @Legend-Master (I stumbled upon this PR 😇).

Can we implement this feature in build.rs or as cargo features instead of tauri-cli?

Sometimes I only use cargo build --features tauri/custom-protocol instead of tauri build.

ref: #4670 (comment)

Additionally, the regular Tauri development process heavily relies on Tauri-Cli to generate executables. However, for Pyo3 bindings, dynamic libraries (.so/.dll/.dylib) are required, so we cannot use Tauri-Cli and must use cargo build instead.

@Legend-Master
Copy link
Contributor Author

Legend-Master commented Mar 4, 2025

I have tried it first before this and unfortunately since we can't run the build script before all the macros in plugins, it's not really viable

I could expose the command for generating the used commands though so that you can run it first and then exposing it to the environment manually

@WSH032
Copy link
Contributor

WSH032 commented Mar 4, 2025

I could expose the command for generating the used commands though so that you can run it first and then exposing it to the environment manually.

In some cases, we don't even have tauri-cli 😥, and cargo is the only tool available.

since we can't run the build script before all the macros in plugins

Can we set an environment variable pointing to the capabilities files and then parse the allowed commands in the generate_handler! macro within the plugins?

This way, we wouldn't need to rely on tauri-cli to generate allowed-commands.json.

When I want to enable this feature, I will manually set this environment variable pointing to the capabilities.

(I'm not very familiar with this part of Tauri, so my idea might be wrong)

@Legend-Master
Copy link
Contributor Author

In some cases, we don't even have tauri-cli 😥, and cargo is the only tool available.

I would also like to make those features not relying on the tauri cli if possible

Can we set an environment variable pointing to the capabilities files and then parse the allowed commands in the generate_handler! macro within the plugins?

Actually good idea, I'll give it a try when I got time, but instead of doing it in the macro, I think in plugins's build script should be better? (I'll see when I get there)

My current approach is not that great as it relies on the build scripts to generate the acl manifest first, so definitely something I would like to improve as well

(I'm not very familiar with this part of Tauri, so my idea might be wrong)

To be honest, I'm not very familiar with acl and macro related things either, so any suggestion would be much appreciated

@Legend-Master Legend-Master marked this pull request as ready for review March 6, 2025 07:32
@Legend-Master Legend-Master requested review from a team as code owners March 6, 2025 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📬Proposal
Development

Successfully merging this pull request may close these issues.

2 participants