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