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