diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ad36f8b..9f174d3 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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] @@ -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 @@ -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 @@ -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/gh-action-pypi-publish@v1.5.0 - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file + # - uses: pypa/gh-action-pypi-publish@v1.5.0 + # with: + # user: __token__ + # password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 288b857..869b909 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/lipo-dir-merge.py b/lipo-dir-merge.py new file mode 100644 index 0000000..5e2e402 --- /dev/null +++ b/lipo-dir-merge.py @@ -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 ` + +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]} ") + 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) \ No newline at end of file diff --git a/prepare-mac.sh b/prepare-mac.sh index 9134c01..a004001 100755 --- a/prepare-mac.sh +++ b/prepare-mac.sh @@ -9,6 +9,17 @@ 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 @@ -16,14 +27,16 @@ if [[ ! -z $VCPKG_INSTALLATION_ROOT ]]; then 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