Skip to content

Commit

Permalink
Adds support for unified/fat binary on macOS, which supports both arm…
Browse files Browse the repository at this point in the history
…64 and x64 architectures -- Thanks to 3DICC and Eliot for providing the baseline for this implementation!
  • Loading branch information
marceltaeumel committed Jan 5, 2022
1 parent 0724852 commit 8832b27
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 2 deletions.
1 change: 1 addition & 0 deletions env_vars
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ readonly VM_LIN_X86="vm-linux"
readonly VM_LIN_ARM="vm-linux-arm"
readonly VM_MAC_X86="vm-macos"
readonly VM_MAC_ARM="vm-macos-arm"
readonly VM_MAC="vm-macos-unified"
readonly VM_WIN_X86="vm-win"
readonly VM_WIN_ARM="vm-win-arm"

Expand Down
74 changes: 74 additions & 0 deletions helpers_bundles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,77 @@ copy_resources() {
cp -R "${TMP_PATH}/ExampleEtoys" "${target}/"
fi
}

# Make a fat binary from a pair of VMs in
# build.macos64{x64,ARMv8}/virtend.cog.spur/Virtend*.app
# To choose the oldest nib the oldest deployment target (x86_64) should be last
create_unified_vm_macOS() {
local MISMATCHINGNIBS=
local MISMATCHINGPLISTS=

readonly O="$1"
readonly A="$2"
readonly B="$3"

if [ ! -d "$A" ]; then
echo "$A does not exist; aborting"
exit 44
fi

if [ ! -d "$B" ]; then
echo "$B does not exist; aborting"
exit 45
fi

echo "merging $A \& $B into $O..."
mkdir -p $O

for f in `cd $A >/dev/null; find . | sed 's|^\.\/||'`; do
if [ -d "$A/$f" ]; then
mkdir -p $O/$f
# elif [ -L "$A/$f" ]; then
# echo ln -s `readlink "$A/$f"` "$O/$f"
elif [ ! -f "$A/$f" ]; then
echo "$A/$f does not exist; how come?"
elif [ ! -f "$B/$f" ]; then
echo "$B/$f does not exist; how come?"
else
case `file -b "$A/$f"` in
Mach-O*)
lipo -create -output "$O/$f" "$A/$f" "$B/$f";;
*)
if cmp -s "$A/$f" "$B/$f"; then
cp "$A/$f" "$O/$f"
else
echo "EXCLUDING $f because it differs"
case "$f" in
*.plist)
MISMATCHINGPLISTS="$MISMATCHINGPLISTS $f"
;;
*.nib)
MISMATCHINGNIBS="$MISMATCHINGNIBS $f"
echo "using $B version"
cp "$B/$f" "$O/$f"
;;
esac
fi
esac
fi
done

if [ -n "$MISMATCHINGPLISTS" ]; then
echo "Builds $A \& $B are NOT in perfect sync. Rebuild one or other to resolve"
for f in $MISMATCHINGPLISTS; do
echo "$f"
diff $A/$f $B/$f
done
exit 46
fi

if [ -n "$MISMATCHINGNIBS" ]; then
echo "Builds $A \& $B are NOT in perfect sync. ui nibs differ. Took $B\'s"
for f in $MISMATCHINGNIBS; do
echo $f
done
fi
}
57 changes: 57 additions & 0 deletions prepare_bundle_macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
################################################################################
# PROJECT: Squeak Bundle Generation
# FILE: prepare_bundle_macos_arm.sh
# CONTENT: Generate bundle for macOS (unified, arm64 and x64).
#
# AUTHORS: Fabio Niephaus, Hasso Plattner Institute, Potsdam, Germany
# Marcel Taeumel, Hasso Plattner Institute, Potsdam, Germany
################################################################################

