Skip to content

Build fig2sketch branch #10

Build fig2sketch branch

Build fig2sketch branch #10

Workflow file for this run

name: Build fig2sketch branch
on:
workflow_dispatch
jobs:
build:
name: Build
runs-on: ${{ matrix.runs }}
strategy:
matrix:
include:
- os: linux
arch: x86_64
runs: ubuntu-latest
ext: ""
- os: windows
arch: x86_64
runs: windows-latest
ext: ".exe"
- os: macos
arch: x86_64
runs: macos-12
ext: ""
- os: macos
arch: arm64
runs: macos-14
ext: ""
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.11"
architecture: x64 # Otherwise the runner will try to download Python arm64, which is not available. x64 has support for both archs (universal2).
- name: Install latest stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Build
run: |
python -m pip install --upgrade pip
pip install "pyinstaller>=5.12"
pip install certifi
pip install maturin
pip install .[fast]
bash -c "rm -rf /tmp/orjson"
bash scripts/install_patched_orjson.sh
pyinstaller src/fig2sketch.py -y --onefile --target-arch ${{ matrix.arch }}
- name: zip release
uses: thedoctor0/zip-release@main
with:
type: "zip"
filename: "fig2sketch-${{ matrix.os }}-${{ matrix.arch }}.zip"
directory: "dist"
path: "*"
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: builds
path: dist/fig2sketch-${{ matrix.os }}-${{ matrix.arch }}.zip
build-macos-universal:
needs: [build]
runs-on: macos-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: builds
- name: Create universal binary with lipo
# Why are we patching the binary?
# Both binaries are generated by pyinstaller. This works by archiving the python interpreter and .py files
# and then adding a binary that unarchives the content and runs them (similar to a self-extracting zip).
# The problem is that it locates the start of the archive inside the binary by looking for a specific magic value.
# Both binaries (x86_64 and arm64) use the same magic value, so after bundling in a universal binary, the bootloader
# will always find the first archive, even if it's the wrong architecture. Thus, only one architecture works.
# The binary patch applied below changes the magic value for only one of the binaries, so we have a different
# magic value to search for each architecture, which solves the problem.
# We need to re-sign the binary afterwards since the signature becomes invalid when tweaking the bytes
run: |
mkdir x86_64
mkdir arm64
mkdir -p dist
unzip fig2sketch-macos-x86_64.zip -d x86_64/
unzip fig2sketch-macos-arm64.zip -d arm64/
hexdump -ve '1/1 "%.2X"' x86_64/fig2sketch | sed "s/4D45490\([0C]\)0B0A0B0E/4D45490\10B0A0B0F/g" | xxd -r -p > x86_64/fig2sketch.patched
codesign --remove x86_64/fig2sketch.patched
codesign -s - x86_64/fig2sketch.patched
lipo -create x86_64/fig2sketch.patched arm64/fig2sketch -output dist/fig2sketch
- name: zip release
uses: thedoctor0/zip-release@main
with:
type: "zip"
filename: "fig2sketch-macos-universal.zip"
directory: "dist"
path: "*"
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: builds
path: dist/fig2sketch-macos-universal.zip