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