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# Build binary in release mode
42export RUSTFLAGS="-C link-args=-Wl,--disable-new-dtags,-rpath,\$ORIGIN/../lib"
43cargo build --release --target "${target_triple}" --package zed --package cli
44
45# Strip the binary of all debug symbols
46# Later, we probably want to do something like this: https://github.com/GabrielMajeri/separate-symbols
47strip --strip-debug "${target_dir}/${target_triple}/release/zed"
48strip --strip-debug "${target_dir}/${target_triple}/release/cli"
49
50suffix=""
51if [ "$channel" != "stable" ]; then
52 suffix="-$channel"
53fi
54
55# Move everything that should end up in the final package
56# into a temp directory.
57temp_dir=$(mktemp -d)
58zed_dir="${temp_dir}/zed$suffix.app"
59
60# Binary
61mkdir -p "${zed_dir}/bin" "${zed_dir}/libexec"
62cp "${target_dir}/${target_triple}/release/zed" "${zed_dir}/libexec/zed-editor"
63cp "${target_dir}/${target_triple}/release/cli" "${zed_dir}/bin/zed"
64
65# Libs
66find_libs() {
67 ldd ${target_dir}/${target_triple}/release/zed |\
68 cut -d' ' -f3 |\
69 grep -v '\<\(libstdc++.so\|libc.so\|libgcc_s.so\|libm.so\|libpthread.so\|libdl.so\)'
70}
71
72mkdir -p "${zed_dir}/lib"
73rm -rf "${zed_dir}/lib/*"
74cp $(find_libs) "${zed_dir}/lib"
75
76# Icons
77mkdir -p "${zed_dir}/share/icons/hicolor/512x512/apps"
78cp "crates/zed/resources/app-icon$suffix.png" "${zed_dir}/share/icons/hicolor/512x512/apps/zed.png"
79mkdir -p "${zed_dir}/share/icons/hicolor/1024x1024/apps"
80cp "crates/zed/resources/app-icon$suffix@2x.png" "${zed_dir}/share/icons/hicolor/1024x1024/apps/zed.png"
81
82# .desktop
83export DO_STARTUP_NOTIFY="true"
84export APP_CLI="zed"
85export APP_ICON="zed"
86export APP_ARGS="%U"
87if [[ "$channel" == "preview" ]]; then
88 export APP_NAME="Zed Preview"
89elif [[ "$channel" == "nightly" ]]; then
90 export APP_NAME="Zed Nightly"
91elif [[ "$channel" == "dev" ]]; then
92 export APP_NAME="Zed Devel"
93else
94 export APP_NAME="Zed"
95fi
96
97mkdir -p "${zed_dir}/share/applications"
98envsubst < "crates/zed/resources/zed.desktop.in" > "${zed_dir}/share/applications/zed$suffix.desktop"
99
100# Licenses
101script/generate-licenses
102cp "assets/licenses.md" "${zed_dir}/licenses.md"
103
104# Create archive out of everything that's in the temp directory
105target="linux-$(uname -m)"
106if [[ "$channel" == "dev" ]]; then
107 archive="zed-${commit}-${target}.tar.gz"
108else
109 archive="zed-${target}.tar.gz"
110fi
111
112rm -rf "${archive}"
113remove_match="zed(-[a-zA-Z0-9]+)?-linux-$(uname -m)\.tar\.gz"
114ls "${target_dir}/release" | grep -E ${remove_match} | xargs -d "\n" -I {} rm -f "${target_dir}/release/{}" || true
115tar -czvf "${target_dir}/release/$archive" -C ${temp_dir} "zed$suffix.app"