bundle-linux

 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)
29
30version="$(cargo metadata --no-deps --manifest-path crates/zed/Cargo.toml --offline --format-version=1 | jq -r '.packages | map(select(.name == "zed"))[0].version')"
31# Set RELEASE_VERSION so it's compiled into GPUI and it knows about the version.
32export RELEASE_VERSION="${version}"
33
34commit=$(git rev-parse HEAD | cut -c 1-7)
35
36version_info=$(rustc --version --verbose)
37host_line=$(echo "$version_info" | grep host)
38target_triple=${host_line#*: }
39
40# Build binary in release mode
41cargo build --release --target "${target_triple}" --package zed --package cli
42
43# Strip the binary of all debug symbols
44# Later, we probably want to do something like this: https://github.com/GabrielMajeri/separate-symbols
45strip "target/${target_triple}/release/Zed"
46strip "target/${target_triple}/release/cli"
47
48suffix=""
49if [ "$channel" != "stable" ]; then
50  suffix="-$channel"
51fi
52
53# Move everything that should end up in the final package
54# into a temp directory.
55temp_dir=$(mktemp -d)
56zed_dir="${temp_dir}/zed$suffix.app"
57
58# Binary
59mkdir -p "${zed_dir}/bin"
60cp "target/${target_triple}/release/Zed" "${zed_dir}/bin/zed"
61cp "target/${target_triple}/release/cli" "${zed_dir}/bin/cli"
62
63# Icons
64mkdir -p "${zed_dir}/share/icons/hicolor/512x512/apps"
65cp "crates/zed/resources/app-icon$suffix.png" "${zed_dir}/share/icons/hicolor/512x512/apps/zed.png"
66mkdir -p "${zed_dir}/share/icons/hicolor/1024x1024/apps"
67cp "crates/zed/resources/app-icon$suffix@2x.png" "${zed_dir}/share/icons/hicolor/1024x1024/apps/zed.png"
68
69# .desktop
70mkdir -p "${zed_dir}/share/applications"
71cp "crates/zed/resources/zed.desktop" "${zed_dir}/share/applications/zed$suffix.desktop"
72if [[ "$channel" == "preview" ]]; then
73    sed -i "s|Name=Zed|Name=Zed Preview|g" "${zed_dir}/share/applications/zed$suffix.desktop"
74elif [[ "$channel" == "nightly" ]]; then
75    sed -i "s|Name=Zed|Name=Zed Nightly|g" "${zed_dir}/share/applications/zed$suffix.desktop"
76fi
77
78# Licenses
79cp "assets/licenses.md" "${zed_dir}/licenses.md"
80
81# Create archive out of everything that's in the temp directory
82target="linux-$(uname -m)"
83
84if [[ "$channel" == "nightly" ]]; then
85  archive="zed-${target}.tar.gz"
86elif  [[ "$channel" == "dev" ]]; then
87  archive="zed-${commit}-${target}.tar.gz"
88else
89  archive="zed-${target}.tar.gz"
90fi
91
92rm -rf "${archive}"
93tar -czvf target/release/$archive -C ${temp_dir} "zed$suffix.app"