Skip to content

Commit f76b1d3

Browse files
feat(bundler): show bundle sizes in the finished output (#15644)
* feat(bundler): show bundle sizes in the finished output Append a human-readable size to each bundle path in the "Finished N bundles at:" log, so the sizes are visible right after `tauri build` instead of having to look them up manually. Directory bundles (e.g. macOS `.app`) are measured recursively. Closes #15341 * chore: include tauri-cli in changefile * refactor(bundler): use human_bytes crate for size formatting * Also `@tauri-apps/cli` * Change to use bytesize for 2 digit precisions And fail instead of reporting partial sizes --------- Co-authored-by: Tony <legendmastertony@gmail.com>
1 parent 30fa4e4 commit f76b1d3

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎.changes/bundler-show-sizes.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri-bundler": "minor:feat"
3+
"tauri-cli": "minor:feat"
4+
"@tauri-apps/cli": "minor:feat"
5+
---
6+
7+
The bundler now prints the size of each generated bundle next to its path in the `Finished N bundles at:` output (directories such as macOS `.app` bundles are measured recursively).

‎Cargo.lock‎

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/tauri-bundler/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ serde = { version = "1", features = ["derive"] }
2727
strsim = "0.11"
2828
tar = "0.4"
2929
walkdir = "2"
30+
bytesize = "2"
3031
handlebars = "6"
3132
tempfile = "3"
3233
log = { version = "0.4.21", features = ["kv"] }

‎crates/tauri-bundler/src/bundle.rs‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mod windows;
1616

1717
use crate::error::ErrorExt;
1818
use anyhow::Context;
19+
use bytesize::ByteSize;
1920
use std::{
2021
fmt::Write,
2122
io::{Seek, SeekFrom},
@@ -290,7 +291,10 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<Bundle>> {
290291
""
291292
};
292293
let path_display = display_path(path);
293-
writeln!(printable_paths, " {path_display}{note}").unwrap();
294+
let size = bundle_size(path)
295+
.map(|bytes| format!(" ({:.2})", ByteSize::b(bytes).display()))
296+
.unwrap_or_default();
297+
writeln!(printable_paths, " {path_display}{note}{size}").unwrap();
294298
}
295299
}
296300

@@ -299,6 +303,20 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<Bundle>> {
299303
Ok(bundles)
300304
}
301305

306+
/// Total size in bytes of a bundle path, recursing into directories (e.g. macOS `.app`).
307+
fn bundle_size(path: &std::path::Path) -> crate::Result<u64> {
308+
let metadata = std::fs::symlink_metadata(path)?;
309+
if metadata.is_dir() {
310+
let mut total = 0;
311+
for entry in walkdir::WalkDir::new(path) {
312+
total += entry?.metadata()?.len();
313+
}
314+
Ok(total)
315+
} else {
316+
Ok(metadata.len())
317+
}
318+
}
319+
302320
fn sign_binaries_if_needed(settings: &Settings, target_os: &TargetPlatform) -> crate::Result<()> {
303321
if matches!(target_os, TargetPlatform::Windows) {
304322
if settings.windows().can_sign() {

0 commit comments

Comments
 (0)