Skip to content

Commit

Permalink
Merge universal2 debloat script into prep
Browse files Browse the repository at this point in the history
This additionally skips building the wheel if it has already been built (e.g. for rapid development).
  • Loading branch information
spotlightishere committed May 16, 2024
1 parent ba58863 commit a83dc11
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 39 deletions.
16 changes: 14 additions & 2 deletions scripts/macos-universal2/build.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
#!/bin/bash
set -e

# Run everything relative to our script directory.
cd "$(dirname "$0")"

# Activate a virtual environment so we don't pollute the system environment.
python3 -m venv --upgrade-deps venv
source venv/bin/activate
python3 -m pip install wheel PyQt6
python3 -m pip install wheel

# Before we install anything further, create our custom universal2 version of
# the PyQt6 frameworks (PyQt6_Qt6), and then install PyQt6 itself.
bash prep-PyQt.sh
python3 -m pip install PyQt6

# Lastly, build our client.
# We'll override our default setup.py with one adjusted for macOS.
cd ../../client
python3 -m pip install -r requirements.txt py2app GitPython
python3 _version.py
Expand All @@ -11,7 +24,6 @@ py2applet --make-setup app.py icon.icns "icon.png" "taskbarDark.png" "taskbarLig
# build universal binary
sed -i '' -e "s/)/ name='NSO-RPC')/" setup.py
python3 setup.py py2app -O2 --arch=universal2
python3 ../scripts/macos-universal2/debloat-qt.py
# arm64 requires codesigning to run
codesign --deep --force --sign - dist/NSO-RPC.app/Contents/MacOS/*
open dist
30 changes: 0 additions & 30 deletions scripts/macos-universal2/debloat-qt.py

This file was deleted.

46 changes: 39 additions & 7 deletions scripts/macos-universal2/prep-PyQt.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
#!/bin/bash
set -e

# Provided by @spotlightishere on Github
# https://github.com/MCMi460/NSO-RPC/pull/86#issuecomment-1605700512

# If we already have a universal2 wheel available, install and process no further.
# https://stackoverflow.com/a/6364244
if compgen -G "./PyQt6_*universal2.whl"; then
python3 -m pip install PyQt6_*universal2.whl --force-reinstall
exit 0
fi

# Download and unpack
python3 -m pip download --only-binary=:all: --platform=macosx_13_0_x86_64 PyQt6_Qt6
python3 -m pip download --only-binary=:all: --platform=macosx_13_0_arm64 PyQt6_Qt6
python3 -m wheel unpack PyQt6_*arm64.whl --dest arm64
python3 -m wheel unpack PyQt6_*x86_64.whl --dest x86_64
python3 -m wheel unpack PyQt6_Qt6*arm64.whl --dest arm64
python3 -m wheel unpack PyQt6_Qt6*x86_64.whl --dest x86_64

# We'll use x86_64 as our basis.
# As of writing, PyQt6_Qt6 specifies a minimum of 10.14 for x86_64, and 11.0 for arm64.
# We'll reuse this tag; it should be updated if this ever changes in the future.
python3 -m wheel tags --platform-tag macosx_10_14_universal2 PyQt6_*x86_64.whl
python3 -m wheel unpack PyQt6_*universal2.whl --dest universal
python3 -m wheel tags --platform-tag macosx_10_14_universal2 PyQt6_Qt6*x86_64.whl
python3 -m wheel unpack PyQt6_Qt6*universal2.whl --dest universal

# https://stackoverflow.com/a/46020381
merge_frameworks() {
Expand All @@ -22,9 +31,32 @@ merge_frameworks() {
}
export -f merge_frameworks

# Iterate through all frameworks and libraries, and lipo together
# Iterate through all frameworks and libraries, and lipo together.
find universal -perm +111 -type f -exec sh -c 'merge_frameworks "$1"' _ {} \;
python3 -m wheel pack universal/PyQt6_*

# Finally, install our universal python3.11 -m wheel.
# We can now debloat our created universal wheel by removing
# frameworks and libraries irrelevant to NSO-RPC.
debloat_paths=(
"Qt6/lib/QtQuick3DRuntimeRender.framework"
"Qt6/lib/QtQuickParticles.framework"
"Qt6/lib/QtSpatialAudio.framework"
"Qt6/lib/QtShaderTools.framework"
"Qt6/lib/QtQuickTest.framework"
"Qt6/lib/QtBluetooth.framework"
"Qt6/lib/QtDesigner.framework"
"Qt6/lib/QtQuick.framework"
"Qt6/lib/QtHelp.framework"
"Qt6/lib/QtPdf.framework"
"Qt6/lib/QtQml.framework"
"Qt6/plugins/sqldrivers"
"Qt6/plugins/multimedia"
"Qt6/qml"
)

for debloat_path in "${debloat_paths[@]}"; do
rm -rf universal/PyQt6_Qt6*/PyQt6/$debloat_path
done

# Finally, pack and install our universal2 wheel.
python3 -m wheel pack universal/PyQt6_*
python3 -m pip install PyQt6_*universal2.whl --force-reinstall

0 comments on commit a83dc11

Please sign in to comment.