1#!/bin/bash
2
3set -e
4
5export ZED_BUNDLE=true
6export MACOSX_DEPLOYMENT_TARGET=10.15.7
7
8which cargo-bundle > /dev/null || cargo install cargo-bundle --version 0.5.0
9rustup target add wasm32-wasi
10
11# Deal with versions of macOS that don't include libstdc++ headers
12export CXXFLAGS="-stdlib=libc++"
13
14echo "Compiling zed binary for aarch64-apple-darwin"
15cargo build --release --package zed --target aarch64-apple-darwin
16echo "Compiling zed binary for x86_64-apple-darwin"
17cargo build --release --package zed --target x86_64-apple-darwin
18echo "Compiling cli binary for aarch64-apple-darwin"
19cargo build --release --package cli --target aarch64-apple-darwin
20echo "Compiling cli binary for x86_64-apple-darwin"
21cargo build --release --package cli --target x86_64-apple-darwin
22
23echo "Creating application bundle"
24pushd crates/zed
25channel=$(cat RELEASE_CHANNEL)
26cp Cargo.toml Cargo.toml.backup
27sed \
28 -i .backup \
29 "s/package.metadata.bundle-${channel}/package.metadata.bundle/" \
30 Cargo.toml
31app_path=$(cargo bundle --release --target x86_64-apple-darwin | xargs)
32mv Cargo.toml.backup Cargo.toml
33popd
34echo "Bundled ${app_path}"
35
36echo "Creating fat binaries"
37lipo \
38 -create \
39 target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/Zed \
40 -output \
41 "${app_path}/Contents/MacOS/zed"
42lipo \
43 -create \
44 target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/cli \
45 -output \
46 "${app_path}/Contents/MacOS/cli"
47
48echo "Copying WebRTC.framework into the frameworks folder"
49mkdir "${app_path}/Contents/Frameworks"
50cp -R target/x86_64-apple-darwin/release/WebRTC.framework "${app_path}/Contents/Frameworks/"
51
52if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
53 echo "Signing bundle with Apple-issued certificate"
54 security create-keychain -p $MACOS_CERTIFICATE_PASSWORD zed.keychain || echo ""
55 security default-keychain -s zed.keychain
56 security unlock-keychain -p $MACOS_CERTIFICATE_PASSWORD zed.keychain
57 echo $MACOS_CERTIFICATE | base64 --decode > /tmp/zed-certificate.p12
58 security import /tmp/zed-certificate.p12 -k zed.keychain -P $MACOS_CERTIFICATE_PASSWORD -T /usr/bin/codesign
59 rm /tmp/zed-certificate.p12
60 security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $MACOS_CERTIFICATE_PASSWORD zed.keychain
61 /usr/bin/codesign --force --deep --timestamp --options runtime --sign "Zed Industries, Inc." "${app_path}" -v
62 security default-keychain -s login.keychain
63else
64 echo "One or more of the following variables are missing: MACOS_CERTIFICATE, MACOS_CERTIFICATE_PASSWORD, APPLE_NOTARIZATION_USERNAME, APPLE_NOTARIZATION_PASSWORD"
65 echo "Performing an ad-hoc signature, but this bundle should not be distributed"
66 codesign --force --deep --sign - "${app_path}" -v
67fi
68
69echo "Creating DMG"
70mkdir -p target/release/dmg
71rm -rf target/release/dmg/*
72mv "${app_path}" target/release/dmg/
73hdiutil create -volname Zed -srcfolder target/release/dmg -ov -format UDZO target/release/Zed.dmg
74
75if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
76 echo "Notarizing DMG with Apple"
77 npm install -g notarize-cli
78 npx notarize-cli --file target/release/Zed.dmg --bundle-id dev.zed.Zed --username $APPLE_NOTARIZATION_USERNAME --password $APPLE_NOTARIZATION_PASSWORD
79fi
80
81# If -o option is specified, open the target/release directory in Finder to reveal the DMG
82while getopts o flag
83do
84 case "${flag}" in
85 o) open target/release;;
86 esac
87done