Skip to content

Commit

Permalink
Build macOS universal2 and arm64 package
Browse files Browse the repository at this point in the history
  • Loading branch information
laggykiller committed Sep 11, 2023
1 parent b19285c commit aac2c27
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 31 deletions.
49 changes: 39 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ name: Build

on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
# tags:
# - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:

createrelease:
name: Create Release
runs-on: [ubuntu-latest]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -52,18 +53,43 @@ jobs:
pyinstaller sticker_convert.spec
cd dist
Compress-Archive -Path sticker-convert -DestinationPath sticker-convert-windows.zip
OUT_FILE_NAME: sticker-convert-windows.zip
OUT_FILE_NAME: ./dist/sticker-convert-windows.zip
- os: macos-11
TARGET: macos
CMD_BUILD: |
python -m pip install --upgrade pip
pip install wheel
pip install -r requirements-build.txt
pyinstaller sticker_convert.spec
cp run_me_first.command ./dist
python -m venv venv
source ./venv/bin/activate
pip install wheel delocate pyinstaller~=5.13.2
pip install -r requirements-src.txt
mkdir wheel_arm
mkdir wheel_x64
mkdir wheel_universal2
pip download -r requirements-bin.txt --platform macosx_11_0_arm64 --only-binary=:all: -d wheel_arm
pip download -r requirements-bin.txt --platform macosx_11_0_x86_64 --only-binary=:all: -d wheel_x64
python ./scripts/delocate-fuse-dir.py ./wheel_arm ./wheel_x64 ./wheel_universal2
pip install ./wheel_universal2/*.whl
SC_TARGET_ARCH=x86_64 pyinstaller sticker_convert.spec
cp ./scripts/run_me_first.command ./dist
cd dist/
zip -r9 sticker-convert-macos-x86_64.zip sticker-convert.app run_me_first.command
OUT_FILE_NAME: sticker-convert-macos-x86_64.zip
cd ../
SC_TARGET_ARCH=arm64 pyinstaller sticker_convert.spec
cp ./scripts/run_me_first.command ./dist
cd dist/
zip -r9 sticker-convert-macos-arm64.zip sticker-convert.app run_me_first.command
cd ../
SC_TARGET_ARCH=universal2 pyinstaller sticker_convert.spec
cp ./scripts/run_me_first.command ./dist
cd dist/
zip -r9 sticker-convert-macos-universal2.zip sticker-convert.app run_me_first.command
OUT_FILE_NAME: |
./dist/sticker-convert-macos-x86_64.zip
./dist/sticker-convert-macos-arm64.zip
./dist/sticker-convert-macos-universal2.zip
- os: ubuntu-20.04
TARGET: linux
CMD_BUILD: |
Expand All @@ -87,7 +113,7 @@ jobs:
chmod +x sticker-convert-x86_64.AppImage
mkdir dist
mv ./sticker-convert-x86_64.AppImage ./dist/sticker-convert-x86_64.AppImage
OUT_FILE_NAME: sticker-convert-x86_64.AppImage
OUT_FILE_NAME: ./dist/sticker-convert-x86_64.AppImage
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -106,10 +132,11 @@ jobs:
- name: Upload Release Asset
id: upload-release-asset
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: dist/${{ matrix.OUT_FILE_NAME}}
files: dist/${{ matrix.OUT_FILE_NAME }}

build-docker:
name: Build Docker image and push
Expand Down Expand Up @@ -146,6 +173,7 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v4
if: startsWith(github.ref, 'refs/tags/v')
with:
context: .
push: true
Expand All @@ -156,6 +184,7 @@ jobs:
name: Upload to pypi
needs: [build-wheel, build-binary]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RUN apt purge -y curl wget gpg git && \
apt autoremove --yes && \
rm -rf /var/lib/{apt,dpkg,cache,log}/

COPY startapp.sh /startapp.sh
COPY ./scripts/startapp.sh /startapp.sh
COPY ./src /app/

RUN chmod -R 777 /app
Expand Down
17 changes: 17 additions & 0 deletions requirements-bin.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apngasm_python~=1.0.7
av~=10.0.0
beautifulsoup4~=4.12.2
browser-cookie3~=0.19.1
imageio~=2.31.3
memory-tempfile~=2.2.3
mergedeep~=1.3.4
Pillow~=10.0.0
pyoxipng~=8.0.0
python-telegram-bot~=20.5
requests~=2.31.0
rlottie_python~=1.1.5
selenium~=4.12.0
signalstickers-client~=3.3.0
tqdm~=4.66.1
ttkbootstrap-fork-laggykiller~=1.5.1
webp~=0.2.0
1 change: 1 addition & 0 deletions requirements-src.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lottie~=0.7.0
20 changes: 2 additions & 18 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,2 @@
apngasm_python~=1.0.4
av~=10.0.0
beautifulsoup4~=4.12.2
browser-cookie3~=0.19.1
imageio~=2.31.3
lottie~=0.7.0
memory-tempfile~=2.2.3
mergedeep~=1.3.4
Pillow~=10.0.0
pyoxipng~=8.0.0
python-telegram-bot~=20.5
requests~=2.31.0
rlottie_python~=1.1.4
selenium~=4.12.0
signalstickers-client~=3.3.0
tqdm~=4.66.1
ttkbootstrap-fork-laggykiller~=1.5.1
webp~=0.1.8
-r requirements-src.txt
-r requirements-bin.txt
44 changes: 44 additions & 0 deletions scripts/delocate-fuse-dir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
# A script for creating universal2 wheels from x86_64 and arm64 wheels
# Used for creating macOS application

import sys
import os
import shutil
import subprocess

in_dir1 = sys.argv[1]
in_dir2 = sys.argv[2]
out_dir = sys.argv[3]

def search_wheel_in_dir(package, dir):
for i in os.listdir(dir):
if i.startswith(package):
return i

def copy_if_universal(wheel_name, in_dir, out_dir):
if wheel_name.endswith('universal2.whl') or wheel_name.endswith('any.whl'):
src_path = os.path.join(in_dir, wheel_name)
dst_path = os.path.join(
out_dir,
wheel_name
.replace('x86_64', 'universal2')
.replace('arm64', 'universal2')
)

shutil.copy(src_path, dst_path)
return True
else:
return False

for wheel_name_1 in os.listdir(in_dir1):
package = wheel_name_1.split('-')[0]
wheel_name_2 = search_wheel_in_dir(package, in_dir2)
if copy_if_universal(wheel_name_1, in_dir1, out_dir):
continue
if copy_if_universal(wheel_name_2, in_dir2, out_dir):
continue

wheel_path_1 = os.path.join(in_dir1, wheel_name_1)
wheel_path_2 = os.path.join(in_dir2, wheel_name_2)
subprocess.run(['delocate-fuse', wheel_path_1, wheel_path_2, '-w', out_dir])
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions sticker_convert.spec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ else:
proot = os.path.dirname(importlib.import_module('rlottie_python').__file__)
datas.append((os.path.join(proot, rlottie_dll), 'rlottie_python/'))

target_arch = os.getenv('SC_TARGET_ARCH')

a = Analysis(
['src/sticker_convert/__main__.py'],
pathex=['src/sticker_convert'],
Expand Down Expand Up @@ -52,7 +54,7 @@ exe = EXE(
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
target_arch=target_arch,
codesign_identity=None,
entitlements_file=None,
icon='./src/sticker_convert/resources/appicon.ico'
Expand All @@ -71,4 +73,4 @@ coll = COLLECT(
app = BUNDLE(coll,
name=f'sticker-convert.app',
icon='./src/sticker_convert/resources/appicon.icns',
bundle_identifier=None)
bundle_identifier=None)

0 comments on commit aac2c27

Please sign in to comment.