Skip to content

Commit

Permalink
Merge pull request #9 from InvoxiPlayGames/egui-universal-actions
Browse files Browse the repository at this point in the history
[macOS] Build Universal macOS app in CI
  • Loading branch information
NotNite authored Oct 7, 2024
2 parents 02ef04d + d26a193 commit f9d7164
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 15 deletions.
28 changes: 13 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
# macos-latest is aarch64, install x86_64 target
- uses: dtolnay/rust-toolchain@stable
- name: Install cargo-bundle
run: cargo install cargo-bundle
with:
targets: x86_64-apple-darwin

# build our two architectures
- name: Build (AArch64)
run: cargo build --target=aarch64-apple-darwin --release
- name: Build (x86_64)
run: cargo build --target=x86_64-apple-darwin --release

# cargo-bundle doesn't understand what to do about workspaces
- name: Bundle
run: |
cargo build --release
cp -r ./target ./crates/moonlight-installer/target
cd ./crates/moonlight-installer
cargo bundle --release
cd ../..
rm -rf ./target
mv ./crates/moonlight-installer/target .
- name: Apply ad-hoc signature
run: codesign --force --deep -s - "target/release/bundle/osx/moonlight installer.app"
# packaging
- name: Create .app bundle
run: ./package-macos-app.sh bundle
- name: Create DMG
run: hdiutil create -volname "Moonlight Installer" -srcfolder target/release/bundle/osx -ov -format UDZO moonlight-installer-macos.dmg
run: hdiutil create -volname "moonlight installer" -srcfolder temp/app -ov -format UDZO moonlight-installer-macos.dmg
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
temp/
.DS_Store
32 changes: 32 additions & 0 deletions assets/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>moonlight installer</string>
<key>CFBundleExecutable</key>
<string>moonlight-installer</string>
<key>CFBundleIconFile</key>
<string>Icon.icns</string>
<key>CFBundleIdentifier</key>
<string>io.github.moonlight-mod.moonlight-installer</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>moonlight installer</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.2.0</string>
<key>CFBundleVersion</key>
<string>0.2.0</string>
<key>CSResourcesFileMapped</key>
<true/>
<key>LSRequiresCarbon</key>
<true/>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>
Binary file added assets/icon.icns
Binary file not shown.
47 changes: 47 additions & 0 deletions package-macos-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh

# Packaging script to build a macOS .app bundle
# If no arguments are passed, will build a single-architecture .app using the binary at
# ./target/release/moonlight-installer
# Specifying "bundle" will combine the binaries at
# ./target/x86_64-apple-darwin/release/moonlight-installer
# ./target/aarch64-apple-darwin/release/moonlight-installer

APPNAME="moonlight installer.app"
EXENAME=moonlight-installer
ICON=assets/icon.icns
PLIST=assets/Info.plist

# Clear the temp folders
rm -rf temp
if [[ "$1" == "clean" ]]; then
exit
fi

# Make our temporary folders
mkdir -p temp/app

if [[ "$1" == "bundle" ]]; then
EXECUTABLE=temp/$EXENAME
echo "Creating universal binary..."
lipo -create target/x86_64-apple-darwin/release/$EXENAME target/aarch64-apple-darwin/release/$EXENAME -output $EXECUTABLE
else
EXECUTABLE=target/release/$EXENAME
fi

# Make the app directory structure
APPDIR="temp/app/$APPNAME"
echo "Building app bundle..."
mkdir -p "$APPDIR/Contents/MacOS"
mkdir -p "$APPDIR/Contents/Resources"
# Copy our assets to it
cp $PLIST "$APPDIR/Contents/Info.plist"
cp $ICON "$APPDIR/Contents/Resources/Icon.icns"
# Copy the merged binary
cp $EXECUTABLE "$APPDIR/Contents/MacOS/$EXENAME"

# Apply an ad-hoc signature
echo "Code signing..."
codesign --force --deep -s - "$APPDIR"

echo "Built '$APPDIR'"

0 comments on commit f9d7164

Please sign in to comment.