2021-04-28 21:02:02 +00:00
#!/bin/bash
set -e
2023-02-21 19:26:06 +00:00
build_flag="--release"
target_dir="release"
open_result=false
# 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 -od or -do is specified Zed will be bundled in debug and the application will be run.
while getopts 'od' flag
do
case "${flag}" in
o) open_result=true;;
d)
build_flag="";
target_dir="debug"
;;
esac
done
2021-10-25 16:11:52 +00:00
export ZED_BUNDLE=true
2022-10-20 14:55:39 +00:00
export MACOSX_DEPLOYMENT_TARGET=10.15.7
2021-10-25 09:02:35 +00:00
2022-10-26 22:08:53 +00:00
which cargo-bundle > /dev/null || cargo install cargo-bundle --version 0.5.0
2022-07-11 16:29:27 +00:00
rustup target add wasm32-wasi
2021-05-17 23:57:50 +00:00
2022-02-04 15:48:00 +00:00
# Deal with versions of macOS that don't include libstdc++ headers
export CXXFLAGS="-stdlib=libc++"
2022-10-20 14:55:39 +00:00
echo "Compiling zed binary for aarch64-apple-darwin"
2023-02-21 19:26:06 +00:00
cargo build ${build_flag} --package zed --target aarch64-apple-darwin
2022-10-20 14:55:39 +00:00
echo "Compiling zed binary for x86_64-apple-darwin"
2023-02-21 19:26:06 +00:00
cargo build ${build_flag} --package zed --target x86_64-apple-darwin
2022-10-20 14:55:39 +00:00
echo "Compiling cli binary for aarch64-apple-darwin"
2023-02-21 19:26:06 +00:00
cargo build ${build_flag} --package cli --target aarch64-apple-darwin
2022-10-20 14:55:39 +00:00
echo "Compiling cli binary for x86_64-apple-darwin"
2023-02-21 19:26:06 +00:00
cargo build ${build_flag} --package cli --target x86_64-apple-darwin
2021-04-28 21:02:02 +00:00
2022-04-19 21:19:22 +00:00
echo "Creating application bundle"
2022-10-26 22:08:53 +00:00
pushd crates/zed
2023-01-24 22:01:14 +00:00
channel=$(<RELEASE_CHANNEL)
2022-10-26 22:08:53 +00:00
cp Cargo.toml Cargo.toml.backup
sed \
-i .backup \
"s/package.metadata.bundle-${channel}/package.metadata.bundle/" \
Cargo.toml
2023-02-21 19:26:06 +00:00
app_path=$(cargo bundle ${build_flag} --target x86_64-apple-darwin | xargs)
echo app_path
2022-10-26 22:08:53 +00:00
mv Cargo.toml.backup Cargo.toml
popd
2022-10-27 04:06:06 +00:00
echo "Bundled ${app_path}"
2021-05-04 23:18:14 +00:00
2022-04-19 21:19:22 +00:00
echo "Creating fat binaries"
lipo \
-create \
2023-02-21 19:26:06 +00:00
target/{x86_64-apple-darwin,aarch64-apple-darwin}/${target_dir}/Zed \
2022-04-19 21:19:22 +00:00
-output \
2022-10-26 22:08:53 +00:00
"${app_path}/Contents/MacOS/zed"
2022-04-19 21:19:22 +00:00
lipo \
-create \
2023-02-21 19:26:06 +00:00
target/{x86_64-apple-darwin,aarch64-apple-darwin}/${target_dir}/cli \
2022-04-19 21:19:22 +00:00
-output \
2022-10-26 22:08:53 +00:00
"${app_path}/Contents/MacOS/cli"
2021-10-25 09:02:35 +00:00
2022-10-20 13:38:54 +00:00
echo "Copying WebRTC.framework into the frameworks folder"
2022-10-26 22:08:53 +00:00
mkdir "${app_path}/Contents/Frameworks"
2023-02-21 19:26:06 +00:00
cp -R target/x86_64-apple-darwin/${target_dir}/WebRTC.framework "${app_path}/Contents/Frameworks/"
2022-10-20 13:38:54 +00:00
2023-01-24 22:01:14 +00:00
mv "${app_path}/Contents/Info.plist" "${app_path}/Contents/WithoutDocumentTypes.plist"
awk \
"/<\/dict>/{while(getline line<\"./crates/zed/BundleDocumentTypes.plist\"){print line}}1" \
"${app_path}/Contents/WithoutDocumentTypes.plist" \
> "${app_path}/Contents/Info.plist"
rm "${app_path}/Contents/WithoutDocumentTypes.plist"
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"
2022-12-09 21:09:07 +00:00
security create-keychain -p "$MACOS_CERTIFICATE_PASSWORD" zed.keychain || echo ""
2021-09-11 04:51:45 +00:00
security default-keychain -s zed.keychain
2022-12-09 21:09:07 +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
2021-09-11 04:07:20 +00:00
rm /tmp/zed-certificate.p12
2022-12-09 21:09:07 +00:00
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$MACOS_CERTIFICATE_PASSWORD" zed.keychain
2022-10-26 22:08:53 +00:00
/usr/bin/codesign --force --deep --timestamp --options runtime --sign "Zed Industries, Inc." "${app_path}" -v
2021-09-11 05:11:22 +00: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-26 22:08:53 +00:00
codesign --force --deep --sign - "${app_path}" -v
2021-09-11 04:07:20 +00:00
fi
2021-05-04 23:29:39 +00:00
2023-02-21 19:26:06 +00:00
if [ "$target_dir" = "debug" ]; then
if [ "$open_result" = true ]; then
open "$app_path"
else
echo "Created application bundle:"
echo "$app_path"
fi
exit 0
fi
dmg_target_directory="target/${target_dir}"
2022-12-09 21:09:07 +00:00
dmg_source_directory="${dmg_target_directory}/dmg"
dmg_file_path="${dmg_target_directory}/Zed.dmg"
2021-09-11 05:11:22 +00:00
echo "Creating DMG"
2022-12-09 21:09:07 +00:00
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
2021-05-04 23:18:14 +00:00
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
2022-12-09 21:09:07 +00:00
npx notarize-cli --file ${dmg_file_path} --bundle-id dev.zed.Zed --username "$APPLE_NOTARIZATION_USERNAME" --password "$APPLE_NOTARIZATION_PASSWORD"
2021-09-11 05:11:22 +00:00
fi
2023-02-21 19:26:06 +00:00
if [ "$open_result" = true ]; then
open $dmg_target_directory
fi