96 lines · 4.0 KB · Text
RawDownload
#!/bin/bash set -e export ZED_BUNDLE=trueexport MACOSX_DEPLOYMENT_TARGET=10.15.7 which cargo-bundle > /dev/null || cargo install cargo-bundle --version 0.5.0rustup target add wasm32-wasi # Deal with versions of macOS that don't include libstdc++ headersexport CXXFLAGS="-stdlib=libc++" echo "Compiling zed binary for aarch64-apple-darwin"cargo build --release --package zed --target aarch64-apple-darwinecho "Compiling zed binary for x86_64-apple-darwin"cargo build --release --package zed --target x86_64-apple-darwinecho "Compiling cli binary for aarch64-apple-darwin"cargo build --release --package cli --target aarch64-apple-darwinecho "Compiling cli binary for x86_64-apple-darwin"cargo build --release --package cli --target x86_64-apple-darwin echo "Creating application bundle"pushd crates/zedchannel=$(cat RELEASE_CHANNEL)cp Cargo.toml Cargo.toml.backupsed \    -i .backup \    "s/package.metadata.bundle-${channel}/package.metadata.bundle/" \    Cargo.tomlapp_path=$(cargo bundle --release --target x86_64-apple-darwin | xargs)mv Cargo.toml.backup Cargo.tomlpopdecho "Bundled ${app_path}" echo "Creating fat binaries"lipo \    -create \    target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/Zed \    -output \    "${app_path}/Contents/MacOS/zed"lipo \    -create \    target/{x86_64-apple-darwin,aarch64-apple-darwin}/release/cli \    -output \    "${app_path}/Contents/MacOS/cli" echo "Copying WebRTC.framework into the frameworks folder"mkdir "${app_path}/Contents/Frameworks"cp -R target/x86_64-apple-darwin/release/WebRTC.framework "${app_path}/Contents/Frameworks/" if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then    echo "Signing bundle with Apple-issued certificate"    security create-keychain -p "$MACOS_CERTIFICATE_PASSWORD" zed.keychain || echo ""    security default-keychain -s zed.keychain    security unlock-keychain -p "$MACOS_CERTIFICATE_PASSWORD" zed.keychain    echo "$MACOS_CERTIFICATE" | base64 --decode > /tmp/zed-certificate.p12    security import /tmp/zed-certificate.p12 -k zed.keychain -P "$MACOS_CERTIFICATE_PASSWORD" -T /usr/bin/codesign    rm /tmp/zed-certificate.p12    security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$MACOS_CERTIFICATE_PASSWORD" zed.keychain    /usr/bin/codesign --force --deep --timestamp --options runtime --sign "Zed Industries, Inc." "${app_path}" -v    security default-keychain -s login.keychainelse    echo "One or more of the following variables are missing: MACOS_CERTIFICATE, MACOS_CERTIFICATE_PASSWORD, APPLE_NOTARIZATION_USERNAME, APPLE_NOTARIZATION_PASSWORD"    echo "Performing an ad-hoc signature, but this bundle should not be distributed"    codesign --force --deep --sign - "${app_path}" -vfi dmg_target_directory="target/release"dmg_source_directory="${dmg_target_directory}/dmg"dmg_file_path="${dmg_target_directory}/Zed.dmg" echo "Creating DMG"rm -rf ${dmg_source_directory}mkdir -p ${dmg_source_directory}mv "${app_path}" "${dmg_source_directory}" ln -s /Applications ${dmg_source_directory}hdiutil create -volname Zed -srcfolder "${dmg_source_directory}" -ov -format UDZO "${dmg_file_path}"# If someone runs this bundle script locally, a symlink will be placed in `dmg_source_directory`.# This symlink causes CPU issues with Zed if the Zed codebase is the project being worked on, so we simply remove it for now.rm ${dmg_source_directory}/Applications if [[ -n $MACOS_CERTIFICATE && -n $MACOS_CERTIFICATE_PASSWORD && -n $APPLE_NOTARIZATION_USERNAME && -n $APPLE_NOTARIZATION_PASSWORD ]]; then    echo "Notarizing DMG with Apple"    npm install -g notarize-cli    npx notarize-cli --file ${dmg_file_path} --bundle-id dev.zed.Zed --username "$APPLE_NOTARIZATION_USERNAME" --password "$APPLE_NOTARIZATION_PASSWORD"fi # If -o option is specified, open the $dmg_target_directory directory in Finder to reveal the DMGwhile getopts o flagdo    case "${flag}" in        o) open $dmg_target_directory;;    esacdone