1#!/bin/bash
2
3set -e
4
5# Build the app bundle for x86_64
6pushd zed > /dev/null
7cargo bundle --release --target x86_64-apple-darwin
8popd > /dev/null
9
10# Build the binary for aarch64 (Apple M1)
11cargo build --release --target aarch64-apple-darwin
12
13# Replace the bundle's binary with a "fat binary" that combines the two architecture-specific binaries
14lipo -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
15
16# 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.
17codesign --force --deep -s - target/x86_64-apple-darwin/release/bundle/osx/Zed.app
18
19# Create a DMG
20mkdir -p target/release
21hdiutil create -volname Zed -srcfolder target/x86_64-apple-darwin/release/bundle/osx -ov -format UDZO target/release/Zed.dmg
22
23# If -o option is specified, open the target/release directory in Finder to reveal the DMG
24while getopts o flag
25do
26 case "${flag}" in
27 o) open target/release;;
28 esac
29done