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
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"
46
47suffix=""
48if [ "$channel" != "stable" ]; then
49  suffix="-$channel"
50fi
51
52# Move everything that should end up in the final package
53# into a temp directory.
54temp_dir=$(mktemp -d)
55zed_dir="${temp_dir}/zed$suffix.app"
56
57# Binary
58mkdir -p "${zed_dir}/bin"
59cp "target/${target_triple}/release/Zed" "${zed_dir}/bin/zed"
60
61# Icons
62mkdir -p "${zed_dir}/share/icons/hicolor/512x512/apps"
63cp "crates/zed/resources/app-icon$suffix.png" "${zed_dir}/share/icons/hicolor/512x512/apps/zed.png"
64mkdir -p "${zed_dir}/share/icons/hicolor/1024x1024/apps"
65cp "crates/zed/resources/app-icon$suffix@2x.png" "${zed_dir}/share/icons/hicolor/1024x1024/apps/zed.png"
66
67# .desktop
68mkdir -p "${zed_dir}/share/applications"
69cp "crates/zed/resources/zed.desktop" "${zed_dir}/share/applications/zed$suffix.desktop"
70if [[ "$channel" == "preview" ]]; then
71    sed -i "s|Name=Zed|Name=Zed Preview|g" "${zed_dir}/share/applications/zed$suffix.desktop"
72elif [[ "$channel" == "nightly" ]]; then
73    sed -i "s|Name=Zed|Name=Zed Nightly|g" "${zed_dir}/share/applications/zed$suffix.desktop"
74fi
75
76# Licenses
77cp "assets/licenses.md" "${zed_dir}/licenses.md"
78
79# Create archive out of everything that's in the temp directory
80target="linux-$(uname -m)"
81
82if [[ "$channel" == "nightly" ]]; then
83  archive="zed-${target}.tar.gz"
84elif  [[ "$channel" == "dev" ]]; then
85  archive="zed-${commit}-${target}.tar.gz"
86else
87  archive="zed-${target}.tar.gz"
88fi
89
90rm -rf "${archive}"
91tar -czvf $archive -C ${temp_dir} "zed$suffix.app"