bundle

 1#!/bin/bash
 2
 3set -e
 4
 5# Install cargo-bundle 0.5.0 if it's not already installed
 6cargo install cargo-bundle --version 0.5.0
 7
 8# Build the app bundle for x86_64
 9pushd zed > /dev/null
10cargo bundle --release --target x86_64-apple-darwin
11popd > /dev/null
12
13# Build the binary for aarch64 (Apple M1)
14cargo build --release --target aarch64-apple-darwin
15
16# Replace the bundle's binary with a "fat binary" that combines the two architecture-specific binaries
17lipo -create target/x86_64-apple-darwin/release/Zed target/aarch64-apple-darwin/release/Zed -output target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/MacOS/zed
18
19# Sign the app bundle with an ad-hoc signature so it runs on the M1. We need a real certificate but this works for now.
20if [[ -z $MACOS_CERTIFICATE || -z $MACOS_CERTIFICATE_PASSWORD ]]; then
21    echo "Missing MACOS_CERTIFICATE and MACOS_CERTIFICATE_PASSWORD environment variables – performing ad-hoc signature"
22    codesign --force --deep -s - target/x86_64-apple-darwin/release/bundle/osx/Zed.app -v
23else
24    echo "Signing bundle with Apple-issued certificate"
25    security create-keychain -p $MACOS_CERTIFICATE_PASSWORD zed.keychain || echo ""
26    security default-keychain -s zed.keychain
27    security unlock-keychain -p $MACOS_CERTIFICATE_PASSWORD zed.keychain
28    echo $MACOS_CERTIFICATE | base64 --decode > /tmp/zed-certificate.p12
29    security import /tmp/zed-certificate.p12 -k zed.keychain -P $MACOS_CERTIFICATE_PASSWORD -T /usr/bin/codesign
30    rm /tmp/zed-certificate.p12
31    security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $MACOS_CERTIFICATE_PASSWORD zed.keychain
32    /usr/bin/codesign --force -s "Zed Industries, Inc." target/x86_64-apple-darwin/release/bundle/osx/Zed.app -v
33fi
34
35# Create a DMG
36mkdir -p target/release
37hdiutil create -volname Zed -srcfolder target/x86_64-apple-darwin/release/bundle/osx -ov -format UDZO target/release/Zed.dmg
38
39# If -o option is specified, open the target/release directory in Finder to reveal the DMG
40while getopts o flag
41do
42    case "${flag}" in
43        o) open target/release;;
44    esac
45done