From 4c5206fa7b415eefa8c444b582bf2c5df2a040a0 Mon Sep 17 00:00:00 2001 From: Benjamin Sutas Date: Tue, 3 Feb 2026 14:22:59 +1100 Subject: [PATCH] attempt to build mac app bundle --- build.sh | 162 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 114 insertions(+), 48 deletions(-) diff --git a/build.sh b/build.sh index a551bc69..56d8e7ab 100644 --- a/build.sh +++ b/build.sh @@ -13,7 +13,6 @@ FG_GREEN=$(tput setaf 46) BG_GREEN=$(tput setab 46) RESET=$(tput sgr0) - # 1. Get the version from the first command-line argument if [ -z "$1" ]; then echo "Error: Please provide the version as the first argument." @@ -27,54 +26,121 @@ echo "=== Building Object Editor v${FG_BLUE}$version${RESET} for ${FG_BLUE}$fram # read .net version from csproj file framework=$(grep '' Gui/Gui.csproj | sed 's/.*\(.*\)<\/TargetFramework>.*/\1/') + + +build_windows() { + echo "Building the ${FG_BLUE}Editor${RESET} (win-x64)" + dotnet publish Gui/Gui.csproj -c Release -p:WarningLevel=0 -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime win-x64 + + echo "Building the ${FG_BLUE}Updater${RESET} (win-x64)" + dotnet publish GuiUpdater/GuiUpdater.csproj -c Release -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime win-x64 + + echo "Copying ${FG_BLUE}Updater${RESET} files into ${FG_BLUE}Gui${RESET} folders (win-x64)" + cp GuiUpdater/bin/Release/$framework/win-x64/publish/* Gui/bin/Release/$framework/win-x64/publish + + echo "Zipping ${FG_BLUE}win-x64${RESET}" + pushd "Gui/bin/Release/$framework/win-x64/publish" + zip -r "object-editor-$version-win-x64.zip" . + mv "object-editor-$version-win-x64.zip" ../../.. + popd +} + +build_linux() { + echo "Building the ${FG_BLUE}Editor${RESET} (linux-x64)" + dotnet publish Gui/Gui.csproj -c Release -p:WarningLevel=0 -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime linux-x64 + + echo "Building the ${FG_BLUE}Updater${RESET} (linux-x64)" + dotnet publish GuiUpdater/GuiUpdater.csproj -c Release -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime linux-x64 + + echo "Copying ${FG_BLUE}Updater${RESET} files into ${FG_BLUE}Gui${RESET} folders (linux-x64)" + cp GuiUpdater/bin/Release/$framework/linux-x64/publish/* Gui/bin/Release/$framework/linux-x64/publish + + echo "Zipping ${FG_BLUE}linux-x64${RESET}" + pushd "Gui/bin/Release/$framework/linux-x64/publish" + chmod +x "./ObjectEditor" + chmod +x "./ObjectEditorUpdater" + touch "object-editor-$version-linux-x64.tar" + tar --exclude="object-editor-$version-linux-x64.tar" -jcf "object-editor-$version-linux-x64.tar" . + mv "object-editor-$version-linux-x64.tar" ../../.. + popd +} + +build_macos() { + # macOS bundle settings + app_name="ObjectEditor" + mac_bundle_id="com.openloco.objecteditor" + macos_publish_dir="Gui/bin/Release/$framework/osx-x64/publish" + macos_bundle_dir="$macos_publish_dir/$app_name.app" + macos_plist_template="Gui/Packaging/macOS/Info.plist" + + echo "Building the ${FG_BLUE}Editor${RESET} (osx-x64)" + dotnet publish Gui/Gui.csproj -c Release -p:WarningLevel=0 -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime osx-x64 + + echo "Building the ${FG_BLUE}Updater${RESET} (osx-x64)" + dotnet publish GuiUpdater/GuiUpdater.csproj -c Release -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime osx-x64 + + echo "Copying ${FG_BLUE}Updater${RESET} files into ${FG_BLUE}Gui${RESET} folders (osx-x64)" + cp GuiUpdater/bin/Release/$framework/osx-x64/publish/* Gui/bin/Release/$framework/osx-x64/publish + + echo "Creating ${FG_BLUE}macOS .app bundle${RESET}" + rm -rf "$macos_bundle_dir" + mkdir -p "$macos_bundle_dir/Contents/MacOS" "$macos_bundle_dir/Contents/Resources" + find "$macos_bundle_dir/Contents/MacOS" -mindepth 1 -exec rm -rf {} + + find "$macos_publish_dir" -mindepth 1 -maxdepth 1 \( -name "$app_name.app" -o -name "." \) -prune -o -exec cp -R {} "$macos_bundle_dir/Contents/MacOS/" \; + chmod +x "$macos_bundle_dir/Contents/MacOS/$app_name" + chmod +x "$macos_bundle_dir/Contents/MacOS/ObjectEditorUpdater" + + cat > "$macos_bundle_dir/Contents/Info.plist" < + + + + CFBundleName + $app_name + CFBundleDisplayName + $app_name + CFBundleExecutable + $app_name + CFBundleIdentifier + $mac_bundle_id + CFBundlePackageType + APPL + CFBundleShortVersionString + $version + CFBundleVersion + $version + LSMinimumSystemVersion + 11.0 + NSHighResolutionCapable + + CFBundleIconFile + loco_icon.icns + + +EOF + + if [ -f "Gui/Assets/loco_icon.icns" ]; then + cp "Gui/Assets/loco_icon.icns" "$macos_bundle_dir/Contents/Resources/" + fi + + echo "Zipping ${FG_BLUE}osx-x64${RESET}" + pushd "Gui/bin/Release/$framework/osx-x64/publish" + zip -r "object-editor-$version-osx-x64.zip" "$app_name.app" + mv "object-editor-$version-osx-x64.zip" ../../.. + popd +} + # 2. Write the version to version.txt. This is read by the UI to know the current version. echo "$version" > Gui/version.txt -# 3. Build the editor for different platforms -echo "Building the ${FG_BLUE}Editor${RESET}" -dotnet publish Gui/Gui.csproj -c Release -p:WarningLevel=0 -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime win-x64 -dotnet publish Gui/Gui.csproj -c Release -p:WarningLevel=0 -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime linux-x64 -dotnet publish Gui/Gui.csproj -c Release -p:WarningLevel=0 -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime osx-x64 - -echo "Building the ${FG_BLUE}Updater${RESET}" -dotnet publish GuiUpdater/GuiUpdater.csproj -c Release -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime win-x64 -dotnet publish GuiUpdater/GuiUpdater.csproj -c Release -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime linux-x64 -dotnet publish GuiUpdater/GuiUpdater.csproj -c Release -p:PublishSingleFile=true -p:Version=$version --self-contained --runtime osx-x64 - -# 4. Copy updater into release folders -echo "Copying ${FG_BLUE}Updater${RESET} files into ${FG_BLUE}Gui${RESET} folders" -cp GuiUpdater/bin/Release/$framework/win-x64/publish/* Gui/bin/Release/$framework/win-x64/publish -cp GuiUpdater/bin/Release/$framework/linux-x64/publish/* Gui/bin/Release/$framework/linux-x64/publish -cp GuiUpdater/bin/Release/$framework/osx-x64/publish/* Gui/bin/Release/$framework/osx-x64/publish - -# 5. Create the zip and tar archives -pushd "Gui/bin/Release/$framework/" - -echo "Zipping ${FG_BLUE}win-x64${RESET}" -pushd "win-x64/publish" -zip -r "object-editor-$version-win-x64.zip" . -mv "object-editor-$version-win-x64.zip" ../../.. -popd - -echo "Zipping ${FG_BLUE}linux-x64${RESET}" -pushd "linux-x64/publish" -chmod +x "./ObjectEditor" -chmod +x "./ObjectEditorUpdater" -# error happens if you make tar file inside the dir its zipping. hack is to touch it first then exclude it -touch "object-editor-$version-linux-x64.tar" -tar --exclude="object-editor-$version-linux-x64.tar" -jcf "object-editor-$version-linux-x64.tar" . -mv "object-editor-$version-linux-x64.tar" ../../.. -popd - -echo "Zipping ${FG_BLUE}osx-x64${RESET}" -pushd "osx-x64/publish" -chmod +x "./ObjectEditor" -chmod +x "./ObjectEditorUpdater" -# error happens if you make tar file inside the dir its zipping. hack is to touch it first then exclude it -touch "object-editor-$version-osx-x64.tar" -tar --exclude="object-editor-$version-osx-x64.tar" -jcf "object-editor-$version-osx-x64.tar" . -mv "object-editor-$version-osx-x64.tar" ../../.. -popd - -popd +# Restore dependencies first to avoid race conditions during parallel builds +dotnet restore Gui/Gui.csproj +dotnet restore GuiUpdater/GuiUpdater.csproj + +# 3. Build the editor for different platforms in parallel +build_windows +build_linux +build_macos + + echo "=== Build and packaging ${FG_GREEN}complete${RESET}! ==="