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
36echo "Copying WebRTC.framework into the frameworks folder"
37mkdir target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Frameworks
38cp -R target/x86_64-apple-darwin/release/WebRTC.framework target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Frameworks/
39rm -rf target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Frameworks/WebRTC.framework/Versions
40
41if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
42    echo "Signing bundle with Apple-issued certificate"
43    security create-keychain -p $MACOS_CERTIFICATE_PASSWORD zed.keychain || echo ""
44    security default-keychain -s zed.keychain
45    security unlock-keychain -p $MACOS_CERTIFICATE_PASSWORD zed.keychain
46    echo $MACOS_CERTIFICATE | base64 --decode > /tmp/zed-certificate.p12
47    security import /tmp/zed-certificate.p12 -k zed.keychain -P $MACOS_CERTIFICATE_PASSWORD -T /usr/bin/codesign
48    rm /tmp/zed-certificate.p12
49    security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $MACOS_CERTIFICATE_PASSWORD zed.keychain
50    /usr/bin/codesign --force --deep --timestamp --options runtime --sign "Zed Industries, Inc." target/x86_64-apple-darwin/release/bundle/osx/Zed.app -v
51    security default-keychain -s login.keychain
52else
53    echo "One or more of the following variables are missing: MACOS_CERTIFICATE, MACOS_CERTIFICATE_PASSWORD, APPLE_NOTARIZATION_USERNAME, APPLE_NOTARIZATION_PASSWORD"
54    echo "Performing an ad-hoc signature, but this bundle should not be distributed"
55    codesign --force --deep --sign - target/x86_64-apple-darwin/release/bundle/osx/Zed.app -v
56fi
57
58echo "Creating DMG"
59mkdir -p target/release
60hdiutil create -volname Zed -srcfolder target/x86_64-apple-darwin/release/bundle/osx -ov -format UDZO target/release/Zed.dmg
61
62if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
63    echo "Notarizing DMG with Apple"
64    npm install -g notarize-cli
65    npx notarize-cli --file target/release/Zed.dmg --bundle-id dev.zed.Zed --username $APPLE_NOTARIZATION_USERNAME --password $APPLE_NOTARIZATION_PASSWORD
66fi
67
68# If -o option is specified, open the target/release directory in Finder to reveal the DMG
69while getopts o flag
70do
71    case "${flag}" in
72        o) open target/release;;
73    esac
74done