Reduce release binary sizes (#65168)

Not sure how worth such optimization is WRT the speed, but for such
gains, seems worth opening to discuss?

-----------

Optimize selected workspace crates for size and hide Rust exports in
macOS bundles.

Measurements (release editor executable size):

| Platform | Architecture | Before (bytes) | After (bytes) | Reduction
(bytes / %) |
| --- | --- | ---: | ---: | ---: |
| macOS | ARM64 | 258,218,240 | 172,524,896 | 85,693,344 / 33.19% |
| Linux | x86_64 | 317,435,136 | 295,344,952 | 22,090,184 / 6.96% |
| Windows | x86_64 | 358,987,776 | 256,678,400 | 102,309,376 / 28.50% |


Release Notes:

- Reduced Zed's binary size
This commit is contained in:
Kirill Bulatov 2026-10-07 14:56:09 +00:00 • committed by GitHub
parent 83b332342f
commit 976ab33fb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View file

@ -1,3 +1,29 @@
[profile.release]
opt-level = "z"
[profile.release.package]
"*" = { opt-level = 3 }
cli = { opt-level = 3 }
editor = { opt-level = 3 }
gpui = { opt-level = 3 }
gpui_apple = { opt-level = 3 }
gpui_linux = { opt-level = 3 }
gpui_macos = { opt-level = 3 }
gpui_platform = { opt-level = 3 }
gpui_shared_string = { opt-level = 3 }
gpui_util = { opt-level = 3 }
gpui_wgpu = { opt-level = 3 }
gpui_windows = { opt-level = 3 }
language = { opt-level = 3 }
multi_buffer = { opt-level = 3 }
project = { opt-level = 3 }
remote_server = { opt-level = 3 }
rope = { opt-level = 3 }
scheduler = { opt-level = 3 }
sum_tree = { opt-level = 3 }
text = { opt-level = 3 }
zed = { codegen-units = 1 }
[target.'cfg(target_os = "linux")']
rustflags = ["-C", "link-args=-Wl,--disable-new-dtags,-rpath,$ORIGIN/../lib"]

View file

@ -91,7 +91,12 @@ script/generate-licenses
rustup target add $target_triple
echo "Compiling zed binaries"
cargo --config .cargo/bundle-config.toml build ${build_flag} ${zed_features} --package zed --package cli --target $target_triple
if [[ "$target_dir" = "release" ]]; then
cargo --config .cargo/bundle-config.toml rustc ${build_flag} ${zed_features} --package zed --bin zed --target $target_triple -- -C 'link-arg=-Wl,-unexported_symbol,__R*'
cargo --config .cargo/bundle-config.toml build ${build_flag} --package cli --target $target_triple
else
cargo --config .cargo/bundle-config.toml build ${build_flag} ${zed_features} --package zed --package cli --target $target_triple
fi
# Build remote_server in separate invocation to prevent feature unification from other crates
# from influencing dynamic libraries required by it.
cargo --config .cargo/bundle-config.toml build ${build_flag} ${remote_server_features} --package remote_server --target $target_triple