60 lines · 3.0 KB · Text
RawDownload
#!/bin/bash set -e export ZED_BUNDLE=true # Install cargo-bundle 0.5.0 if it's not already installedcargo install cargo-bundle --version 0.5.0 # Build the app bundle for x86_64pushd crates/zed > /dev/nullcargo bundle --release --target x86_64-apple-darwinpopd > /dev/null # Build the binary for aarch64 (Apple M1)cargo build --release --target aarch64-apple-darwin # Replace the bundle's binary with a "fat binary" that combines the two architecture-specific binarieslipo -create target/x86_64-apple-darwin/release/Zed target/aarch64-apple-darwin/release/Zed -output target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/MacOS/zed # Bundle rust-analyzercp vendor/bin/rust-analyzer target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Resources/ # Sign the app bundle with an ad-hoc signature so it runs on the M1. We need a real certificate but this works for now.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." target/x86_64-apple-darwin/release/bundle/osx/Zed.app/Contents/Resources/rust-analyzer -v    /usr/bin/codesign --force --deep --timestamp --options runtime --sign "Zed Industries, Inc." target/x86_64-apple-darwin/release/bundle/osx/Zed.app -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 - target/x86_64-apple-darwin/release/bundle/osx/Zed.app -vfi # Create a DMGecho "Creating DMG"mkdir -p target/releasehdiutil create -volname Zed -srcfolder target/x86_64-apple-darwin/release/bundle/osx -ov -format UDZO target/release/Zed.dmg 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 target/release/Zed.dmg --bundle-id dev.zed.Zed --username $APPLE_NOTARIZATION_USERNAME --password $APPLE_NOTARIZATION_PASSWORDfi # If -o option is specified, open the target/release directory in Finder to reveal the DMGwhile getopts o flagdo    case "${flag}" in        o) open target/release;;    esacdone