bundle

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