tauri 在 Ubuntu 下可执行文件太大的问题

问题描述

构建时间较长,文件较大

    Finished dev [unoptimized + debuginfo] target(s) in 24.36s

real    0m24.724s
user    0m10.158s
sys     0m2.687s
ubuntu@VM-12-10-ubuntu:~/test/tauri-app/src-tauri$ ls -lih target/debug/tauri-app
3422467 -rwxrwxr-x 2 ubuntu ubuntu 360M Nov 11 16:41 target/debug/tauri-app

默认参数

https://doc.rust-lang.org/cargo/reference/profiles.html

[profile.dev]
opt-level = 0
debug = true
strip = false #这一句是我补充的
split-debuginfo = '...'  # Platform-specific. 这一句需要删除
debug-assertions = true
overflow-checks = true
lto = false
panic = 'unwind'
incremental = true
codegen-units = 256
rpath = false

优化

只需调整 debug = false,增量编译时间大幅减少,可执行文件也大幅变小:

    Finished dev [unoptimized] target(s) in 11.13s

real    0m11.210s
user    0m7.070s
sys     0m1.560s
ubuntu@VM-12-10-ubuntu:~/test/tauri-app/src-tauri$ ls -lih target/debug/tauri-app
3421917 -rwxrwxr-x 2 ubuntu ubuntu 26M Nov 11 16:29 target/debug/tauri-app

在此基础上设置 strip = true,得到更进一步优化:

    Finished dev [unoptimized] target(s) in 10.62s

real    0m10.699s
user    0m6.939s
sys     0m1.656s
ubuntu@VM-12-10-ubuntu:~/test/tauri-app/src-tauri$ ls -lih target/debug/tauri-app
3422828 -rwxrwxr-x 2 ubuntu ubuntu 16M Nov 11 16:35 target/debug/tauri-app
ubuntu@VM-12-10-ubuntu:~/test/tauri-app/src-tauri$ 

所以最终我们设置:

[profile.dev]
opt-level = 0 #没有优化
debug = 0 #没有调试信息
strip = true #删除符号或调试信息
lto = false #禁用代码优化

忽略 Rust 项目更改

如果不希望 tauri 频繁编译,可以忽略 Rust 项目,此时前端代码更改仍然可以热重载。

npx tauri dev --no-watch
posted @ 2022-11-11 16:34  develon  阅读(97)  评论(0编辑  收藏  举报