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
34echo "Bundled ${app_path}"
35
36echo "Creating fat binaries"
37lipo \
38    -create \
39    target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/Zed \
40    -output \
41    "${app_path}/Contents/MacOS/zed"
42lipo \
43    -create \
44    target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/cli \
45    -output \
46    "${app_path}/Contents/MacOS/cli"
47
48echo "Copying WebRTC.framework into the frameworks folder"
49mkdir "${app_path}/Contents/Frameworks"
50cp -R target/x86_64-apple-darwin/release/WebRTC.framework "${app_path}/Contents/Frameworks/"
51
52if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
53    echo "Signing bundle with Apple-issued certificate"
54    security create-keychain -p "$MACOS_CERTIFICATE_PASSWORD" zed.keychain || echo ""
55    security default-keychain -s zed.keychain
56    security unlock-keychain -p "$MACOS_CERTIFICATE_PASSWORD" zed.keychain
57    echo "$MACOS_CERTIFICATE" | base64 --decode > /tmp/zed-certificate.p12
58    security import /tmp/zed-certificate.p12 -k zed.keychain -P "$MACOS_CERTIFICATE_PASSWORD" -T /usr/bin/codesign
59    rm /tmp/zed-certificate.p12
60    security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$MACOS_CERTIFICATE_PASSWORD" zed.keychain
61    /usr/bin/codesign --force --deep --timestamp --options runtime --sign "Zed Industries, Inc." "${app_path}" -v
62    security default-keychain -s login.keychain
63else
64    echo "One or more of the following variables are missing: MACOS_CERTIFICATE, MACOS_CERTIFICATE_PASSWORD, APPLE_NOTARIZATION_USERNAME, APPLE_NOTARIZATION_PASSWORD"
65    echo "Performing an ad-hoc signature, but this bundle should not be distributed"
66    codesign --force --deep --sign - "${app_path}" -v
67fi
68
69dmg_target_directory="target/release"
70dmg_source_directory="${dmg_target_directory}/dmg"
71dmg_file_path="${dmg_target_directory}/Zed.dmg"
72
73echo "Creating DMG"
74rm -rf ${dmg_source_directory}
75mkdir -p ${dmg_source_directory}
76mv "${app_path}" "${dmg_source_directory}"
77
78ln -s /Applications ${dmg_source_directory}
79hdiutil create -volname Zed -srcfolder "${dmg_source_directory}" -ov -format UDZO "${dmg_file_path}"
80# If someone runs this bundle script locally, a symlink will be placed in `dmg_source_directory`.
81# This symlink causes CPU issues with Zed if the Zed codebase is the project being worked on, so we simply remove it for now.
82rm ${dmg_source_directory}/Applications
83
84if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then
85    echo "Notarizing DMG with Apple"
86    npm install -g notarize-cli
87    npx notarize-cli --file ${dmg_file_path} --bundle-id dev.zed.Zed --username "$APPLE_NOTARIZATION_USERNAME" --password "$APPLE_NOTARIZATION_PASSWORD"
88fi
89
90# If -o option is specified, open the $dmg_target_directory directory in Finder to reveal the DMG
91while getopts o flag
92do
93    case "${flag}" in
94        o) open $dmg_target_directory;;
95    esac
96done