2021-04-28 21:02:02 +00:00
#!/bin/bash
set -e
2021-10-25 16:11:52 +00:00
export ZED_BUNDLE=true
2021-10-25 09:02:35 +00:00
2021-05-17 23:57:50 +00:00
# Install cargo-bundle 0.5.0 if it's not already installed
cargo install cargo-bundle --version 0.5.0
2021-05-04 23:18:14 +00:00
# Build the app bundle for x86_64
2021-10-05 17:46:59 +00:00
pushd crates/zed > /dev/null
2021-05-04 23:18:14 +00:00
cargo bundle --release --target x86_64-apple-darwin
2021-04-28 21:22:14 +00:00
popd > /dev/null
2021-04-28 21:02:02 +00:00
2021-05-04 23:18:14 +00:00
# Build the binary for aarch64 (Apple M1)
2021-10-25 15:35:45 +00:00
cargo build --release --target aarch64-apple-darwin
2021-05-04 23:18:14 +00:00
# Replace the bundle's binary with a "fat binary" that combines the two architecture-specific binaries
2021-10-25 15:35:45 +00:00
lipo -create target/x86_64-apple-darwin/release/Zed target/aarch64-apple-darwin/release/Zed -output target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/MacOS/zed
2021-10-25 09:02:35 +00:00
# Bundle rust-analyzer
2021-10-29 09:41:07 +00:00
cp vendor/bin/rust-analyzer target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Resources/
2021-05-04 23:18:14 +00:00
2021-05-04 23:29:39 +00:00
# Sign the app bundle with an ad-hoc signature so it runs on the M1. We need a real certificate but this works for now.
2021-09-11 05:11:22 +00:00
if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
2021-09-11 04:07:20 +00:00
echo "Signing bundle with Apple-issued certificate"
security create-keychain -p $MACOS_CERTIFICATE_PASSWORD zed.keychain || echo ""
2021-09-11 04:51:45 +00:00
security default-keychain -s zed.keychain
2021-09-11 04:07:20 +00: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
rm /tmp/zed-certificate.p12
2021-09-11 04:51:45 +00:00
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $MACOS_CERTIFICATE_PASSWORD zed.keychain
2021-11-01 09:30:10 +00:00
/usr/bin/codesign --force --deep --timestamp --options runtime --sign "Zed Industries, Inc." target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Resources/rust-analyzer -v
2021-09-11 05:11:22 +00:00
/usr/bin/codesign --force --deep --timestamp --options runtime --sign "Zed Industries, Inc." target/x86_64-apple-darwin/release/bundle/osx/Zed.app -v
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"
echo "Performing an ad-hoc signature, but this bundle should not be distributed"
codesign --force --deep --sign - target/x86_64-apple-darwin/release/bundle/osx/Zed.app -v
2021-09-11 04:07:20 +00:00
fi
2021-05-04 23:29:39 +00:00
2021-05-04 23:18:14 +00:00
# Create a DMG
2021-09-11 05:11:22 +00:00
echo "Creating DMG"
2021-05-04 23:18:14 +00:00
mkdir -p target/release
hdiutil create -volname Zed -srcfolder target/x86_64-apple-darwin/release/bundle/osx -ov -format UDZO target/release/Zed.dmg
2021-09-11 05:11:22 +00:00
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 target/release/Zed.dmg --bundle-id dev.zed.Zed --username $APPLE_NOTARIZATION_USERNAME --password $APPLE_NOTARIZATION_PASSWORD
fi
2021-05-04 23:18:14 +00:00
# If -o option is specified, open the target/release directory in Finder to reveal the DMG
2021-04-28 21:02:02 +00:00
while getopts o flag
do
case "${flag}" in
2021-05-04 23:18:14 +00:00
o) open target/release;;
2021-04-28 21:02:02 +00:00
esac
done