bundle-linux

  1#!/usr/bin/env bash
  2
  3set -euxo pipefail
  4source script/lib/blob-store.sh
  5source script/lib/sentry-upload.sh
  6
  7# Function for displaying help info
  8help_info() {
  9  echo "
 10Usage: ${0##*/} [options]
 11Build a release .tar.gz for Linux.
 12
 13Options:
 14  -h, --help     Display this help and exit.
 15  --flatpak      Set ZED_BUNDLE_TYPE=flatpak so that this can be included in system info
 16  "
 17}
 18
 19# Parse all arguments manually
 20while [[ $# -gt 0 ]]; do
 21    case $1 in
 22        -h|--help)
 23            help_info
 24            exit 0
 25            ;;
 26        --flatpak)
 27            export ZED_BUNDLE_TYPE=flatpak
 28            shift
 29            ;;
 30        --)
 31            shift
 32            break
 33            ;;
 34        -*)
 35            echo "Unknown option: $1" >&2
 36            help_info
 37            exit 1
 38            ;;
 39        *)
 40            echo "Error: Unexpected argument: $1" >&2
 41            help_info
 42            exit 1
 43            ;;
 44    esac
 45done
 46
 47export ZED_BUNDLE=true
 48
 49channel=$(<crates/zed/RELEASE_CHANNEL)
 50target_dir="${CARGO_TARGET_DIR:-target}"
 51
 52version="$(script/get-crate-version zed)"
 53# Set RELEASE_VERSION so it's compiled into GPUI and it knows about the version.
 54export RELEASE_VERSION="${version}"
 55
 56commit=$(git rev-parse HEAD | cut -c 1-7)
 57
 58version_info=$(rustc --version --verbose)
 59host_line=$(echo "$version_info" | grep host)
 60target_triple=${host_line#*: }
 61musl_triple=${target_triple%-gnu}-musl
 62remote_server_triple=${REMOTE_SERVER_TARGET:-"${musl_triple}"}
 63rustup_installed=false
 64if command -v rustup >/dev/null 2>&1; then
 65    rustup_installed=true
 66fi
 67
 68# Generate the licenses first, so they can be baked into the binaries
 69script/generate-licenses
 70
 71if "$rustup_installed"; then
 72    rustup target add "$remote_server_triple"
 73fi
 74
 75export CC=${CC:-$(which clang)}
 76
 77# Build binary in release mode
 78export RUSTFLAGS="${RUSTFLAGS:-} -C link-args=-Wl,--disable-new-dtags,-rpath,\$ORIGIN/../lib"
 79cargo build --release --target "${target_triple}" --package zed --package cli
 80# Build remote_server in separate invocation to prevent feature unification from other crates
 81# from influencing dynamic libraries required by it.
 82if [[ "$remote_server_triple" == "$musl_triple" ]]; then
 83    export RUSTFLAGS="${RUSTFLAGS:-} -C target-feature=+crt-static"
 84fi
 85cargo build --release --target "${remote_server_triple}" --package remote_server
 86
 87# Upload debug info to sentry.io
 88if ! command -v sentry-cli >/dev/null 2>&1; then
 89    echo "sentry-cli not found. skipping sentry upload."
 90    echo "install with: 'curl -sL https://sentry.io/get-cli | bash'"
 91else
 92    if [[ -n "${SENTRY_AUTH_TOKEN:-}" ]]; then
 93        echo "Uploading zed debug symbols to sentry..."
 94        upload_to_sentry \
 95            "${target_dir}/${target_triple}"/release/zed \
 96            "${target_dir}/${remote_server_triple}"/release/remote_server \
 97            || true
 98    else
 99        echo "missing SENTRY_AUTH_TOKEN. skipping sentry upload."
100    fi
101fi
102
103# Strip debug symbols and save them for upload to DigitalOcean
104objcopy --strip-debug "${target_dir}/${target_triple}/release/zed"
105objcopy --strip-debug "${target_dir}/${target_triple}/release/cli"
106objcopy --strip-debug "${target_dir}/${remote_server_triple}/release/remote_server"
107
108# Ensure that remote_server does not depend on libssl nor libcrypto, as we got rid of these deps.
109if ldd "${target_dir}/${remote_server_triple}/release/remote_server" | grep -q 'libcrypto\|libssl'; then
110    if [[ "$remote_server_triple" == *-musl ]]; then
111        echo "Error: remote_server still depends on libssl or libcrypto" && exit 1
112    else
113        echo "Info: Using non-musl remote-server build."
114    fi
115fi
116
117suffix=""
118if [ "$channel" != "stable" ]; then
119  suffix="-$channel"
120fi
121
122# Move everything that should end up in the final package
123# into a temp directory.
124temp_dir=$(mktemp -d)
125zed_dir="${temp_dir}/zed$suffix.app"
126
127# Binary
128mkdir -p "${zed_dir}/bin" "${zed_dir}/libexec"
129cp "${target_dir}/${target_triple}/release/zed" "${zed_dir}/libexec/zed-editor"
130cp "${target_dir}/${target_triple}/release/cli" "${zed_dir}/bin/zed"
131
132# Libs
133find_libs() {
134    ldd ${target_dir}/${target_triple}/release/zed |\
135        cut -d' ' -f3 |\
136        grep -v '\<\(libstdc++.so\|libc.so\|libgcc_s.so\|libm.so\|libpthread.so\|libdl.so\|libasound.so\)'
137}
138
139mkdir -p "${zed_dir}/lib"
140rm -rf "${zed_dir}/lib/*"
141cp $(find_libs) "${zed_dir}/lib"
142
143# Icons
144mkdir -p "${zed_dir}/share/icons/hicolor/512x512/apps"
145cp "crates/zed/resources/app-icon$suffix.png" "${zed_dir}/share/icons/hicolor/512x512/apps/zed.png"
146mkdir -p "${zed_dir}/share/icons/hicolor/1024x1024/apps"
147cp "crates/zed/resources/app-icon$suffix@2x.png" "${zed_dir}/share/icons/hicolor/1024x1024/apps/zed.png"
148
149# .desktop
150export DO_STARTUP_NOTIFY="true"
151export APP_CLI="zed"
152export APP_ICON="zed"
153export APP_ARGS="%U"
154if [[ "$channel" == "preview" ]]; then
155  export APP_NAME="Zed Preview"
156  APP_ID="dev.zed.Zed-Preview"
157elif [[ "$channel" == "nightly" ]]; then
158  export APP_NAME="Zed Nightly"
159  APP_ID="dev.zed.Zed-Nightly"
160elif [[ "$channel" == "dev" ]]; then
161  export APP_NAME="Zed Devel"
162  APP_ID="dev.zed.Zed-Dev"
163else
164  export APP_NAME="Zed"
165  APP_ID="dev.zed.Zed"
166fi
167
168mkdir -p "${zed_dir}/share/applications"
169envsubst < "crates/zed/resources/zed.desktop.in" > "${zed_dir}/share/applications/$APP_ID.desktop"
170chmod +x "${zed_dir}/share/applications/$APP_ID.desktop"
171
172# Copy generated licenses so they'll end up in archive too
173cp "assets/licenses.md" "${zed_dir}/licenses.md"
174
175# Create archive out of everything that's in the temp directory
176arch=$(uname -m)
177archive="zed-linux-${arch}.tar.gz"
178
179rm -rf "${archive}"
180remove_match="zed(-[a-zA-Z0-9]+)?-linux-$(uname -m)\.tar\.gz"
181ls "${target_dir}/release" | grep -E ${remove_match} | xargs -d "\n" -I {} rm -f "${target_dir}/release/{}" || true
182tar -czvf "${target_dir}/release/$archive" -C ${temp_dir} "zed$suffix.app"
183
184gzip -f --stdout --best "${target_dir}/${remote_server_triple}/release/remote_server" > "${target_dir}/zed-remote-server-linux-${arch}.gz"