bundle

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