#!/usr/bin/env bash set -euxo pipefail build_flag="--release" target_dir="release" bundle_name="" zed_crate="zed" help_info() { echo " Usage: ${0##*/} [options] [bundle_name] Build the application bundle for Linux. Options: -d Compile in debug mode -h Display this help and exit " } while getopts 'dh' flag do case "${flag}" in d) export CARGO_INCREMENTAL=true export CARGO_BUNDLE_SKIP_BUILD=true build_flag=""; target_dir="debug" ;; h) help_info exit 0 ;; esac done shift $((OPTIND-1)) if [[ $# -gt 0 ]]; then if [ "$1" ]; then bundle_name=$1 fi fi export ZED_BUNDLE=true cargo_bundle_version=$(cargo -q bundle --help 2>&1 | head -n 1 || echo "") if [ "$cargo_bundle_version" != "cargo-bundle v0.6.0-zed" ]; then cargo install cargo-bundle --git https://github.com/zed-industries/cargo-bundle.git --branch zed-deploy fi echo "Compiling zed binaries" cargo build ${build_flag} --package ${zed_crate} --package cli echo "Creating application bundle" # TODO linux # Here, hacks to make `cargo bundle` run work, but macOS does not need these # Most probably, needs https://github.com/zed-industries/cargo-bundle/commit/9e185bd44d968d8039192220603494555afdbb4f from the upstream. cp "target/${target_dir}/Zed" "target/${target_dir}/zed" pushd crates/${zed_crate} channel=$(/dev/null || true dpkg-deb -x "${bundle_path}" bundle/ dpkg-deb --control "${bundle_path}" bundle/DEBIAN mkdir -p bundle/usr/local/bin/ mv bundle/usr/bin/zed "bundle/usr/local/bin/zed-$channel" cp "${target_dir}/cli" "bundle/usr/local/bin/cli-$channel" ln -s "/usr/local/bin/cli-$channel" "bundle/usr/local/bin/zed" rm -rf bundle/usr/bin/ dpkg-deb -b bundle/ "${target_dir}/${bundle_name}" bundle_path="${PWD}/${target_dir}/${bundle_name}" popd echo "Bundled ${bundle_path}"