2021-04-29 00:02:02 +03:00
#!/bin/bash
set -e
2023-02-21 22:26:06 +03:00
build_flag="--release"
target_dir="release"
open_result=false
2023-10-06 02:41:08 +03:00
local_arch=false
2023-08-28 22:32:30 +03:00
local_only=false
overwrite_local_app=false
bundle_name=""
2023-11-18 04:44:11 +03:00
zed_crate="zed"
2023-11-20 21:34:22 +03:00
binary_name="Zed"
2023-08-28 22:32:30 +03:00
2024-02-12 11:30:38 +03:00
# This must match the team in the provisioning profile.
2023-11-06 20:37:35 +03:00
APPLE_NOTORIZATION_TEAM="MQ55VZLNZQ"
2023-08-28 22:32:30 +03:00
# Function for displaying help info
help_info() {
echo "
Usage: ${0##*/} [options] [bundle_name]
Build the application bundle.
Options:
2023-10-06 02:41:08 +03:00
-d Compile in debug mode
-l Compile for local architecture and copy bundle to /Applications, implies -d.
2023-08-28 22:32:30 +03:00
-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.
"
}
2023-02-21 22:26:06 +03:00
2024-02-14 20:55:37 +03:00
function uploadDsym
{
SPACE="zed-debug-symbols"
REGION="nyc3"
file_to_upload="$1"
file_name="$2"
space_path="nightly"
date=$(date +"%a, %d %b %Y %T %z")
acl="x-amz-acl:public-read"
content_type="application/octet-stream"
storage_type="x-amz-storage-class:STANDARD"
string="PUT\n\n${content_type}\n${date}\n${acl}\n${storage_type}\n/${SPACE}/${space_path}/${file_name}"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${DIGITALOCEAN_SPACES_SECRET_KEY}" -binary | base64)
curl --fail -vv -s -X PUT -T "$file_to_upload" \
-H "Host: ${SPACE}.${REGION}.digitaloceanspaces.com" \
-H "Date: $date" \
-H "Content-Type: $content_type" \
-H "$storage_type" \
-H "$acl" \
-H "Authorization: AWS ${DIGITALOCEAN_SPACES_ACCESS_KEY}:$signature" \
"https://${SPACE}.${REGION}.digitaloceanspaces.com/${space_path}/${file_name}"
}
2024-01-03 21:08:26 +03:00
while getopts 'dlfoh' flag
2023-02-21 22:26:06 +03:00
do
case "${flag}" in
o) open_result=true;;
2023-03-14 00:47:15 +03:00
d)
2023-10-06 02:41:08 +03:00
export CARGO_INCREMENTAL=true
export CARGO_BUNDLE_SKIP_BUILD=true
2023-02-21 22:26:06 +03:00
build_flag="";
2023-10-06 02:41:08 +03:00
target_dir="debug"
;;
l)
export CARGO_INCREMENTAL=true
export CARGO_BUNDLE_SKIP_BUILD=true
build_flag=""
local_arch=true
local_only=true
2023-02-21 22:26:06 +03:00
target_dir="debug"
;;
2023-08-28 22:32:30 +03:00
f) overwrite_local_app=true;;
h)
help_info
exit 0
;;
2023-02-21 22:26:06 +03:00
esac
done
2023-08-28 22:32:30 +03:00
shift $((OPTIND-1))
if [ "$1" ]; then
bundle_name=$1
fi
2021-10-25 19:11:52 +03:00
export ZED_BUNDLE=true
2022-10-20 17:55:39 +03:00
export MACOSX_DEPLOYMENT_TARGET=10.15.7
2021-10-25 12:02:35 +03:00
2023-06-14 04:01:51 +03:00
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
2022-07-11 19:29:27 +03:00
rustup target add wasm32-wasi
2021-05-18 02:57:50 +03:00
2022-02-04 18:48:00 +03:00
# Deal with versions of macOS that don't include libstdc++ headers
export CXXFLAGS="-stdlib=libc++"
2023-08-28 22:32:30 +03:00
version_info=$(rustc --version --verbose)
host_line=$(echo "$version_info" | grep host)
local_target_triple=${host_line#*: }
2023-10-06 02:41:08 +03:00
if [ "$local_arch" = true ]; then
2023-08-28 22:32:30 +03:00
echo "Building for local target only."
2023-11-18 04:44:11 +03:00
cargo build ${build_flag} --package ${zed_crate}
2023-08-28 22:32:30 +03:00
cargo build ${build_flag} --package cli
else
2023-11-06 19:21:34 +03:00
echo "Compiling zed binaries"
2023-11-18 04:44:11 +03:00
cargo build ${build_flag} --package ${zed_crate} --package cli --target aarch64-apple-darwin --target x86_64-apple-darwin
2023-08-28 22:32:30 +03:00
fi
2021-04-29 00:02:02 +03:00
2022-04-20 00:19:22 +03:00
echo "Creating application bundle"
2022-10-27 01:08:53 +03:00
pushd crates/zed
2023-01-25 01:01:14 +03:00
channel=$(<RELEASE_CHANNEL)
2023-11-18 04:44:11 +03:00
popd
pushd crates/${zed_crate}
2022-10-27 01:08:53 +03:00
cp Cargo.toml Cargo.toml.backup
sed \
-i .backup \
"s/package.metadata.bundle-${channel}/package.metadata.bundle/" \
Cargo.toml
2023-08-28 22:32:30 +03:00
2023-10-06 02:41:08 +03:00
if [ "$local_arch" = true ]; then
app_path=$(cargo bundle ${build_flag} --select-workspace-root | xargs)
2023-08-28 22:32:30 +03:00
else
app_path=$(cargo bundle ${build_flag} --target x86_64-apple-darwin --select-workspace-root | xargs)
fi
2023-02-21 22:26:06 +03:00
2022-10-27 01:08:53 +03:00
mv Cargo.toml.backup Cargo.toml
popd
2022-10-27 07:06:06 +03:00
echo "Bundled ${app_path}"
2021-05-05 02:18:14 +03:00
2023-10-06 02:41:08 +03:00
if [ "$local_arch" = false ]; then
2024-02-14 20:55:37 +03:00
echo "Uploading dSYMs"
dsymutil --flat target/aarch64-apple-darwin/release/Zed
dsymutil --flat target/x86_64-apple-darwin/release/Zed
version="$(cargo metadata --no-deps --manifest-path crates/zed/Cargo.toml --offline --format-version=1 | jq -r '.packages | map(select(.name == "zed"))[0].version')"
if [ "$channel" == "nightly" ]; then
version="$version-$(git rev-parse --short HEAD)"
fi
uploadDsym target/aarch64-apple-darwin/release/Zed.dwarf "$channel/Zed-$version-aarch64-apple-darwin.dwarf"
uploadDsym target/x86_64-apple-darwin/release/Zed.dwarf "$channel/Zed-$version-x86_64-apple-darwin.dwarf"
2023-08-28 22:32:30 +03:00
echo "Creating fat binaries"
lipo \
-create \
2023-11-20 21:34:22 +03:00
target/{x86_64-apple-darwin,aarch64-apple-darwin}/${target_dir}/${binary_name} \
2023-08-28 22:32:30 +03:00
-output \
2023-11-18 21:46:35 +03:00
"${app_path}/Contents/MacOS/${zed_crate}"
2023-08-28 22:32:30 +03:00
lipo \
-create \
target/{x86_64-apple-darwin,aarch64-apple-darwin}/${target_dir}/cli \
-output \
"${app_path}/Contents/MacOS/cli"
fi
2021-10-25 12:02:35 +03:00
2022-10-20 16:38:54 +03:00
echo "Copying WebRTC.framework into the frameworks folder"
2022-10-27 01:08:53 +03:00
mkdir "${app_path}/Contents/Frameworks"
2023-10-09 17:59:25 +03:00
if [ "$local_arch" = false ]; then
cp -R target/${local_target_triple}/${target_dir}/WebRTC.framework "${app_path}/Contents/Frameworks/"
else
cp -R target/${target_dir}/WebRTC.framework "${app_path}/Contents/Frameworks/"
fi
2022-10-20 16:38:54 +03:00
2024-01-10 03:14:54 +03:00
# Note: The app identifier for our development builds is the same as the app identifier for nightly.
2023-11-18 04:44:11 +03:00
cp crates/${zed_crate}/contents/$channel/embedded.provisionprofile "${app_path}/Contents/"
2023-10-11 18:23:06 +03:00
2021-09-11 08:11:22 +03:00
if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
2021-09-11 07:07:20 +03:00
echo "Signing bundle with Apple-issued certificate"
2022-12-10 00:09:07 +03:00
security create-keychain -p "$MACOS_CERTIFICATE_PASSWORD" zed.keychain || echo ""
2021-09-11 07:51:45 +03:00
security default-keychain -s zed.keychain
2022-12-10 00:09:07 +03:00
security unlock-keychain -p "$MACOS_CERTIFICATE_PASSWORD" zed.keychain
echo "$MACOS_CERTIFICATE" | base64 --decode > /tmp/zed-certificate.p12
security import /tmp/zed-certificate.p12 -k zed.keychain -P "$MACOS_CERTIFICATE_PASSWORD" -T /usr/bin/codesign
2021-09-11 07:07:20 +03:00
rm /tmp/zed-certificate.p12
2022-12-10 00:09:07 +03:00
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$MACOS_CERTIFICATE_PASSWORD" zed.keychain
2023-10-12 00:17:46 +03:00
# sequence of codesign commands modeled after this example: https://developer.apple.com/forums/thread/701514
2023-10-26 10:58:35 +03:00
/usr/bin/codesign --deep --force --timestamp --sign "Zed Industries, Inc." "${app_path}/Contents/Frameworks/WebRTC.framework" -v
2024-01-03 21:08:26 +03:00
/usr/bin/codesign --deep --force --timestamp --options runtime --sign "Zed Industries, Inc." "${app_path}/Contents/MacOS/cli" -v
2023-11-18 05:27:11 +03:00
/usr/bin/codesign --deep --force --timestamp --options runtime --entitlements crates/${zed_crate}/resources/zed.entitlements --sign "Zed Industries, Inc." "${app_path}/Contents/MacOS/${zed_crate}" -v
2023-11-18 04:44:11 +03:00
/usr/bin/codesign --force --timestamp --options runtime --entitlements crates/${zed_crate}/resources/zed.entitlements --sign "Zed Industries, Inc." "${app_path}" -v
2023-10-12 00:17:46 +03:00
2021-09-11 08:11:22 +03:00
security default-keychain -s login.keychain
else
echo "One or more of the following variables are missing: MACOS_CERTIFICATE, MACOS_CERTIFICATE_PASSWORD, APPLE_NOTARIZATION_USERNAME, APPLE_NOTARIZATION_PASSWORD"
2023-10-12 00:33:59 +03:00
if [[ "$local_only" = false ]]; then
echo "To create a self-signed local build use ./scripts/build.sh -ldf"
exit 1
fi
echo "====== WARNING ======"
echo "This bundle is being signed without all entitlements, some features (e.g. universal links) will not work"
echo "====== WARNING ======"
# NOTE: if you need to test universal links you have a few paths forward:
# - create a PR and tag it with the `run-build-dmg` label, and download the .dmg file from there.
# - get a signing key for the MQ55VZLNZQ team from Nathan.
# - create your own signing key, and update references to MQ55VZLNZQ to your own team ID
# then comment out this line.
2023-11-18 04:44:11 +03:00
cat crates/${zed_crate}/resources/zed.entitlements | sed '/com.apple.developer.associated-domains/,+1d' > "${app_path}/Contents/Resources/zed.entitlements"
2023-10-12 00:33:59 +03:00
codesign --force --deep --entitlements "${app_path}/Contents/Resources/zed.entitlements" --sign ${MACOS_SIGNING_KEY:- -} "${app_path}" -v
2021-09-11 07:07:20 +03:00
fi
2021-05-05 02:29:39 +03:00
2023-10-06 02:41:08 +03:00
if [[ "$target_dir" = "debug" && "$local_only" = false ]]; then
2023-02-21 22:26:06 +03:00
if [ "$open_result" = true ]; then
open "$app_path"
else
echo "Created application bundle:"
echo "$app_path"
fi
exit 0
fi
2023-08-28 22:32:30 +03:00
if [ "$local_only" = true ]; then
# If bundle_name is not set or empty, use the basename of $app_path
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
2021-05-05 02:18:14 +03:00
2023-08-28 22:32:30 +03:00
if [ "$overwrite_local_app" = true ]; then
rm -rf "/Applications/$bundle_name"
fi
mv "$app_path" "/Applications/$bundle_name"
2023-03-14 00:47:15 +03:00
2023-08-28 22:32:30 +03:00
if [ "$open_result" = true ]; then
open "/Applications/$bundle_name"
else
echo "Installed application bundle:"
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"
rm -rf ${dmg_source_directory}
mkdir -p ${dmg_source_directory}
mv "${app_path}" "${dmg_source_directory}"
ln -s /Applications ${dmg_source_directory}
hdiutil create -volname Zed -srcfolder "${dmg_source_directory}" -ov -format UDZO "${dmg_file_path}"
# If someone runs this bundle script locally, a symlink will be placed in `dmg_source_directory`.
# This symlink causes CPU issues with Zed if the Zed codebase is the project being worked on, so we simply remove it for now.
rm ${dmg_source_directory}/Applications
echo "Adding license agreement to DMG"
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"
2023-11-06 20:37:35 +03:00
"$(xcode-select -p)/usr/bin/notarytool" submit --wait --apple-id "$APPLE_NOTARIZATION_USERNAME" --password "$APPLE_NOTARIZATION_PASSWORD" --team-id "$APPLE_NOTORIZATION_TEAM" "${dmg_file_path}"
2023-08-28 22:32:30 +03:00
fi
2021-09-11 08:11:22 +03:00
2023-08-28 22:32:30 +03:00
if [ "$open_result" = true ]; then
open $dmg_target_directory
fi
2023-03-14 00:47:15 +03:00
fi