Skip to content

Commit 8832b27

Browse files
committed
Adds support for unified/fat binary on macOS, which supports both arm64 and x64 architectures -- Thanks to 3DICC and Eliot for providing the baseline for this implementation!
1 parent 0724852 commit 8832b27

File tree

4 files changed

+135
-2
lines changed

4 files changed

+135
-2
lines changed

env_vars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ readonly VM_LIN_X86="vm-linux"
1313
readonly VM_LIN_ARM="vm-linux-arm"
1414
readonly VM_MAC_X86="vm-macos"
1515
readonly VM_MAC_ARM="vm-macos-arm"
16+
readonly VM_MAC="vm-macos-unified"
1617
readonly VM_WIN_X86="vm-win"
1718
readonly VM_WIN_ARM="vm-win-arm"
1819

helpers_bundles.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,77 @@ copy_resources() {
139139
cp -R "${TMP_PATH}/ExampleEtoys" "${target}/"
140140
fi
141141
}
142+
143+
# Make a fat binary from a pair of VMs in
144+
# build.macos64{x64,ARMv8}/virtend.cog.spur/Virtend*.app
145+
# To choose the oldest nib the oldest deployment target (x86_64) should be last
146+
create_unified_vm_macOS() {
147+
local MISMATCHINGNIBS=
148+
local MISMATCHINGPLISTS=
149+
150+
readonly O="$1"
151+
readonly A="$2"
152+
readonly B="$3"
153+
154+
if [ ! -d "$A" ]; then
155+
echo "$A does not exist; aborting"
156+
exit 44
157+
fi
158+
159+
if [ ! -d "$B" ]; then
160+
echo "$B does not exist; aborting"
161+
exit 45
162+
fi
163+
164+
echo "merging $A \& $B into $O..."
165+
mkdir -p $O
166+
167+
for f in `cd $A >/dev/null; find . | sed 's|^\.\/||'`; do
168+
if [ -d "$A/$f" ]; then
169+
mkdir -p $O/$f
170+
# elif [ -L "$A/$f" ]; then
171+
# echo ln -s `readlink "$A/$f"` "$O/$f"
172+
elif [ ! -f "$A/$f" ]; then
173+
echo "$A/$f does not exist; how come?"
174+
elif [ ! -f "$B/$f" ]; then
175+
echo "$B/$f does not exist; how come?"
176+
else
177+
case `file -b "$A/$f"` in
178+
Mach-O*)
179+
lipo -create -output "$O/$f" "$A/$f" "$B/$f";;
180+
*)
181+
if cmp -s "$A/$f" "$B/$f"; then
182+
cp "$A/$f" "$O/$f"
183+
else
184+
echo "EXCLUDING $f because it differs"
185+
case "$f" in
186+
*.plist)
187+
MISMATCHINGPLISTS="$MISMATCHINGPLISTS $f"
188+
;;
189+
*.nib)
190+
MISMATCHINGNIBS="$MISMATCHINGNIBS $f"
191+
echo "using $B version"
192+
cp "$B/$f" "$O/$f"
193+
;;
194+
esac
195+
fi
196+
esac
197+
fi
198+
done
199+
200+
if [ -n "$MISMATCHINGPLISTS" ]; then
201+
echo "Builds $A \& $B are NOT in perfect sync. Rebuild one or other to resolve"
202+
for f in $MISMATCHINGPLISTS; do
203+
echo "$f"
204+
diff $A/$f $B/$f
205+
done
206+
exit 46
207+
fi
208+
209+
if [ -n "$MISMATCHINGNIBS" ]; then
210+
echo "Builds $A \& $B are NOT in perfect sync. ui nibs differ. Took $B\'s"
211+
for f in $MISMATCHINGNIBS; do
212+
echo $f
213+
done
214+
fi
215+
}

