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