From 1772d732cdeeaee55ed14ed2dff376c5325a228e Mon Sep 17 00:00:00 2001 From: Adrian Stutz Date: Sun, 13 Mar 2022 17:25:55 +0100 Subject: [PATCH] Update build script to create universal binary --- Build/build-osx.sh | 48 +++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/Build/build-osx.sh b/Build/build-osx.sh index 0055b08..f8cea1e 100755 --- a/Build/build-osx.sh +++ b/Build/build-osx.sh @@ -1,17 +1,28 @@ -#!/bin/bash +#!/bin/zsh PROJECT="Command/Command.csproj" TARGET="net6.0" -ARCH="osx-x64" +ARCHES=("osx-x64" "osx-arm64") SIGN_IDENTITY="Developer ID Application: Feist GmbH (DHNHQKSSYT)" +ASC_PROVIDER="DHNHQKSSYT" ENTITLEMENTS="Build/notarization.entitlements" BUNDLE_ID="ch.sttz.install-unity" +# Mapping of arche names used by .Net to the ones used by lipo +typeset -A LIPO_ARCHES=() +LIPO_ARCHES[osx-x64]=x86_64 +LIPO_ARCHES[osx-arm64]=arm64 + if [[ -z "$ASC_USER" ]]; then echo "ASC user not set in ASC_USER" exit 1 fi +if [[ -z "$ASC_KEYCHAIN" ]]; then + echo "ASC keychain item not set in ASC_KEYCHAIN" + exit 1 +fi + cd "$(dirname "$0")/.." # Extract version from project @@ -23,25 +34,36 @@ if [[ -z "$VERSION" ]]; then exit 1 fi -# Build a new executable +# Build new executables, one per arch -dotnet publish -r "$ARCH" -c release -f "$TARGET" "$PROJECT" || exit 1 +ARCH_ARGS=() +for arch in $ARCHES; do + dotnet publish -r "$arch" -c release -f "$TARGET" "$PROJECT" || exit 1 -BUILD_OUTPUT="Command/bin/release/$TARGET/$ARCH/publish/Command" + output="Command/bin/release/$TARGET/$arch/publish/Command" -if [ ! -f "$BUILD_OUTPUT" ]; then - echo "Could not find executable at path: $BUILD_OUTPUT" - exit 1 -fi + if [ ! -f "$output" ]; then + echo "Could not find executable at path: $output" + exit 1 + fi + + if [[ -z $LIPO_ARCHES[$arch] ]]; then + echo "No lipo arch specified for .Net arch: $arch" + exit 1 + fi -# Codesign, archive and notarize executable + ARCH_ARGS+=(-arch $LIPO_ARCHES[$arch] "$output") +done + +# Merge, codesign, archive and notarize executable ARCHIVE="Releases/$VERSION" EXECUTABLE="$ARCHIVE/install-unity" ZIPARCHIVE="Releases/install-unity-$VERSION.zip" -mkdir "$ARCHIVE" -cp "$BUILD_OUTPUT" "$EXECUTABLE" +mkdir -p "$ARCHIVE" + +lipo -create $ARCH_ARGS -output "$EXECUTABLE" || exit 1 codesign --force --timestamp --options=runtime --entitlements="$ENTITLEMENTS" --sign "$SIGN_IDENTITY" "$EXECUTABLE" || exit 1 @@ -49,7 +71,7 @@ pushd "$ARCHIVE" zip "../install-unity-$VERSION.zip" "install-unity" || exit 1 popd -xcrun altool --notarize-app --primary-bundle-id "$BUNDLE_ID" --asc-provider "$ASC_PROVIDER" --username "$ASC_USER" --file "$ZIPARCHIVE" || exit 1 +xcrun altool --notarize-app --primary-bundle-id "$BUNDLE_ID" --asc-provider "$ASC_PROVIDER" --username "$ASC_USER" --password "@keychain:$ASC_KEYCHAIN" --file "$ZIPARCHIVE" || exit 1 # Shasum for Homebrew