begin_group "Creating macOS bundle for ${SMALLTALK_VERSION}..."
BUNDLE_NAME_MAC="${IMAGE_NAME}-${VERSION_VM_MACOS}"
export_variable "BUNDLE_NAME_MAC" "${BUNDLE_NAME_MAC}"
BUNDLE_ID_MAC="org.squeak.$(echo ${SQUEAK_VERSION} | tr '[:upper:]' '[:lower:]')-${IMAGE_BITS}bit"
APP_NAME="${IMAGE_NAME}.app"
APP_PATH="${BUILD_PATH}/${APP_NAME}"
CONTENTS_PATH="${APP_PATH}/Contents"
RESOURCES_PATH="${CONTENTS_PATH}/Resources"
VM_MAC_TARGET="${CONTENTS_PATH}/MacOS"

echo "...copying macOS VM (unified)..."
if is_dir "${TMP_PATH}/${VM_MAC}/Squeak.app"; then
cp -R "${TMP_PATH}/${VM_MAC}/Squeak.app" "${APP_PATH}"
else
echo "Unable to locate macOS VM." && exit 1
fi

copy_resources "${RESOURCES_PATH}"

echo "...merging template..."
cp "${MAC_TEMPLATE_PATH}/Squeak.app/Contents/Info.plist" "${CONTENTS_PATH}/"
cp "${ICONS_PATH}/${SMALLTALK_NAME}"*.icns "${RESOURCES_PATH}/"
ENGLISH_PATH="${MAC_TEMPLATE_PATH}/Squeak.app/Contents/Resources/English.lproj"
cp "${ENGLISH_PATH}/Credits.rtf" "${RESOURCES_PATH}/English.lproj/"

echo "...setting permissions..."
chmod +x "${VM_MAC_TARGET}/Squeak"

echo "...patching Info.plist..."
# Info.plist
sed -i".bak" "s/%SmalltalkName%/${SMALLTALK_NAME}/g" "${CONTENTS_PATH}/Info.plist"
sed -i".bak" "s/%CFBundleGetInfoString%/${BUNDLE_NAME_MAC}/g" "${CONTENTS_PATH}/Info.plist"
sed -i".bak" "s/%CFBundleIdentifier%/${BUNDLE_ID_MAC}/g" "${CONTENTS_PATH}/Info.plist"
sed -i".bak" "s/%CFBundleName%/${SMALLTALK_NAME}/g" "${CONTENTS_PATH}/Info.plist"
sed -i".bak" "s/%CFBundleShortVersionString%/${SQUEAK_VERSION_NUMBER}/g" "${CONTENTS_PATH}/Info.plist"
sed -i".bak" "s/%CFBundleVersion%/${IMAGE_BITS} bit/g" "${CONTENTS_PATH}/Info.plist"
sed -i".bak" "s/%SqueakImageName%/${IMAGE_NAME}.image/g" "${CONTENTS_PATH}/Info.plist"
rm -f "${CONTENTS_PATH}/Info.plist.bak"

if should_codesign; then
do_codesign "${APP_PATH}" # *.app
fi

compress_into_product_macOS "${APP_PATH}" "${BUNDLE_NAME_MAC}"
reset_build_dir

end_group
5 changes: 3 additions & 2 deletions prepare_bundles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ if should_use_rc_vm; then
else
download_and_extract_all_vms
fi
create_unified_vm_macOS "${TMP_PATH}/${VM_MAC}" "${TMP_PATH}/${VM_MAC_ARM}" "${TMP_PATH}/${VM_MAC_X86}"

if should_codesign; then
source "helpers_codesign.sh"
Expand All @@ -75,12 +76,12 @@ fi

prepare_image_bundle # Just .image and .changes in an archive
if is_64bit; then
# source "prepare_bundle_aio.sh"
# source "prepare_bundle_macos.sh" # Unified binary x86+ARM
source "prepare_bundle_macos.sh" # Unified binary arm64+x64
source "prepare_bundle_macos_x86.sh"
source "prepare_bundle_macos_arm.sh"
fi

source "prepare_bundle_aio.sh"
source "prepare_bundle_linux_x86.sh"
source "prepare_bundle_linux_arm.sh"
source "prepare_bundle_windows_x86.sh"
Expand Down

0 comments on commit 8832b27

Please sign in to comment.