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.
20codesign --force --deep -s - target/x86_64-apple-darwin/release/bundle/osx/Zed.app
21
22# Create a DMG
23mkdir -p target/release
24hdiutil create -volname Zed -srcfolder target/x86_64-apple-darwin/release/bundle/osx -ov -format UDZO target/release/Zed.dmg
25
26# If -o option is specified, open the target/release directory in Finder to reveal the DMG
27while getopts o flag
28do
29    case "${flag}" in
30        o) open target/release;;
31    esac
32done