bundle

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