1#!/usr/bin/env bash
2
3set -euxo pipefail
4
5# Function for displaying help info
6help_info() {
7 echo "
8Usage: ${0##*/} [options]
9Build a release .tar.gz for Linux.
10
11Options:
12 -h Display this help and exit.
13 "
14}
15
16while getopts 'h' flag
17do
18 case "${flag}" in
19 h)
20 help_info
21 exit 0
22 ;;
23 esac
24done
25
26export ZED_BUNDLE=true
27
28channel=$(<crates/zed/RELEASE_CHANNEL)
29target_dir="${CARGO_TARGET_DIR:-target}"
30
31version="$(script/get-crate-version zed)"
32# Set RELEASE_VERSION so it's compiled into GPUI and it knows about the version.
33export RELEASE_VERSION="${version}"
34
35commit=$(git rev-parse HEAD | cut -c 1-7)
36
37version_info=$(rustc --version --verbose)
38host_line=$(echo "$version_info" | grep host)
39target_triple=${host_line#*: }
40
41# Generate the licenses first, so they can be baked into the binaries
42script/generate-licenses
43
44# Build binary in release mode
45export RUSTFLAGS="${RUSTFLAGS:-} -C link-args=-Wl,--disable-new-dtags,-rpath,\$ORIGIN/../lib"
46cargo build --release --target "${target_triple}" --package zed --package cli
47# Build remote_server in separate invocation to prevent feature unification from other crates
48# from influencing dynamic libraries required by it.
49cargo build --release --target "${target_triple}" --package remote_server
50
51# Strip the binary of all debug symbols
52# Later, we probably want to do something like this: https://github.com/GabrielMajeri/separate-symbols
53strip --strip-debug "${target_dir}/${target_triple}/release/zed"
54strip --strip-debug "${target_dir}/${target_triple}/release/cli"
55strip --strip-debug "${target_dir}/${target_triple}/release/remote_server"
56
57
58# Ensure that remote_server does not depend on libssl nor libcrypto, as we got rid of these deps.
59! ldd "${target_dir}/${target_triple}/release/remote_server" | grep -q 'libcrypto\|libssl'
60
61suffix=""
62if [ "$channel" != "stable" ]; then
63 suffix="-$channel"
64fi
65
66# Move everything that should end up in the final package
67# into a temp directory.
68temp_dir=$(mktemp -d)
69zed_dir="${temp_dir}/zed$suffix.app"
70
71# Binary
72mkdir -p "${zed_dir}/bin" "${zed_dir}/libexec"
73cp "${target_dir}/${target_triple}/release/zed" "${zed_dir}/libexec/zed-editor"
74cp "${target_dir}/${target_triple}/release/cli" "${zed_dir}/bin/zed"
75
76# Libs
77find_libs() {
78 ldd ${target_dir}/${target_triple}/release/zed |\
79 cut -d' ' -f3 |\
80 grep -v '\<\(libstdc++.so\|libc.so\|libgcc_s.so\|libm.so\|libpthread.so\|libdl.so\)'
81}
82
83mkdir -p "${zed_dir}/lib"
84rm -rf "${zed_dir}/lib/*"
85cp $(find_libs) "${zed_dir}/lib"
86
87# Icons
88mkdir -p "${zed_dir}/share/icons/hicolor/512x512/apps"
89cp "crates/zed/resources/app-icon$suffix.png" "${zed_dir}/share/icons/hicolor/512x512/apps/zed.png"
90mkdir -p "${zed_dir}/share/icons/hicolor/1024x1024/apps"
91cp "crates/zed/resources/app-icon$suffix@2x.png" "${zed_dir}/share/icons/hicolor/1024x1024/apps/zed.png"
92
93# .desktop
94export DO_STARTUP_NOTIFY="true"
95export APP_CLI="zed"
96export APP_ICON="zed"
97export APP_ARGS="%U"
98if [[ "$channel" == "preview" ]]; then
99 export APP_NAME="Zed Preview"
100elif [[ "$channel" == "nightly" ]]; then
101 export APP_NAME="Zed Nightly"
102elif [[ "$channel" == "dev" ]]; then
103 export APP_NAME="Zed Devel"
104else
105 export APP_NAME="Zed"
106fi
107
108mkdir -p "${zed_dir}/share/applications"
109envsubst < "crates/zed/resources/zed.desktop.in" > "${zed_dir}/share/applications/zed$suffix.desktop"
110
111# Copy generated licenses so they'll end up in archive too
112cp "assets/licenses.md" "${zed_dir}/licenses.md"
113
114# Create archive out of everything that's in the temp directory
115arch=$(uname -m)
116target="linux-${arch}"
117if [[ "$channel" == "dev" ]]; then
118 archive="zed-${commit}-${target}.tar.gz"
119else
120 archive="zed-${target}.tar.gz"
121fi
122
123rm -rf "${archive}"
124remove_match="zed(-[a-zA-Z0-9]+)?-linux-$(uname -m)\.tar\.gz"
125ls "${target_dir}/release" | grep -E ${remove_match} | xargs -d "\n" -I {} rm -f "${target_dir}/release/{}" || true
126tar -czvf "${target_dir}/release/$archive" -C ${temp_dir} "zed$suffix.app"
127
128gzip --stdout --best "${target_dir}/${target_triple}/release/remote_server" > "${target_dir}/zed-remote-server-linux-${arch}.gz"