2021-04-29 00:02:02 +03:00
#!/bin/bash
set -e
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
2022-10-27 01:08:53 +03:00
which cargo-bundle > /dev/null || cargo install cargo-bundle --version 0.5.0
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++"
2022-10-20 17:55:39 +03:00
echo "Compiling zed binary for aarch64-apple-darwin"
2022-04-20 00:19:22 +03:00
cargo build --release --package zed --target aarch64-apple-darwin
2022-10-20 17:55:39 +03:00
echo "Compiling zed binary for x86_64-apple-darwin"
2022-04-20 00:19:22 +03:00
cargo build --release --package zed --target x86_64-apple-darwin
2022-10-20 17:55:39 +03:00
echo "Compiling cli binary for aarch64-apple-darwin"
2022-04-20 00:19:22 +03:00
cargo build --release --package cli --target aarch64-apple-darwin
2022-10-20 17:55:39 +03:00
echo "Compiling cli binary for x86_64-apple-darwin"
2022-04-20 00:19:22 +03:00
cargo build --release --package cli --target x86_64-apple-darwin
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
channel=$(cat RELEASE_CHANNEL)
cp Cargo.toml Cargo.toml.backup
sed \
-i .backup \
"s/package.metadata.bundle-${channel}/package.metadata.bundle/" \
Cargo.toml
app_path=$(cargo bundle --release --target x86_64-apple-darwin | xargs)
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
2022-04-20 00:19:22 +03:00
echo "Creating fat binaries"
lipo \
-create \
target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/Zed \
-output \
2022-10-27 01:08:53 +03:00
"${app_path}/Contents/MacOS/zed"
2022-04-20 00:19:22 +03:00
lipo \
-create \
target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/cli \
-output \
2022-10-27 01:08:53 +03:00
"${app_path}/Contents/MacOS/cli"
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"
cp -R target/x86_64-apple-darwin/release/WebRTC.framework "${app_path}/Contents/Frameworks/"
2022-10-20 16:38:54 +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"
security create-keychain -p $MACOS_CERTIFICATE_PASSWORD zed.keychain || echo ""
2021-09-11 07:51:45 +03:00
security default-keychain -s zed.keychain
2021-09-11 07:07:20 +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
rm /tmp/zed-certificate.p12
2021-09-11 07:51:45 +03:00
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $MACOS_CERTIFICATE_PASSWORD zed.keychain
2022-10-27 01:08:53 +03:00
/usr/bin/codesign --force --deep --timestamp --options runtime --sign "Zed Industries, Inc." "${app_path}" -v
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"
echo "Performing an ad-hoc signature, but this bundle should not be distributed"
2022-10-27 01:08:53 +03:00
codesign --force --deep --sign - "${app_path}" -v
2021-09-11 07:07:20 +03:00
fi
2021-05-05 02:29:39 +03:00
2021-09-11 08:11:22 +03:00
echo "Creating DMG"
2022-10-27 07:06:06 +03:00
mkdir -p target/release/dmg
rm -rf target/release/dmg/*
mv "${app_path}" target/release/dmg/
hdiutil create -volname Zed -srcfolder target/release/dmg -ov -format UDZO target/release/Zed.dmg
2021-05-05 02:18:14 +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
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-05 02:18:14 +03:00
# If -o option is specified, open the target/release directory in Finder to reveal the DMG
2021-04-29 00:02:02 +03:00
while getopts o flag
do
case "${flag}" in
2021-05-05 02:18:14 +03:00
o) open target/release;;
2021-04-29 00:02:02 +03:00
esac
done