Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Improve Linux binary size (#65169)
Kirill Bulatovd6b7f24b7b86
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex b87f1858eb9..c9aea2386dc 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -404,8 +404,8 @@ jobs:run: ./script/linux- name: steps::download_wasi_sdkrun: ./script/download-wasi-sdk- - name: ./script/bundle-linux- run: ./script/bundle-linux+ - name: ./script/bundle-linux --require-sentry+ run: ./script/bundle-linux --require-sentry- name: run_bundling::upload_artifactuses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0awith:@@ -449,8 +449,8 @@ jobs:run: ./script/linux- name: steps::download_wasi_sdkrun: ./script/download-wasi-sdk- - name: ./script/bundle-linux- run: ./script/bundle-linux+ - name: ./script/bundle-linux --require-sentry+ run: ./script/bundle-linux --require-sentry- name: run_bundling::upload_artifactuses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0awith:diff --git a/.github/workflows/release_nightly.yml b/.github/workflows/release_nightly.ymlindex 1652e104b6b..c8f47291fcf 100644--- a/.github/workflows/release_nightly.yml+++ b/.github/workflows/release_nightly.yml@@ -129,8 +129,8 @@ jobs:run: ./script/linux- name: steps::download_wasi_sdkrun: ./script/download-wasi-sdk- - name: ./script/bundle-linux- run: ./script/bundle-linux+ - name: ./script/bundle-linux --require-sentry+ run: ./script/bundle-linux --require-sentry- name: run_bundling::upload_artifactuses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0awith:@@ -178,8 +178,8 @@ jobs:run: ./script/linux- name: steps::download_wasi_sdkrun: ./script/download-wasi-sdk- - name: ./script/bundle-linux- run: ./script/bundle-linux+ - name: ./script/bundle-linux --require-sentry+ run: ./script/bundle-linux --require-sentry- name: run_bundling::upload_artifactuses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0awith:diff --git a/script/bundle-linux b/script/bundle-linuxindex 017fb99cc0e..0d6f5fbfbfa 100755--- a/script/bundle-linux+++ b/script/bundle-linux@@ -10,11 +10,16 @@ Usage: ${0##*/} [options]Build a release .tar.gz for Linux.Options:- -h, --help Display this help and exit.- --flatpak Set ZED_BUNDLE_TYPE=flatpak so that this can be included in system info+ -h, --help Display this help and exit.+ --flatpak Set ZED_BUNDLE_TYPE=flatpak so that this can be included in system info+ --require-sentry Require Sentry credentials, CLI, and successful symbol upload (official releases).+ --skip-sentry Skip symbol upload for local packaging; incompatible with --require-sentry."}+require_sentry=false+skip_sentry=false+# Parse all arguments manuallywhile [[ $# -gt 0 ]]; docase $1 in@@ -26,6 +31,14 @@ while [[ $# -gt 0 ]]; doexport ZED_BUNDLE_TYPE=flatpakshift;;+ --require-sentry)+ require_sentry=true+ shift+ ;;+ --skip-sentry)+ skip_sentry=true+ shift+ ;;--)shiftbreak@@ -48,6 +61,30 @@ if [[ -n "${RUSTFLAGS+x}" || -n "${CARGO_ENCODED_RUSTFLAGS+x}" ]]; thenexit 1fi+if "$require_sentry" && "$skip_sentry"; then+ echo "--require-sentry and --skip-sentry cannot be used together." >&2+ exit 1+fi++if "$skip_sentry"; then+ echo "Skipping Sentry upload for local packaging."+elif ! command -v sentry-cli >/dev/null 2>&1; then+ if "$require_sentry"; then+ echo "Official Linux releases require sentry-cli for symbol upload." >&2+ exit 1+ fi+ echo "sentry-cli not found. skipping sentry upload."+ echo "install with: 'curl -sL https://sentry.io/get-cli | bash'"+ skip_sentry=true+elif [[ -z "${SENTRY_AUTH_TOKEN:+set}" ]]; then+ if "$require_sentry"; then+ echo "Official Linux releases require SENTRY_AUTH_TOKEN for symbol upload." >&2+ exit 1+ fi+ echo "missing SENTRY_AUTH_TOKEN. skipping sentry upload."+ skip_sentry=true+fi+export ZED_BUNDLE=truechannel=$(<crates/zed/RELEASE_CHANNEL)@@ -77,9 +114,16 @@ if "$rustup_installed"; thenfiexport CC=${CC:-$(which clang)}+lld=$("$CC" -print-prog-name=ld.lld)+lld_version=$("$lld" --version)+if [[ ! "$lld_version" =~ LLD\ ([0-9]+)\. ]] || (( BASH_REMATCH[1] < 12 )); then+ echo "Bundling requires LLD 12 or newer for safe ICF; select a matching compiler with CC (e.g. CC=clang-18)." >&2+ exit 1+fi# Build binary in release mode-cargo --config .cargo/bundle-config.toml build --release --target "${target_triple}" --package zed --package cli+cargo --config .cargo/bundle-config.toml rustc --release --target "${target_triple}" --package zed --bin zed -- -C linker="$CC" -C llvm-args=-addrsig -C link-arg=-fuse-ld=lld -C link-arg=-Wl,--icf=safe+cargo --config .cargo/bundle-config.toml build --release --target "${target_triple}" --package cli# Build remote_server in separate invocation to prevent feature unification from other crates# from influencing dynamic libraries required by it.if [[ "$remote_server_triple" == "$musl_triple" ]]; then@@ -88,32 +132,24 @@ if [[ "$remote_server_triple" == "$musl_triple" ]]; thenficargo --config .cargo/bundle-config.toml build --release --target "${remote_server_triple}" --package remote_server-# Upload debug info to sentry.io-if ! command -v sentry-cli >/dev/null 2>&1; then- echo "sentry-cli not found. skipping sentry upload."- echo "install with: 'curl -sL https://sentry.io/get-cli | bash'"-else- if [[ -n "${SENTRY_AUTH_TOKEN:-}" ]]; then- echo "Uploading zed debug symbols to sentry..."- # note: this uploads the unstripped binary which is needed because it contains- # .eh_frame data for stack unwinding. see https://github.com/getsentry/symbolic/issues/783- for attempt in 1 2 3; do- echo "Attempting sentry upload (attempt $attempt/3)..."- if sentry-cli debug-files upload --include-sources --wait -p zed -o zed-dev \- "${target_dir}/${target_triple}"/release/zed \- "${target_dir}/${remote_server_triple}"/release/remote_server; then- echo "Sentry upload successful on attempt $attempt"- break- else- echo "Sentry upload failed on attempt $attempt"- if [ $attempt -eq 3 ]; then- echo "All sentry upload attempts failed"- fi- fi- done- else- echo "missing SENTRY_AUTH_TOKEN. skipping sentry upload."- fi+if ! "$skip_sentry"; then+ echo "Uploading zed debug symbols to sentry..."+ # Sentry needs the full ELF for .eh_frame unwinding, not just the debug+ # companion. See https://github.com/getsentry/symbolic/issues/783.+ for attempt in 1 2 3; do+ echo "Attempting sentry upload (attempt $attempt/3)..."+ if sentry-cli debug-files upload --include-sources --wait -p zed -o zed-dev \+ "${target_dir}/${target_triple}"/release/zed \+ "${target_dir}/${remote_server_triple}"/release/remote_server; then+ echo "Sentry upload successful on attempt $attempt"+ break+ fi+ echo "Sentry upload failed on attempt $attempt" >&2+ if [ "$attempt" -eq 3 ]; then+ echo "All sentry upload attempts failed; refusing to package binaries without uploaded symbols." >&2+ exit 1+ fi+ donefi# Split debug symbols into local .dbg files, then strip debug info and local@@ -124,9 +160,6 @@ fi# doesn't understand CREL sections produced by newer LLVM.llvm-objcopy --only-keep-debug "${target_dir}/${target_triple}/release/zed" "${target_dir}/${target_triple}/release/zed.dbg"llvm-objcopy --only-keep-debug "${target_dir}/${remote_server_triple}/release/remote_server" "${target_dir}/${remote_server_triple}/release/remote_server.dbg"-llvm-objcopy --strip-debug --discard-all "${target_dir}/${target_triple}/release/zed"-llvm-objcopy --strip-debug --discard-all "${target_dir}/${target_triple}/release/cli"-llvm-objcopy --strip-debug --discard-all "${target_dir}/${remote_server_triple}/release/remote_server"# Ensure that remote_server does not depend on libssl nor libcrypto, as we got rid of these deps.if ldd "${target_dir}/${remote_server_triple}/release/remote_server" | grep -q 'libcrypto\|libssl'; then@@ -145,12 +178,15 @@ fi# Move everything that should end up in the final package# into a temp directory.temp_dir=$(mktemp -d)+trap 'rm -rf "$temp_dir"' EXITzed_dir="${temp_dir}/zed$suffix.app"-# Binary+# Cargo may reuse its outputs on the next invocation. Strip packaging copies+# so reruns still upload full ELFs and extract complete debug companions.mkdir -p "${zed_dir}/bin" "${zed_dir}/libexec"-cp "${target_dir}/${target_triple}/release/zed" "${zed_dir}/libexec/zed-editor"-cp "${target_dir}/${target_triple}/release/cli" "${zed_dir}/bin/zed"+llvm-objcopy --strip-unneeded "${target_dir}/${target_triple}/release/zed" "${zed_dir}/libexec/zed-editor"+llvm-objcopy --strip-debug --discard-all "${target_dir}/${target_triple}/release/cli" "${zed_dir}/bin/zed"+llvm-objcopy --strip-debug --discard-all "${target_dir}/${remote_server_triple}/release/remote_server" "${temp_dir}/remote_server"# Libs# Bundle libstdc++ so older supported systems can run binaries built with our@@ -211,4 +247,4 @@ remove_match="zed(-[a-zA-Z0-9]+)?-linux-$(uname -m)\.tar\.gz"ls "${target_dir}/release" | grep -E ${remove_match} | xargs -d "\n" -I {} rm -f "${target_dir}/release/{}" || truetar -czvf "${target_dir}/release/$archive" -C ${temp_dir} "zed$suffix.app"-gzip -f --stdout --best "${target_dir}/${remote_server_triple}/release/remote_server" > "${target_dir}/zed-remote-server-linux-${arch}.gz"+gzip -f --stdout --best "${temp_dir}/remote_server" > "${target_dir}/zed-remote-server-linux-${arch}.gz"diff --git a/script/linux b/script/linuxindex f7445e43e2c..a2b0499d585 100755--- a/script/linux+++ b/script/linux@@ -76,7 +76,7 @@ if [[ -n $apt ]]; thencurl -fsSL 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x1E9377A2BA9EF27F' | \sed -n '/-----BEGIN PGP PUBLIC KEY BLOCK-----/,/-----END PGP PUBLIC KEY BLOCK-----/p' | \$maysudo gpg --dearmor -o /etc/apt/trusted.gpg.d/ubuntu-toolchain-r-test.gpg- deps+=( clang-18 libstdc++-11-dev )+ deps+=( clang-18 lld-18 libstdc++-11-dev )fi$maysudo "$apt" update@@ -97,6 +97,7 @@ if [[ -n $dnf ]] || [[ -n $yum ]]; thenmusl-gccgccclang+ lldcmakealsa-lib-develfontconfig-devel@@ -163,6 +164,7 @@ if [[ -n $zyp ]]; thendeps=(alsa-develclang+ lldcmakefontconfig-develgcc@@ -199,6 +201,7 @@ if [[ -n $pacman ]]; thendeps=(gccclang+ lldmuslcmakealsa-lib@@ -230,6 +233,7 @@ if [[ -n $xbps ]]; thendeps=(gettext-develclang+ lldcmakejqelfutils-devel@@ -264,6 +268,7 @@ if [[ -n $emerge ]]; thendev-libs/openssldev-libs/waylanddev-build/cmake+ llvm-core/lldmedia-libs/alsa-libmedia-libs/fontconfigmedia-libs/libvadiff --git a/tooling/xtask/src/tasks/workflows/release.rs b/tooling/xtask/src/tasks/workflows/release.rsindex 0b75268bc9c..da7fb4d9c07 100644--- a/tooling/xtask/src/tasks/workflows/release.rs+++ b/tooling/xtask/src/tasks/workflows/release.rs@@ -33,11 +33,13 @@ pub(crate) fn release() -> Workflow {linux_aarch64: bundle_linux(Arch::AARCH64,None,+ true,&[&linux_tests, &linux_clippy, &check_scripts],),linux_x86_64: bundle_linux(Arch::X86_64,None,+ true,&[&linux_tests, &linux_clippy, &check_scripts],),bwrap_linux_aarch64: build_static_bwrap(diff --git a/tooling/xtask/src/tasks/workflows/release_nightly.rs b/tooling/xtask/src/tasks/workflows/release_nightly.rsindex 2ec04776ecc..97bad59ad1e 100644--- a/tooling/xtask/src/tasks/workflows/release_nightly.rs+++ b/tooling/xtask/src/tasks/workflows/release_nightly.rs@@ -31,8 +31,8 @@ pub fn release_nightly() -> Workflow {const NIGHTLY: Option<ReleaseChannel> = Some(ReleaseChannel::Nightly);let bundle = ReleaseBundleJobs {- linux_aarch64: bundle_linux(Arch::AARCH64, NIGHTLY, &[&tests]),- linux_x86_64: bundle_linux(Arch::X86_64, NIGHTLY, &[&tests]),+ linux_aarch64: bundle_linux(Arch::AARCH64, NIGHTLY, true, &[&tests]),+ linux_x86_64: bundle_linux(Arch::X86_64, NIGHTLY, true, &[&tests]),bwrap_linux_aarch64: build_static_bwrap(Arch::AARCH64, &[&tests]),bwrap_linux_x86_64: build_static_bwrap(Arch::X86_64, &[&tests]),mac_aarch64: bundle_mac(Arch::AARCH64, NIGHTLY, &[&tests]),diff --git a/tooling/xtask/src/tasks/workflows/run_bundling.rs b/tooling/xtask/src/tasks/workflows/run_bundling.rsindex 6fc34c9d775..07b5aadb08f 100644--- a/tooling/xtask/src/tasks/workflows/run_bundling.rs+++ b/tooling/xtask/src/tasks/workflows/run_bundling.rs@@ -16,8 +16,8 @@ use indoc::indoc;pub fn run_bundling() -> Workflow {let bundle = ReleaseBundleJobs {- linux_aarch64: bundle_linux(Arch::AARCH64, None, &[]),- linux_x86_64: bundle_linux(Arch::X86_64, None, &[]),+ linux_aarch64: bundle_linux(Arch::AARCH64, None, false, &[]),+ linux_x86_64: bundle_linux(Arch::X86_64, None, false, &[]),bwrap_linux_aarch64: build_static_bwrap(Arch::AARCH64, &[]),bwrap_linux_x86_64: build_static_bwrap(Arch::X86_64, &[]),mac_aarch64: bundle_mac(Arch::AARCH64, None, &[]),@@ -166,6 +166,7 @@ pub(crate) fn build_static_bwrap(arch: Arch, deps: &[&NamedJob]) -> NamedJob {pub(crate) fn bundle_linux(arch: Arch,release_channel: Option<ReleaseChannel>,+ require_sentry: bool,deps: &[&NamedJob],) -> NamedJob {let platform = Platform::Linux;@@ -191,7 +192,11 @@ pub(crate) fn bundle_linux(}).add_step(steps::setup_sentry()).map(steps::install_linux_dependencies)- .add_step(steps::script("./script/bundle-linux"))+ .add_step(steps::script(if require_sentry {+ "./script/bundle-linux --require-sentry"+ } else {+ "./script/bundle-linux"+ })).add_step(upload_artifact(&format!("target/release/{artifact_name}"))).add_step(upload_artifact(&format!("target/{remote_server_artifact_name}"