Acord/build.sh

78 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
BUILD="$ROOT/build"
APP="$BUILD/bin/Swiftly.app"
CONTENTS="$APP/Contents"
MACOS="$CONTENTS/MacOS"
RESOURCES="$CONTENTS/Resources"
SDK=$(xcrun --show-sdk-path)
RUST_LIB="$ROOT/target/release"
export MACOSX_DEPLOYMENT_TARGET=14.0
export ZERO_AR_DATE=0
echo "Building Rust workspace (release)..."
cd "$ROOT" && cargo build --release -p swiftly-viewport
if [ $? -ne 0 ]; then
echo "ERROR: Rust build failed"
exit 1
fi
if [ ! -f "$RUST_LIB/libswiftly_viewport.a" ]; then
echo "ERROR: libswiftly_viewport.a not found at $RUST_LIB"
exit 1
fi
RUST_FLAGS=(-import-objc-header "$ROOT/viewport/include/swiftly.h" -L "$RUST_LIB" -lswiftly_viewport)
# --- App icon from pre-rendered PNGs ---
ICONS="$ROOT/assets/icon_sources"
if [ -d "$ICONS" ]; then
echo "Generating app icon..."
ICONSET="$BUILD/AppIcon.iconset"
mkdir -p "$ICONSET"
cp "$ICONS/Swiftly_icons.png" "$ICONSET/icon_16x16.png"
cp "$ICONS/Swiftly_icons@2x.png" "$ICONSET/icon_16x16@2x.png"
cp "$ICONS/Swiftly_icons@2x.png" "$ICONSET/icon_32x32.png"
cp "$ICONS/Swiftly_icons@4x.png" "$ICONSET/icon_32x32@2x.png"
cp "$ICONS/Swiftly_icons@8x.png" "$ICONSET/icon_128x128.png"
cp "$ICONS/Swiftly_icons@16x.png" "$ICONSET/icon_128x128@2x.png"
cp "$ICONS/Swiftly_icons@16x.png" "$ICONSET/icon_256x256.png"
cp "$ICONS/Swiftly_icons@32.png" "$ICONSET/icon_256x256@2x.png"
cp "$ICONS/Swiftly_icons@32.png" "$ICONSET/icon_512x512.png"
cp "$ICONS/Swiftly_icons@64.png" "$ICONSET/icon_512x512@2x.png"
iconutil -c icns "$ICONSET" -o "$BUILD/AppIcon.icns"
rm -rf "$ICONSET"
fi
# --- Bundle structure ---
mkdir -p "$MACOS" "$RESOURCES"
cp "$ROOT/Info.plist" "$CONTENTS/Info.plist"
if [ -f "$BUILD/AppIcon.icns" ]; then
cp "$BUILD/AppIcon.icns" "$RESOURCES/AppIcon.icns"
fi
# --- Compile Swift ---
echo "Compiling Swift (release)..."
swiftc \
-target arm64-apple-macosx14.0 \
-sdk "$SDK" \
"${RUST_FLAGS[@]}" \
-framework Cocoa \
-framework SwiftUI \
-framework Metal \
-framework MetalKit \
-framework QuartzCore \
-framework CoreGraphics \
-framework CoreFoundation \
-O \
-o "$MACOS/Swiftly" \
"$ROOT"/src/*.swift
# --- Code sign ---
codesign --force --deep --sign - "$APP"
echo "Built: $APP"