Skip to content

Commit

Permalink
Update build script to create universal binary
Browse files Browse the repository at this point in the history
  • Loading branch information
sttz committed Mar 13, 2022
1 parent 1ea695a commit 1772d73
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions Build/build-osx.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -23,33 +34,44 @@ 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

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

Expand Down

0 comments on commit 1772d73

Please sign in to comment.