Add -l option to build script

When you pass -l, we build for the local architecture only and copy the
resulting app bundle to /Applications. You can provide a bundle name as
an optional argument.
This commit is contained in:
Nathan Sobo 2023-08-28 13:32:30 -06:00
parent 851d74d5e1
commit a1d2ae3095

View File

@ -5,11 +5,29 @@ set -e
build_flag="--release" build_flag="--release"
target_dir="release" target_dir="release"
open_result=false open_result=false
local_only=false
overwrite_local_app=false
bundle_name=""
# Function for displaying help info
help_info() {
echo "
Usage: ${0##*/} [options] [bundle_name]
Build the application bundle.
Options:
-d Compile in debug mode and print the app bundle's path.
-l Compile for local architecture only and copy bundle to /Applications.
-o Open the resulting DMG or the app itself in local mode.
-f Overwrite the local app bundle if it exists.
-h Display this help and exit.
"
}
# If -o option is specified, the folder of the resulting dmg will be opened in finder # If -o option is specified, the folder of the resulting dmg will be opened in finder
# If -d is specified, Zed will be compiled in debug mode and the application's path printed # If -d is specified, Zed will be compiled in debug mode and the application's path printed
# If -od or -do is specified Zed will be bundled in debug and the application will be run. # If -od or -do is specified Zed will be bundled in debug and the application will be run.
while getopts 'od' flag while getopts 'dlfoh' flag
do do
case "${flag}" in case "${flag}" in
o) open_result=true;; o) open_result=true;;
@ -17,9 +35,21 @@ do
build_flag=""; build_flag="";
target_dir="debug" target_dir="debug"
;; ;;
l) local_only=true;;
f) overwrite_local_app=true;;
h)
help_info
exit 0
;;
esac esac
done done
shift $((OPTIND-1))
if [ "$1" ]; then
bundle_name=$1
fi
export ZED_BUNDLE=true export ZED_BUNDLE=true
export MACOSX_DEPLOYMENT_TARGET=10.15.7 export MACOSX_DEPLOYMENT_TARGET=10.15.7
@ -33,14 +63,24 @@ rustup target add wasm32-wasi
# Deal with versions of macOS that don't include libstdc++ headers # Deal with versions of macOS that don't include libstdc++ headers
export CXXFLAGS="-stdlib=libc++" export CXXFLAGS="-stdlib=libc++"
echo "Compiling zed binary for aarch64-apple-darwin" version_info=$(rustc --version --verbose)
cargo build ${build_flag} --package zed --target aarch64-apple-darwin host_line=$(echo "$version_info" | grep host)
echo "Compiling zed binary for x86_64-apple-darwin" local_target_triple=${host_line#*: }
cargo build ${build_flag} --package zed --target x86_64-apple-darwin
echo "Compiling cli binary for aarch64-apple-darwin" if [ "$local_only" = true ]; then
cargo build ${build_flag} --package cli --target aarch64-apple-darwin echo "Building for local target only."
echo "Compiling cli binary for x86_64-apple-darwin" cargo build ${build_flag} --package zed
cargo build ${build_flag} --package cli --target x86_64-apple-darwin cargo build ${build_flag} --package cli
else
echo "Compiling zed binary for aarch64-apple-darwin"
cargo build ${build_flag} --package zed --target aarch64-apple-darwin
echo "Compiling zed binary for x86_64-apple-darwin"
cargo build ${build_flag} --package zed --target x86_64-apple-darwin
echo "Compiling cli binary for aarch64-apple-darwin"
cargo build ${build_flag} --package cli --target aarch64-apple-darwin
echo "Compiling cli binary for x86_64-apple-darwin"
cargo build ${build_flag} --package cli --target x86_64-apple-darwin
fi
echo "Creating application bundle" echo "Creating application bundle"
pushd crates/zed pushd crates/zed
@ -50,27 +90,34 @@ sed \
-i .backup \ -i .backup \
"s/package.metadata.bundle-${channel}/package.metadata.bundle/" \ "s/package.metadata.bundle-${channel}/package.metadata.bundle/" \
Cargo.toml Cargo.toml
app_path=$(cargo bundle ${build_flag} --target x86_64-apple-darwin --select-workspace-root | xargs)
if [ "$local_only" = true ]; then
app_path=$(cargo bundle ${build_flag} --select-workspace-root | xargs)
else
app_path=$(cargo bundle ${build_flag} --target x86_64-apple-darwin --select-workspace-root | xargs)
fi
mv Cargo.toml.backup Cargo.toml mv Cargo.toml.backup Cargo.toml
popd popd
echo "Bundled ${app_path}" echo "Bundled ${app_path}"
echo "Creating fat binaries" if [ "$local_only" = false ]; then
lipo \ echo "Creating fat binaries"
-create \ lipo \
target/{x86_64-apple-darwin,aarch64-apple-darwin}/${target_dir}/Zed \ -create \
-output \ target/{x86_64-apple-darwin,aarch64-apple-darwin}/${target_dir}/Zed \
"${app_path}/Contents/MacOS/zed" -output \
lipo \ "${app_path}/Contents/MacOS/zed"
-create \ lipo \
target/{x86_64-apple-darwin,aarch64-apple-darwin}/${target_dir}/cli \ -create \
-output \ target/{x86_64-apple-darwin,aarch64-apple-darwin}/${target_dir}/cli \
"${app_path}/Contents/MacOS/cli" -output \
"${app_path}/Contents/MacOS/cli"
fi
echo "Copying WebRTC.framework into the frameworks folder" echo "Copying WebRTC.framework into the frameworks folder"
mkdir "${app_path}/Contents/Frameworks" mkdir "${app_path}/Contents/Frameworks"
cp -R target/x86_64-apple-darwin/${target_dir}/WebRTC.framework "${app_path}/Contents/Frameworks/" cp -R target/${local_target_triple}/${target_dir}/WebRTC.framework "${app_path}/Contents/Frameworks/"
if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
echo "Signing bundle with Apple-issued certificate" echo "Signing bundle with Apple-issued certificate"
@ -99,31 +146,55 @@ if [ "$target_dir" = "debug" ]; then
exit 0 exit 0
fi fi
dmg_target_directory="target/${target_dir}" if [ "$local_only" = true ]; then
dmg_source_directory="${dmg_target_directory}/dmg" # If bundle_name is not set or empty, use the basename of $app_path
dmg_file_path="${dmg_target_directory}/Zed.dmg" if [ -z "$bundle_name" ]; then
bundle_name=$(basename "$app_path")
else
# If bundle_name doesn't end in .app, append it
if [[ "$bundle_name" != *.app ]]; then
bundle_name="$bundle_name.app"
fi
fi
echo "Creating DMG" if [ "$overwrite_local_app" = true ]; then
rm -rf ${dmg_source_directory} rm -rf "/Applications/$bundle_name"
mkdir -p ${dmg_source_directory} fi
mv "${app_path}" "${dmg_source_directory}" mv "$app_path" "/Applications/$bundle_name"
ln -s /Applications ${dmg_source_directory} if [ "$open_result" = true ]; then
hdiutil create -volname Zed -srcfolder "${dmg_source_directory}" -ov -format UDZO "${dmg_file_path}" open "/Applications/$bundle_name"
# If someone runs this bundle script locally, a symlink will be placed in `dmg_source_directory`. else
# This symlink causes CPU issues with Zed if the Zed codebase is the project being worked on, so we simply remove it for now. echo "Installed application bundle:"
rm ${dmg_source_directory}/Applications echo "/Applications/$bundle_name"
fi
else
echo "Creating DMG"
dmg_target_directory="target/${target_dir}"
dmg_source_directory="${dmg_target_directory}/dmg"
dmg_file_path="${dmg_target_directory}/Zed.dmg"
echo "Adding license agreement to DMG" rm -rf ${dmg_source_directory}
npm install --global dmg-license minimist mkdir -p ${dmg_source_directory}
dmg-license script/eula/eula.json "${dmg_file_path}" mv "${app_path}" "${dmg_source_directory}"
if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then ln -s /Applications ${dmg_source_directory}
echo "Notarizing DMG with Apple" hdiutil create -volname Zed -srcfolder "${dmg_source_directory}" -ov -format UDZO "${dmg_file_path}"
npm install -g notarize-cli # If someone runs this bundle script locally, a symlink will be placed in `dmg_source_directory`.
npx notarize-cli --file "${dmg_file_path}" --bundle-id dev.zed.Zed --username "$APPLE_NOTARIZATION_USERNAME" --password "$APPLE_NOTARIZATION_PASSWORD" # This symlink causes CPU issues with Zed if the Zed codebase is the project being worked on, so we simply remove it for now.
fi rm ${dmg_source_directory}/Applications
if [ "$open_result" = true ]; then echo "Adding license agreement to DMG"
open $dmg_target_directory npm install --global dmg-license minimist
dmg-license script/eula/eula.json "${dmg_file_path}"
if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
echo "Notarizing DMG with Apple"
npm install -g notarize-cli
npx notarize-cli --file "${dmg_file_path}" --bundle-id dev.zed.Zed --username "$APPLE_NOTARIZATION_USERNAME" --password "$APPLE_NOTARIZATION_PASSWORD"
fi
if [ "$open_result" = true ]; then
open $dmg_target_directory
fi
fi fi