prepare_bundle_macos.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
################################################################################
3+
# PROJECT: Squeak Bundle Generation
4+
# FILE: prepare_bundle_macos_arm.sh
5+
# CONTENT: Generate bundle for macOS (unified, arm64 and x64).
6+
#
7+
# AUTHORS: Fabio Niephaus, Hasso Plattner Institute, Potsdam, Germany
8+
# Marcel Taeumel, Hasso Plattner Institute, Potsdam, Germany
9+
################################################################################
10+
11+
begin_group "Creating macOS bundle for ${SMALLTALK_VERSION}..."
12+
BUNDLE_NAME_MAC="${IMAGE_NAME}-${VERSION_VM_MACOS}"
13+
export_variable "BUNDLE_NAME_MAC" "${BUNDLE_NAME_MAC}"
14+
BUNDLE_ID_MAC="org.squeak.$(echo ${SQUEAK_VERSION} | tr '[:upper:]' '[:lower:]')-${IMAGE_BITS}bit"
15+
APP_NAME="${IMAGE_NAME}.app"
16+
APP_PATH="${BUILD_PATH}/${APP_NAME}"
17+
CONTENTS_PATH="${APP_PATH}/Contents"
18+
RESOURCES_PATH="${CONTENTS_PATH}/Resources"
19+
VM_MAC_TARGET="${CONTENTS_PATH}/MacOS"
20+
21+
echo "...copying macOS VM (unified)..."
22+
if is_dir "${TMP_PATH}/${VM_MAC}/Squeak.app"; then
23+
cp -R "${TMP_PATH}/${VM_MAC}/Squeak.app" "${APP_PATH}"
24+
else
25+
echo "Unable to locate macOS VM." && exit 1
26+
fi
27+
28+
copy_resources "${RESOURCES_PATH}"
29+
30+
echo "...merging template..."
31+
cp "${MAC_TEMPLATE_PATH}/Squeak.app/Contents/Info.plist" "${CONTENTS_PATH}/"
32+
cp "${ICONS_PATH}/${SMALLTALK_NAME}"*.icns "${RESOURCES_PATH}/"
33+
ENGLISH_PATH="${MAC_TEMPLATE_PATH}/Squeak.app/Contents/Resources/English.lproj"
34+
cp "${ENGLISH_PATH}/Credits.rtf" "${RESOURCES_PATH}/English.lproj/"
35+
36+
echo "...setting permissions..."
37+
chmod +x "${VM_MAC_TARGET}/Squeak"
38+
39+
echo "...patching Info.plist..."
40+
# Info.plist
41+
sed -i".bak" "s/%SmalltalkName%/${SMALLTALK_NAME}/g" "${CONTENTS_PATH}/Info.plist"
42+
sed -i".bak" "s/%CFBundleGetInfoString%/${BUNDLE_NAME_MAC}/g" "${CONTENTS_PATH}/Info.plist"
43+
sed -i".bak" "s/%CFBundleIdentifier%/${BUNDLE_ID_MAC}/g" "${CONTENTS_PATH}/Info.plist"
44+
sed -i".bak" "s/%CFBundleName%/${SMALLTALK_NAME}/g" "${CONTENTS_PATH}/Info.plist"
45+
sed -i".bak" "s/%CFBundleShortVersionString%/${SQUEAK_VERSION_NUMBER}/g" "${CONTENTS_PATH}/Info.plist"
46+
sed -i".bak" "s/%CFBundleVersion%/${IMAGE_BITS} bit/g" "${CONTENTS_PATH}/Info.plist"
47+
sed -i".bak" "s/%SqueakImageName%/${IMAGE_NAME}.image/g" "${CONTENTS_PATH}/Info.plist"
48+
rm -f "${CONTENTS_PATH}/Info.plist.bak"
49+
50+
if should_codesign; then
51+
do_codesign "${APP_PATH}" # *.app
52+
fi
53+
54+
compress_into_product_macOS "${APP_PATH}" "${BUNDLE_NAME_MAC}"
55+
reset_build_dir
56+
57+
end_group

prepare_bundles.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ if should_use_rc_vm; then
6767
else
6868
download_and_extract_all_vms
6969
fi
70+
create_unified_vm_macOS "${TMP_PATH}/${VM_MAC}" "${TMP_PATH}/${VM_MAC_ARM}" "${TMP_PATH}/${VM_MAC_X86}"
7071

7172
if should_codesign; then
7273
source "helpers_codesign.sh"
@@ -75,12 +76,12 @@ fi
7576

7677
prepare_image_bundle # Just .image and .changes in an archive
7778
if is_64bit; then
78-
# source "prepare_bundle_aio.sh"
79-
# source "prepare_bundle_macos.sh" # Unified binary x86+ARM
79+
source "prepare_bundle_macos.sh" # Unified binary arm64+x64
8080
source "prepare_bundle_macos_x86.sh"
8181
source "prepare_bundle_macos_arm.sh"
8282
fi
8383

84+
source "prepare_bundle_aio.sh"
8485
source "prepare_bundle_linux_x86.sh"
8586
source "prepare_bundle_linux_arm.sh"
8687
source "prepare_bundle_windows_x86.sh"

0 commit comments

Comments
 (0)