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