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