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(cd crates/zed && cargo bundle --release --target x86_64-apple-darwin)
26
27echo "Creating fat binaries"
28lipo \
29 -create \
30 target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/Zed \
31 -output \
32 target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/MacOS/zed
33lipo \
34 -create \
35 target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/cli \
36 -output \
37 target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/MacOS/cli
38
39echo "Copying WebRTC.framework into the frameworks folder"
40mkdir target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Frameworks
41cp -R target/x86_64-apple-darwin/release/WebRTC.framework target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Frameworks/
42
43if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
44 echo "Signing bundle with Apple-issued certificate"
45 security create-keychain -p $MACOS_CERTIFICATE_PASSWORD zed.keychain || echo ""
46 security default-keychain -s zed.keychain
47 security unlock-keychain -p $MACOS_CERTIFICATE_PASSWORD zed.keychain
48 echo $MACOS_CERTIFICATE | base64 --decode > /tmp/zed-certificate.p12
49 security import /tmp/zed-certificate.p12 -k zed.keychain -P $MACOS_CERTIFICATE_PASSWORD -T /usr/bin/codesign
50 rm /tmp/zed-certificate.p12
51 security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $MACOS_CERTIFICATE_PASSWORD zed.keychain
52 /usr/bin/codesign --force --deep --timestamp --options runtime --sign "Zed Industries, Inc." target/x86_64-apple-darwin/release/bundle/osx/Zed.app -v
53 security default-keychain -s login.keychain
54else
55 echo "One or more of the following variables are missing: MACOS_CERTIFICATE, MACOS_CERTIFICATE_PASSWORD, APPLE_NOTARIZATION_USERNAME, APPLE_NOTARIZATION_PASSWORD"
56 echo "Performing an ad-hoc signature, but this bundle should not be distributed"
57 codesign --force --deep --sign - target/x86_64-apple-darwin/release/bundle/osx/Zed.app -v
58fi
59
60echo "Creating DMG"
61mkdir -p target/release
62hdiutil create -volname Zed -srcfolder target/x86_64-apple-darwin/release/bundle/osx -ov -format UDZO target/release/Zed.dmg
63
64if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
65 echo "Notarizing DMG with Apple"
66 npm install -g notarize-cli
67 npx notarize-cli --file target/release/Zed.dmg --bundle-id dev.zed.Zed --username $APPLE_NOTARIZATION_USERNAME --password $APPLE_NOTARIZATION_PASSWORD
68fi
69
70# If -o option is specified, open the target/release directory in Finder to reveal the DMG
71while getopts o flag
72do
73 case "${flag}" in
74 o) open target/release;;
75 esac
76done