diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-06-13 17:50:28 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-06-14 10:26:22 +0100 |
| commit | 45a641316a01b4861c887caf08058b2d48dfdc17 (patch) | |
| tree | 3d487e8a606c1730aced7c1d50f0dd363002c193 | |
| parent | 0f8d3c7b47a79d882f6376d5b3f4f4fae2ed904e (diff) | |
Simplify building of Windows wheels
| -rw-r--r-- | .github/workflows/build.yml | 62 | ||||
| -rw-r--r-- | build_jq.mk | 29 | ||||
| -rw-r--r-- | setup.py | 30 |
3 files changed, 43 insertions, 78 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c7523f6..0ff05e7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -101,14 +101,6 @@ jobs: ) echo matrix="$MATRIX" >> $GITHUB_OUTPUT - MATRIX_WIN=$( - { - env CIBW_SKIP="pp* cp36*" cibuildwheel --print-build-identifiers --platform windows \ - | sed 's/.*/{"cibw-only": "&", "os": "windows-latest" }/' - } | jq --slurp --compact-output '{"include": .}' - ) - echo matrix_win="$MATRIX_WIN" >> $GITHUB_OUTPUT - build_wheels: name: Build ${{ matrix.cibw-only }} wheel @@ -151,14 +143,13 @@ jobs: path: ./wheelhouse/*.whl build_wheels_win: - name: Build ${{ matrix.cibw-only }} wheel + name: Build Windows wheel - needs: build_wheels_matrix + runs-on: windows-2022 strategy: - matrix: ${{ fromJson(needs.build_wheels_matrix.outputs.matrix_win) }} - - runs-on: ${{ matrix.os }} + matrix: + arch: ["AMD64", "x86"] steps: @@ -173,46 +164,37 @@ jobs: uses: msys2/setup-msys2@v2 with: release: false - msystem: ${{ contains(matrix.cibw-only, 'win32') && 'mingw32' || 'ucrt64' }} - install: make mingw-w64-${{ contains(matrix.cibw-only, 'win32') && 'i686' || 'ucrt-x86_64' }}-gcc + msystem: ${{ matrix.arch == 'x86' && 'mingw32' || 'ucrt64' }} + install: make mingw-w64-${{ matrix.arch == 'x86' && 'i686' || 'ucrt-x86_64' }}-gcc - - name: Setup windows build variables - id: setup-build-win - shell: msys2 {0} - run: | - JQ_VERSION=$(ls deps/jq-*.tar.gz | grep -oP 'jq-\K[\d.]+(?=.tar.gz)') - echo jq-lib-version="$JQ_VERSION" >> $GITHUB_OUTPUT - echo arch=$( grep -o 'win_amd64\|win32' <<< ${{matrix.cibw-only}}) >> $GITHUB_OUTPUT - ${{ contains(matrix.cibw-only, 'win32') && 'echo "C:/msys64/mingw32/bin" >> $GITHUB_PATH' || 'echo no need to set PATH for win_amd64' }} - printf "[build]\ncompiler=mingw32" > setup.cfg - - - name: Cache pre-built jq lib - id: cache-prebuilt-jq - uses: actions/cache@v4 - with: - path: _deps/build - key: prebuilt-jq-${{steps.setup-build-win.outputs.jq-lib-version}}-${{ steps.setup-build-win.outputs.arch }} - - - name: Build jq lib - if: steps.cache-prebuilt-jq.outputs.cache-hit != 'true' + - name: Set PATH for x86 + if: ${{ matrix.arch == 'x86' }} shell: msys2 {0} - run: make -f build_jq.mk + run: echo "C:/msys64/mingw32/bin" >> "$GITHUB_PATH" - name: Print build identifiers run: | python -m pip install cibuildwheel==2.17.0 - python -m cibuildwheel --only ${{ matrix.cibw-only }} --print-build-identifiers + python -m cibuildwheel --print-build-identifiers + env: + CIBW_ARCHS: ${{ matrix.arch }} + + - name: Build wheels + if: ${{ (github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')) }} + uses: pypa/cibuildwheel@v2.17.0 + env: + CIBW_ARCHS: ${{ matrix.arch }} + CIBW_ENVIRONMENT: ${{ matrix.arch == 'x86' && 'CC=i686-w64-mingw32-gcc.exe' || '' }} - name: Build wheels - if: ${{ (github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')) || matrix.cibw-only == 'cp311-win_amd64' }} + if: ${{ !(github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')) }} uses: pypa/cibuildwheel@v2.17.0 with: - only: ${{ matrix.cibw-only }} + only: ${{ matrix.arch == 'x86' && 'cp310-win32' || 'cp310-win_amd64' }} env: - CIBW_ENVIRONMENT: JQPY_USE_PREBUILT_LIBS=1 ${{ contains(matrix.cibw-only, 'win32') && 'CC=i686-w64-mingw32-gcc.exe' || '' }} + CIBW_ENVIRONMENT: ${{ matrix.arch == 'x86' && 'CC=i686-w64-mingw32-gcc.exe' || '' }} - uses: actions/upload-artifact@v3 - if: ${{ (github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/')) || matrix.cibw-only == 'cp311-win_amd64' }} with: path: ./wheelhouse/*.whl diff --git a/build_jq.mk b/build_jq.mk deleted file mode 100644 index fb17f65..0000000 --- a/build_jq.mk +++ /dev/null @@ -1,29 +0,0 @@ -# makefile for building jq -.PHONY: jq_tarball jq_src jq_lib clean - -jq_build_parent:=_deps/build - -jq_version:=$(shell echo $(shell ls deps/jq-*.tar.gz) | grep -oP 'jq-\K[\d.]+(?=.tar.gz)') -jq_tarball_path:=deps/jq-$(jq_version).tar.gz -jq_build_path:=$(jq_build_parent)/jq-$(jq_version) - -all: $(jq_build_path)/.libs/libjq.a $(jq_build_path)/modules/oniguruma/src/.libs/libonig.a - -jq_tarball: $(jq_tarball_path) - echo "found jq tarball: $(jq_tarball_path)" - -jq_src: jq_tarball - # extract tarball to jq_build_path - mkdir -p $(jq_build_path) - tar -xf $(jq_tarball_path) -C $(jq_build_parent) - -$(jq_build_path)/.libs/libjq.a $(jq_build_path)/modules/oniguruma/src/.libs/libonig.a: jq_lib - -jq_lib: jq_src - # build jq - cd $(jq_build_path) ; \ - ./configure CFLAGS="-fPIC -pthread" --disable-maintainer-mode --with-oniguruma=builtin; \ - make - -clean: - rm -rf $(jq_build_parent)
\ No newline at end of file @@ -1,11 +1,12 @@ #!/usr/bin/env python import os -import sys -import subprocess -import tarfile +import shlex import shutil +import subprocess +import sys import sysconfig +import tarfile from setuptools import setup from setuptools.command.build_ext import build_ext @@ -29,6 +30,11 @@ jq_lib_tarball_path = _dep_source_path("jq-1.7.1.tar.gz") jq_lib_dir = _dep_build_path("jq-1.7.1") class jq_with_deps_build_ext(build_ext): + def finalize_options(self): + build_ext.finalize_options(self) + if os.name == "nt": + self.compiler = "mingw32" + def run(self): if not os.path.exists(_dep_build_path(".")): os.makedirs(_dep_build_path(".")) @@ -56,7 +62,14 @@ class jq_with_deps_build_ext(build_ext): def run_command(args): print("Executing: %s" % ' '.join(args)) - subprocess.check_call(args, cwd=lib_dir) + + if os.name == "nt": + msys2_path = os.path.join(os.getenv("RUNNER_TEMP"), "setup-msys2", "msys2.cmd") + command = [msys2_path, "-c", " ".join(shlex.quote(arg) for arg in args)] + else: + command = args + + subprocess.check_call(command, cwd=lib_dir) for command in commands: run_command(command) @@ -66,17 +79,16 @@ class jq_with_deps_build_ext(build_ext): shutil.rmtree(lib_dir) tarfile.open(tarball_path, "r:gz").extractall(_dep_build_path(".")) + use_system_libs = bool(os.environ.get("JQPY_USE_SYSTEM_LIBS")) -use_prebuilt_libs = bool(os.environ.get("JQPY_USE_PREBUILT_LIBS")) -print(f"use_system_libs={use_system_libs}") -print(f"use_prebuilt_libs={use_prebuilt_libs}") + if use_system_libs: jq_build_ext = build_ext link_args_deps = ["-ljq", "-lonig"] extra_objects = [] else: - jq_build_ext = build_ext if use_prebuilt_libs else jq_with_deps_build_ext + jq_build_ext = jq_with_deps_build_ext link_args_deps = [] extra_objects = [ os.path.join(jq_lib_dir, ".libs/libjq.a"), @@ -86,7 +98,7 @@ else: jq_extension = Extension( "jq", sources=["jq.c"], - define_macros=[("MS_WIN64" , 1)] if os.name == 'nt' and sys.maxsize > 2**32 else None, # https://github.com/cython/cython/issues/2670 + define_macros=[("MS_WIN64" , 1)] if os.name == "nt" and sys.maxsize > 2**32 else None, # https://github.com/cython/cython/issues/2670 include_dirs=[os.path.join(jq_lib_dir, "src")], extra_link_args=["-lm"] + (["-Wl,-Bstatic", "-lpthread", "-lshlwapi", "-static-libgcc"] if os.name == 'nt' else []) + link_args_deps, extra_objects=extra_objects, |
