Skip to content

Commit

Permalink
Merge pull request #1 from laggykiller/universal2_wheel
Browse files Browse the repository at this point in the history
Universal2 wheel
  • Loading branch information
laggykiller authored Sep 8, 2023
2 parents 0c38e85 + fdff5e3 commit cc30587
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 94 deletions.
182 changes: 97 additions & 85 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Build and upload to PyPI

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
# release:
# types:
# - [published]
Expand All @@ -16,24 +16,24 @@ jobs:
fail-fast: false
matrix:
include:
- os: windows-2019
arch: x64
submodules_mode: true
cibw_archs_windows: AMD64
cibw_environment: APNGASM_COMPILE_TARGET=x64
cibw_before_all: prepare-win.bat
- os: windows-2019
arch: x86
submodules_mode: true
cibw_archs_windows: x86
cibw_environment: APNGASM_COMPILE_TARGET=x86
cibw_before_all: prepare-win.bat
- os: windows-2019
arch: arm64
submodules_mode: true
cibw_archs_windows: ARM64
cibw_environment: APNGASM_COMPILE_TARGET=ARM64
cibw_before_all: prepare-win.bat
# - os: windows-2019
# arch: x64
# submodules_mode: true
# cibw_archs_windows: AMD64
# cibw_environment: APNGASM_COMPILE_TARGET=x64
# cibw_before_all: prepare-win.bat
# - os: windows-2019
# arch: x86
# submodules_mode: true
# cibw_archs_windows: x86
# cibw_environment: APNGASM_COMPILE_TARGET=x86
# cibw_before_all: prepare-win.bat
# - os: windows-2019
# arch: arm64
# submodules_mode: true
# cibw_archs_windows: ARM64
# cibw_environment: APNGASM_COMPILE_TARGET=ARM64
# cibw_before_all: prepare-win.bat
- os: macos-11
arch: x64
submodules_mode: true
Expand All @@ -60,58 +60,70 @@ jobs:
VCPKG_C_FLAGS="-mmacosx-version-min=11.0"
VCPKG_CXX_FLAGS="-mmacosx-version-min=11.0"
cibw_before_all: ./prepare-mac.sh
- os: ubuntu-20.04
arch: x64
submodules_mode: true
cibw_archs_linux: x86_64
cibw_before_all: ./prepare-linux.sh
- os: ubuntu-20.04
arch: x86
submodules_mode: true
cibw_archs_linux: i686
cibw_before_all: ./prepare-linux.sh
- os: ubuntu-20.04
arch: arm64
submodules_mode: true
cibw_archs_linux: aarch64
cibw_skip: "*-muslinux_* pp*"
cibw_before_all: ./prepare-linux.sh
- os: ubuntu-20.04
arch: arm64
submodules_mode: true
cibw_archs_linux: aarch64
cibw_skip: "*-multilinux_* pp*"
cibw_before_all: ./prepare-linux.sh
- os: ubuntu-20.04
arch: arm64
submodules_mode: true
cibw_archs_linux: aarch64
cibw_skip: "*-muslinux_* *-multilinux_*"
cibw_before_all: ./prepare-linux.sh
- os: ubuntu-20.04
arch: ppc64le
submodules_mode: true
cibw_archs_linux: ppc64le
cibw_skip: "*-muslinux_*"
cibw_before_all: ./prepare-linux.sh
- os: ubuntu-20.04
arch: ppc64le
submodules_mode: true
cibw_archs_linux: ppc64le
cibw_skip: "*-multilinux_*"
cibw_before_all: ./prepare-linux.sh
- os: ubuntu-20.04
arch: s390x
submodules_mode: true
cibw_archs_linux: s390x
cibw_skip: "*-muslinux_*"
cibw_before_all: ./prepare-linux.sh
- os: ubuntu-20.04
arch: s390x
- os: macos-11
arch: universal2
submodules_mode: true
cibw_archs_linux: s390x
cibw_skip: "*-multilinux_*"
cibw_before_all: ./prepare-linux.sh
cibw_archs_macos: universal2
cibw_environment: >
APNGASM_COMPILE_TARGET=universal2
_PYTHON_HOST_PLATFORM=macosx-11.0-universal2
VCPKG_OSX_DEPLOYMENT_TARGET=11.0
MACOSX_DEPLOYMENT_TARGET=11.0
CMAKE_OSX_DEPLOYMENT_TARGET=11.0
VCPKG_C_FLAGS="-mmacosx-version-min=11.0"
VCPKG_CXX_FLAGS="-mmacosx-version-min=11.0"
# - os: ubuntu-20.04
# arch: x64
# submodules_mode: true
# cibw_archs_linux: x86_64
# cibw_before_all: ./prepare-linux.sh
# - os: ubuntu-20.04
# arch: x86
# submodules_mode: true
# cibw_archs_linux: i686
# cibw_before_all: ./prepare-linux.sh
# - os: ubuntu-20.04
# arch: arm64
# submodules_mode: true
# cibw_archs_linux: aarch64
# cibw_skip: "*-muslinux_* pp*"
# cibw_before_all: ./prepare-linux.sh
# - os: ubuntu-20.04
# arch: arm64
# submodules_mode: true
# cibw_archs_linux: aarch64
# cibw_skip: "*-multilinux_* pp*"
# cibw_before_all: ./prepare-linux.sh
# - os: ubuntu-20.04
# arch: arm64
# submodules_mode: true
# cibw_archs_linux: aarch64
# cibw_skip: "*-muslinux_* *-multilinux_*"
# cibw_before_all: ./prepare-linux.sh
# - os: ubuntu-20.04
# arch: ppc64le
# submodules_mode: true
# cibw_archs_linux: ppc64le
# cibw_skip: "*-muslinux_*"
# cibw_before_all: ./prepare-linux.sh
# - os: ubuntu-20.04
# arch: ppc64le
# submodules_mode: true
# cibw_archs_linux: ppc64le
# cibw_skip: "*-multilinux_*"
# cibw_before_all: ./prepare-linux.sh
# - os: ubuntu-20.04
# arch: s390x
# submodules_mode: true
# cibw_archs_linux: s390x
# cibw_skip: "*-muslinux_*"
# cibw_before_all: ./prepare-linux.sh
# - os: ubuntu-20.04
# arch: s390x
# submodules_mode: true
# cibw_archs_linux: s390x
# cibw_skip: "*-multilinux_*"
# cibw_before_all: ./prepare-linux.sh

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -171,18 +183,18 @@ jobs:
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# repository_url: https://test.pypi.org/legacy/

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist
# upload_pypi:
# needs: [build_wheels, build_sdist]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/download-artifact@v3
# with:
# # unpacks default artifact into dist/
# # if `name: artifact` is omitted, the action will create extra parent dir
# name: artifact
# path: dist

- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
# - uses: pypa/[email protected]
# with:
# user: __token__
# password: ${{ secrets.PYPI_API_TOKEN }}
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ if (DEFINED VCPKG_INSTALLATION_ROOT)
set(ZLIB_ROOT ${VCPKG_INSTALLATION_ROOT}/installed)
set(PNG_ROOT ${VCPKG_INSTALLATION_ROOT}/installed)
set(Boost_ROOT ${VCPKG_INSTALLATION_ROOT}/installed)

set(VCPKG_TARGET_TRIPLET ${APNGASM_COMPILE_TARGET}-${PLATFORM})

include_directories(${VCPKG_INSTALLATION_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/include)
set(LIBZ_PATH ${VCPKG_INSTALLATION_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/lib/${LIBZ_NAME}${STATIC_LIBRARY_SUFFIX})
set(LIBPNG_PATH ${VCPKG_INSTALLATION_ROOT}/installed/${VCPKG_TARGET_TRIPLET}/lib/${LIBPNG_NAME}${STATIC_LIBRARY_SUFFIX})

set(CMAKE_TOOLCHAIN_FILE "${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "Vcpkg toolchain file")
else()
Expand Down
61 changes: 61 additions & 0 deletions lipo-dir-merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright (C) Falko Axmann. All rights reserved.
# Licensed under the GPL v3 license.
#
# This script merges two directories containing static libraries for
# two different architectures into one directory with universal binaries.
# Files that don't end in ".a" will just be copied over from the first directory.
#
# Run it like this:
# `python3 lipo-dir-merge.py <arm64-dir-tree> <x64-dir-tree> <universal-output-dir>`

import sys
import shutil
import os
import subprocess

#
# Make sure we got enough arguments on the command line
#
if len(sys.argv) < 4:
print("Not enough args")
print(f"{sys.argv[0]} <primary directory> <other architecture source> <destination>")
sys.exit(-1)

# This is where we take most of the files from
primary_path = sys.argv[1]
# This is the directory tree from which we take libraries of the alternative arch
secondary_path = sys.argv[2]
# This is where we copy stuff to
destination_path = sys.argv[3]


# Merge the libraries at `src1` and `src2` and create a
# universal binary at `dst`
def merge_libs(src1, src2, dst):
subprocess.run(["lipo", "-create", src1, src2, "-output", dst])

# Find the library at `src` in the `secondary_path` and then
# merge the two versions, creating a universal binary at `dst`.
def find_and_merge_libs(src, dst):
rel_path = os.path.relpath(src, primary_path)
lib_in_secondary = os.path.join(secondary_path, rel_path)

if os.path.exists(lib_in_secondary) == False:
print("Lib not found in secondary source: {lib_in_secondary}")
return

merge_libs(src, lib_in_secondary, dst)

# Either copy the file at `src` to `dst`, or, if it is a static
# library, merge it with its version from `secondary_path` and
# write the universal binary to `dst`.
def copy_file_or_merge_libs(src, dst, *, follow_symlinks=True):
_, file_ext = os.path.splitext(src)
if file_ext == ".a":
find_and_merge_libs(src, dst)
else:
shutil.copy2(src, dst, follow_symlinks=follow_symlinks)

# Use copytree to do most of the work, with our own `copy_function` doing a little bit
# of magic in case of static libraries.
shutil.copytree(primary_path, destination_path, copy_function=copy_file_or_merge_libs)
29 changes: 21 additions & 8 deletions prepare-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,34 @@ if [[ $? -ne 0 ]]; then
CORES=2
fi

function vcpkg_install() {
${VCPKG_INSTALLATION_ROOT}/vcpkg install zlib:$1-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install libpng:$1-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-program-options:$1-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-regex:$1-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-system:$1-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-algorithm:$1-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-property-tree:$1-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-foreach:$1-osx
}

# Cross compiling supported only through vcpkg
if [[ ! -z $VCPKG_INSTALLATION_ROOT ]]; then
export VCPKG_OSX_DEPLOYMENT_TARGET=10.15
export VCPKG_C_FLAGS="-mmacosx-version-min=10.15"
export VCPKG_CXX_FLAGS="-mmacosx-version-min=10.15"
export APNGASM_COMPILE_TARGET=$(./get-target-mac.sh)

${VCPKG_INSTALLATION_ROOT}/vcpkg install zlib:${APNGASM_COMPILE_TARGET}-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install libpng:${APNGASM_COMPILE_TARGET}-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-program-options:${APNGASM_COMPILE_TARGET}-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-regex:${APNGASM_COMPILE_TARGET}-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-system:${APNGASM_COMPILE_TARGET}-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-algorithm:${APNGASM_COMPILE_TARGET}-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-property-tree:${APNGASM_COMPILE_TARGET}-osx
${VCPKG_INSTALLATION_ROOT}/vcpkg install boost-foreach:${APNGASM_COMPILE_TARGET}-osx
if [[ $APNGASM_COMPILE_TARGET != 'universal2' ]]; then
vcpkg_install ${APNGASM_COMPILE_TARGET}
else
vcpkg_install x64
vcpkg_install arm64
python3 lipo-dir-merge.py \
${VCPKG_INSTALLATION_ROOT}/installed/arm64-osx \
${VCPKG_INSTALLATION_ROOT}/installed/x64-osx \
${VCPKG_INSTALLATION_ROOT}/installed/universal2-osx
fi
else
which -s brew
if [[ $? != 0 ]] ; then
Expand Down

0 comments on commit cc30587

Please sign in to comment.