From f7f30349ab674efb0c0e883b1a6c9c1f3af73376 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Aug 2023 19:05:26 +0000 Subject: [PATCH 01/60] Bump node-api-headers from 1.0.1 to 1.1.0 in /bindings/js Bumps [node-api-headers](https://github.com/nodejs/node-api-headers) from 1.0.1 to 1.1.0. - [Release notes](https://github.com/nodejs/node-api-headers/releases) - [Changelog](https://github.com/nodejs/node-api-headers/blob/main/CHANGELOG.md) - [Commits](https://github.com/nodejs/node-api-headers/compare/v1.0.1...v1.1.0) --- updated-dependencies: - dependency-name: node-api-headers dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- bindings/js/package-lock.json | 14 +++++++------- bindings/js/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bindings/js/package-lock.json b/bindings/js/package-lock.json index 4eede1f77a..d41507668f 100644 --- a/bindings/js/package-lock.json +++ b/bindings/js/package-lock.json @@ -14,7 +14,7 @@ "node-gyp-build": "^4.6.0" }, "devDependencies": { - "node-api-headers": "^1.0.1" + "node-api-headers": "^1.1.0" } }, "node_modules/@isaacs/cliui": { @@ -805,9 +805,9 @@ } }, "node_modules/node-api-headers": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/node-api-headers/-/node-api-headers-1.0.1.tgz", - "integrity": "sha512-42iSgdJwCPp2eDYB4jrj8tJ5SjakZA41I7QxilOXa8E1fPbKyfr7hG4VzikCableU/HUqpnwmoqGNVnUYYbeIQ==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/node-api-headers/-/node-api-headers-1.1.0.tgz", + "integrity": "sha512-ucQW+SbYCUPfprvmzBsnjT034IGRB2XK8rRc78BgjNKhTdFKgAwAmgW704bKIBmcYW48it0Gkjpkd39Azrwquw==", "dev": true }, "node_modules/node-gyp": { @@ -1955,9 +1955,9 @@ "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==" }, "node-api-headers": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/node-api-headers/-/node-api-headers-1.0.1.tgz", - "integrity": "sha512-42iSgdJwCPp2eDYB4jrj8tJ5SjakZA41I7QxilOXa8E1fPbKyfr7hG4VzikCableU/HUqpnwmoqGNVnUYYbeIQ==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/node-api-headers/-/node-api-headers-1.1.0.tgz", + "integrity": "sha512-ucQW+SbYCUPfprvmzBsnjT034IGRB2XK8rRc78BgjNKhTdFKgAwAmgW704bKIBmcYW48it0Gkjpkd39Azrwquw==", "dev": true }, "node-gyp": { diff --git a/bindings/js/package.json b/bindings/js/package.json index 8b0efcf5cc..f213e1d171 100644 --- a/bindings/js/package.json +++ b/bindings/js/package.json @@ -51,6 +51,6 @@ "node-gyp-build": "^4.6.0" }, "devDependencies": { - "node-api-headers": "^1.0.1" + "node-api-headers": "^1.1.0" } } From 1f0e1dbc6885f303ba3875c4f57626b8c1e9a1a9 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 17:40:23 -0500 Subject: [PATCH 02/60] Add Github Workflow for Python packaging --- .ci/ensure-go.sh | 8 ++ .github/workflows/python.yml | 186 +++++++++++++++++++++++++++++++++++ bindings/py/setup.py | 38 +++++-- 3 files changed, 226 insertions(+), 6 deletions(-) create mode 100644 .ci/ensure-go.sh create mode 100644 .github/workflows/python.yml diff --git a/.ci/ensure-go.sh b/.ci/ensure-go.sh new file mode 100644 index 0000000000..97bc7c0a69 --- /dev/null +++ b/.ci/ensure-go.sh @@ -0,0 +1,8 @@ +if command -v dnf; then + dnf -y install golang +elif command -v yum; then + yum install epel-release + yum -y install golang +elif command -v apk; then + apk add go +fi diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 0000000000..5854daffa1 --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,186 @@ +name: Python + +on: + push: + branches: + - master + - test-packaging + tags: + - '*' + +permissions: + contents: read + +jobs: + linux: + runs-on: ubuntu-latest + strategy: + matrix: + go_target: ['386', 'amd64', 'arm64'] + include: + - go_target: 'amd64' + cibw_target: 'x86_64' + - go_target: '386' + cibw_target: 'i686' + - go_target: 'arm64' + cibw_target: 'aarch64' + + steps: + - uses: actions/checkout@v3 + + - name: Set up QEMU + if: matrix.cibw_target == 'arm64' + uses: docker/setup-qemu-action@v2 + with: + platforms: arm64 + - name: Build wheels + uses: pypa/cibuildwheel@v2.15.0 + with: + package-dir: bindings/py + env: + CIBW_ARCHS: ${{ matrix.cibw_target }} + CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64 + CIBW_BEFORE_ALL: .ci/ensure-go.sh + + - name: Upload to GitHub Release + uses: softprops/action-gh-release@v0.1.14 + if: startsWith(github.ref, 'refs/tags/') + - name: Upload wheels + uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + + windows-go-crosscompile: + runs-on: ubuntu-latest + strategy: + matrix: + go_target: ['386', 'amd64', 'arm64'] + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-go@v4 + with: + go-version: '>=1.17' + + - name: Prebuild extension + if: startsWith(github.ref, 'refs/tags/') + run: | + cd bindings/py + go get github.com/tdewolff/minify/v2@${GITHUB_REF#refs/tags/} + GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so + - name: Prebuild extension + if: startsWith(github.ref, 'refs/tags/') == false + run: | + cd bindings/py + go get github.com/tdewolff/minify/v2@$(git describe --tags --abbrev=0) + GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so + + - name: Upload go library + uses: actions/upload-artifact@v3 + with: + name: minify-win-${{ matrix.go_target }}.so + path: bindings/py/minify.so + + windows: + runs-on: windows-latest + needs: windows-go-crosscompile + strategy: + matrix: + go_target: ['386', 'amd64', 'arm64'] + include: + - go_target: 'amd64' + cibw_target: 'x86_64' + - go_target: '386' + cibw_target: 'i686' + - go_target: 'arm64' + cibw_target: 'aarch64' + steps: + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v3 + with: + name: minify-win-${{ matrix.go_target }}.so + path: bindings/py/minify.so + + - name: Build wheels + uses: pypa/cibuildwheel@v2.15.0 + with: + package-dir: bindings/py + env: + CIBW_ARCHS: ${{ matrix.cibw_target }} + CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64 + CIBW_BEFORE_ALL: .ci/ensure-go.sh + CIBW_ENVIRONMENT: PREBUILT_EXT_PATH='minify.so' + + - name: Upload wheels + uses: actions/upload-artifact@v3 + with: + name: wheels + path: ./wheelhouse/*.whl + + macos: + runs-on: macos-latest + strategy: + matrix: + go_target: ['amd64', 'arm64'] + include: + - go_target: 'amd64' + cibw_target: 'x86_64' + - go_target: 'arm64' + cibw_target: 'arm64' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.11' + - uses: actions/setup-go@v4 + with: + go-version: '>=1.17' + + - name: Build wheels + uses: pypa/cibuildwheel@v2.15.0 + with: + package-dir: bindings/py + env: + CIBW_ARCHS: ${{ matrix.cibw_target }} + CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64 + CIBW_ENVIRONMENT: GOARCH='${{ matrix.go_target }}' + + - name: Upload wheels + uses: actions/upload-artifact@v3 + with: + path: ./wheelhouse/*.whl + + sdist: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + - name: Install dependencies + run: pip install build + - name: Build package + run: python -m build --sdist + - name: Upload sdist + uses: actions/upload-artifact@v3 + with: + name: wheels + path: dist + + release: + name: Release + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + needs: [linux, windows, macos, sdist] + steps: + - name: Collect artifacts + uses: actions/download-artifact@v3 + - name: Upload to GitHub Release + uses: softprops/action-gh-release@v0.1.14 + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/bindings/py/setup.py b/bindings/py/setup.py index e86e2a95de..15d1306b09 100644 --- a/bindings/py/setup.py +++ b/bindings/py/setup.py @@ -1,5 +1,7 @@ +import os import pathlib -from subprocess import call +import shutil +from subprocess import CalledProcessError, check_call from setuptools import Extension, setup from setuptools.command.build_ext import build_ext from setuptools.errors import CompileError @@ -11,11 +13,16 @@ class build_go_ext(build_ext): """Custom command to build extension from Go source files""" def build_extension(self, ext): ext_path = self.get_ext_fullpath(ext.name) - cmd = ['go', 'build', '-buildmode=c-shared', '-o', ext_path] - #cmd += ext.sources - out = call(cmd) - if out != 0: - raise CompileError('Go build failed') + prebuilt = os.environ.get('PREBUILT_EXT_PATH') + if prebuilt: + shutil.copyfile(prebuilt, ext_path) + else: + cmd = ['go', 'build', '-buildmode=c-shared', '-o', ext_path] + #cmd += ext.sources + try: + out = check_call(cmd) + except CalledProcessError as e: + raise CompileError('Go build failed') from e def get_version(): with open('go.mod') as f: @@ -35,6 +42,25 @@ def get_version(): author="Taco de Wolff", author_email="tacodewolff@gmail.com", license="MIT", + classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: JavaScript", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Internet :: WWW/HTTP", + "Topic :: Software Development :: Pre-processors", + "Topic :: Text Processing :: Markup", + ], ext_modules=[ Extension("minify", ["minify.go"]), ], From 35d182b5d421b57e76621a285fbdbe056dedb725 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 17:46:51 -0500 Subject: [PATCH 03/60] Make ensure-go.sh executable --- .ci/ensure-go.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .ci/ensure-go.sh diff --git a/.ci/ensure-go.sh b/.ci/ensure-go.sh old mode 100644 new mode 100755 From ca459c67633532bba7abee9d37ac38ad1e59c8e4 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 17:48:27 -0500 Subject: [PATCH 04/60] Add missing cd for sdist build --- .github/workflows/python.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 5854daffa1..03e094e66c 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -162,7 +162,9 @@ jobs: - name: Install dependencies run: pip install build - name: Build package - run: python -m build --sdist + run: | + cd bindings/py + python -m build --sdist - name: Upload sdist uses: actions/upload-artifact@v3 with: From d15f11af88d9385a95ac5cce2c94ec204b9fb433 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 17:55:10 -0500 Subject: [PATCH 05/60] Add gcc to linux wheel dependencies --- .ci/ensure-go.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.ci/ensure-go.sh b/.ci/ensure-go.sh index 97bc7c0a69..82b8603bc4 100755 --- a/.ci/ensure-go.sh +++ b/.ci/ensure-go.sh @@ -1,8 +1,8 @@ if command -v dnf; then - dnf -y install golang + dnf -y install golang gcc elif command -v yum; then yum install epel-release - yum -y install golang + yum -y install golang gcc elif command -v apk; then - apk add go + apk add go gcc fi From d6ea6836b80b6680fd1a6d246271a3188439e41d Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 17:55:29 -0500 Subject: [PATCH 06/60] Fix python workflow branch names --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 03e094e66c..4626bd2e73 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -4,7 +4,7 @@ on: push: branches: - master - - test-packaging + - python-packaging tags: - '*' From 7a0977a01896bd9901df37fc4946c8ce4885ac30 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 18:03:27 -0500 Subject: [PATCH 07/60] Fix missing tags in windows crosscompile --- .github/workflows/python.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 4626bd2e73..72e4bbb06f 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -58,6 +58,8 @@ jobs: steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - uses: actions/setup-go@v4 with: From d31d7c2ba9172da290983efc10b48de4a8a9180e Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 18:03:45 -0500 Subject: [PATCH 08/60] Add missing GCC to windows crosscompile --- .github/workflows/python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 72e4bbb06f..f176cef207 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -64,7 +64,8 @@ jobs: - uses: actions/setup-go@v4 with: go-version: '>=1.17' - + - name: Install GCC + run: sudo apt-get install gcc - name: Prebuild extension if: startsWith(github.ref, 'refs/tags/') run: | From b88b36a0fd2dafa5fe0fdc2e7ecb326b40347385 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 18:14:21 -0500 Subject: [PATCH 09/60] Remove unneeded CIBW envvars --- .github/workflows/python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index f176cef207..556af920b9 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -39,6 +39,8 @@ jobs: package-dir: bindings/py env: CIBW_ARCHS: ${{ matrix.cibw_target }} + CIBW_MANYLINUX_I686_IMAGE: quay.io/pypa/manylinux_2_28_i686 + CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_28_x86_64 CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64 CIBW_BEFORE_ALL: .ci/ensure-go.sh @@ -111,7 +113,6 @@ jobs: package-dir: bindings/py env: CIBW_ARCHS: ${{ matrix.cibw_target }} - CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64 CIBW_BEFORE_ALL: .ci/ensure-go.sh CIBW_ENVIRONMENT: PREBUILT_EXT_PATH='minify.so' @@ -146,7 +147,6 @@ jobs: package-dir: bindings/py env: CIBW_ARCHS: ${{ matrix.cibw_target }} - CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64 CIBW_ENVIRONMENT: GOARCH='${{ matrix.go_target }}' - name: Upload wheels From 3b9641916195d6b477828ee36806b6822bf7a705 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 18:15:02 -0500 Subject: [PATCH 10/60] Remove unnecessary GCC install --- .github/workflows/python.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 556af920b9..83185fd95f 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -66,8 +66,6 @@ jobs: - uses: actions/setup-go@v4 with: go-version: '>=1.17' - - name: Install GCC - run: sudo apt-get install gcc - name: Prebuild extension if: startsWith(github.ref, 'refs/tags/') run: | From f47e09cec23f62075f09145b63897e125c198ef0 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 18:21:40 -0500 Subject: [PATCH 11/60] Try adding CGO_ENABLED=1 --- .github/workflows/python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 83185fd95f..f63fef9c3e 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -71,13 +71,13 @@ jobs: run: | cd bindings/py go get github.com/tdewolff/minify/v2@${GITHUB_REF#refs/tags/} - GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so + CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - name: Prebuild extension if: startsWith(github.ref, 'refs/tags/') == false run: | cd bindings/py go get github.com/tdewolff/minify/v2@$(git describe --tags --abbrev=0) - GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so + CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - name: Upload go library uses: actions/upload-artifact@v3 From c7a091ba1590fb52cbbc874046ba947ffdfca66c Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 18:27:26 -0500 Subject: [PATCH 12/60] Try to fix crosscompilation --- .github/workflows/python.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index f63fef9c3e..44a4025232 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -56,7 +56,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go_target: ['386', 'amd64', 'arm64'] + #go_target: ['386', 'amd64', 'arm64'] + go_target: ['amd64'] steps: - uses: actions/checkout@v3 @@ -71,13 +72,13 @@ jobs: run: | cd bindings/py go get github.com/tdewolff/minify/v2@${GITHUB_REF#refs/tags/} - CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so + CC=x86_64-w64-mingw64-gcc CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - name: Prebuild extension if: startsWith(github.ref, 'refs/tags/') == false run: | cd bindings/py go get github.com/tdewolff/minify/v2@$(git describe --tags --abbrev=0) - CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so + CC=x86_64-w64-mingw64-gcc CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - name: Upload go library uses: actions/upload-artifact@v3 From cdb32e77f2d908ef8a0498e036ecdb7bd33e2600 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 18:30:22 -0500 Subject: [PATCH 13/60] Add missing mingw64 install for windows xcompile --- .github/workflows/python.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 44a4025232..38fea9a3cf 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -67,17 +67,20 @@ jobs: - uses: actions/setup-go@v4 with: go-version: '>=1.17' - - name: Prebuild extension + - name: Fetch go package if: startsWith(github.ref, 'refs/tags/') run: | cd bindings/py go get github.com/tdewolff/minify/v2@${GITHUB_REF#refs/tags/} - CC=x86_64-w64-mingw64-gcc CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - - name: Prebuild extension + - name: Fetch go package if: startsWith(github.ref, 'refs/tags/') == false run: | cd bindings/py go get github.com/tdewolff/minify/v2@$(git describe --tags --abbrev=0) + - name: Prebuild extension + run: | + apt-get install mingw64 + cd bindings/py CC=x86_64-w64-mingw64-gcc CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - name: Upload go library From 2fbc86c2bc181f71e963179fcf4b3a861ea971f2 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 18:33:41 -0500 Subject: [PATCH 14/60] Disable broken i686 build --- .github/workflows/python.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 38fea9a3cf..4278b33c06 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -16,12 +16,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go_target: ['386', 'amd64', 'arm64'] + #go_target: ['386', 'amd64', 'arm64'] + go_target: ['amd64', 'arm64'] include: - go_target: 'amd64' cibw_target: 'x86_64' - - go_target: '386' - cibw_target: 'i686' + #- go_target: '386' + # cibw_target: 'i686' - go_target: 'arm64' cibw_target: 'aarch64' From 37ddd982fc88dbb96672c65dbcb2e0a4c78d08dc Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 18:34:06 -0500 Subject: [PATCH 15/60] Add missing sudo to apt-get --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 4278b33c06..39d4b47a5b 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -80,7 +80,7 @@ jobs: go get github.com/tdewolff/minify/v2@$(git describe --tags --abbrev=0) - name: Prebuild extension run: | - apt-get install mingw64 + sudo apt-get install mingw64 cd bindings/py CC=x86_64-w64-mingw64-gcc CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so From 893d2625ab88b791b126f45f1eda016375352e28 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 18:37:30 -0500 Subject: [PATCH 16/60] Fix mingw package name --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 39d4b47a5b..beaaff7028 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -80,7 +80,7 @@ jobs: go get github.com/tdewolff/minify/v2@$(git describe --tags --abbrev=0) - name: Prebuild extension run: | - sudo apt-get install mingw64 + sudo apt-get install mingw-w64 cd bindings/py CC=x86_64-w64-mingw64-gcc CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so From a435284f74ca376c63a3d72474b55eff249d0a31 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 15 Aug 2023 18:44:26 -0500 Subject: [PATCH 17/60] Fix mingw compiler name --- .github/workflows/python.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index beaaff7028..7a5932e335 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -58,7 +58,13 @@ jobs: strategy: matrix: #go_target: ['386', 'amd64', 'arm64'] - go_target: ['amd64'] + go_target: ['386', 'amd64'] + include: + - go_target: 'amd64' + xcompiler: x86_64-w64-mingw32-gcc-win32 + - go_target: '386' + xcompiler: i686-w64-mingw32-gcc-win32 + steps: - uses: actions/checkout@v3 @@ -82,7 +88,7 @@ jobs: run: | sudo apt-get install mingw-w64 cd bindings/py - CC=x86_64-w64-mingw64-gcc CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so + CC=${{ matrix.xcompiler }} CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - name: Upload go library uses: actions/upload-artifact@v3 From cde8b799652a925e99509c34ef64b32da18cfd8b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Aug 2023 19:51:16 +0000 Subject: [PATCH 18/60] Bump node-gyp-build from 4.6.0 to 4.6.1 in /bindings/js Bumps [node-gyp-build](https://github.com/prebuild/node-gyp-build) from 4.6.0 to 4.6.1. - [Commits](https://github.com/prebuild/node-gyp-build/compare/v4.6.0...v4.6.1) --- updated-dependencies: - dependency-name: node-gyp-build dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- bindings/js/package-lock.json | 14 +++++++------- bindings/js/package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bindings/js/package-lock.json b/bindings/js/package-lock.json index 4eede1f77a..9dfa43fbc1 100644 --- a/bindings/js/package-lock.json +++ b/bindings/js/package-lock.json @@ -11,7 +11,7 @@ "license": "MIT", "dependencies": { "node-gyp": "^9.4.0", - "node-gyp-build": "^4.6.0" + "node-gyp-build": "^4.6.1" }, "devDependencies": { "node-api-headers": "^1.0.1" @@ -835,9 +835,9 @@ } }, "node_modules/node-gyp-build": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.0.tgz", - "integrity": "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==", + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.1.tgz", + "integrity": "sha512-24vnklJmyRS8ViBNI8KbtK/r/DmXQMRiOMXTNz2nrTnAYUwjmEEbnnpB/+kt+yWRv73bPsSPRFddrcIbAxSiMQ==", "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", @@ -1979,9 +1979,9 @@ } }, "node-gyp-build": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.0.tgz", - "integrity": "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ==" + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.1.tgz", + "integrity": "sha512-24vnklJmyRS8ViBNI8KbtK/r/DmXQMRiOMXTNz2nrTnAYUwjmEEbnnpB/+kt+yWRv73bPsSPRFddrcIbAxSiMQ==" }, "nopt": { "version": "6.0.0", diff --git a/bindings/js/package.json b/bindings/js/package.json index 8b0efcf5cc..52ae2ed262 100644 --- a/bindings/js/package.json +++ b/bindings/js/package.json @@ -48,7 +48,7 @@ ], "dependencies": { "node-gyp": "^9.4.0", - "node-gyp-build": "^4.6.0" + "node-gyp-build": "^4.6.1" }, "devDependencies": { "node-api-headers": "^1.0.1" From 78577e17febd0bb778ae5ddf72bd964f70769358 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Sep 2023 19:16:26 +0000 Subject: [PATCH 19/60] Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- .github/workflows/go.yml | 4 ++-- .github/workflows/nodejs.yml | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7931c4a57d..6c49326ac9 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -8,7 +8,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: docker/metadata-action@v4 id: meta diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c91e3a4cc1..f9f0a4d9d4 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -11,7 +11,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: @@ -37,7 +37,7 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 879e154690..c075d96384 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -20,7 +20,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 @@ -54,7 +54,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 @@ -91,7 +91,7 @@ jobs: needs: [build] runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 From d7158c72c01f2dd231c9ef3ae0bd1759c441431d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 19:43:57 +0000 Subject: [PATCH 20/60] Bump docker/login-action from 2 to 3 Bumps [docker/login-action](https://github.com/docker/login-action) from 2 to 3. - [Release notes](https://github.com/docker/login-action/releases) - [Commits](https://github.com/docker/login-action/compare/v2...v3) --- updated-dependencies: - dependency-name: docker/login-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7931c4a57d..fa8fa35f0e 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -15,7 +15,7 @@ jobs: with: images: tdewolff/minify - - uses: docker/login-action@v2 + - uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} From c74a5a14163354067b5e4f4b6f95572ec8e568fa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 19:44:01 +0000 Subject: [PATCH 21/60] Bump docker/metadata-action from 4 to 5 Bumps [docker/metadata-action](https://github.com/docker/metadata-action) from 4 to 5. - [Release notes](https://github.com/docker/metadata-action/releases) - [Upgrade guide](https://github.com/docker/metadata-action/blob/master/UPGRADE.md) - [Commits](https://github.com/docker/metadata-action/compare/v4...v5) --- updated-dependencies: - dependency-name: docker/metadata-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7931c4a57d..1751104ca7 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -10,7 +10,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: docker/metadata-action@v4 + - uses: docker/metadata-action@v5 id: meta with: images: tdewolff/minify From f7bd4fb31bc5f18815fe7c6356ec807f1409ff49 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 19:44:04 +0000 Subject: [PATCH 22/60] Bump docker/setup-buildx-action from 2 to 3 Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 2 to 3. - [Release notes](https://github.com/docker/setup-buildx-action/releases) - [Commits](https://github.com/docker/setup-buildx-action/compare/v2...v3) --- updated-dependencies: - dependency-name: docker/setup-buildx-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7931c4a57d..2bda89907a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -20,7 +20,7 @@ jobs: username: ${{ secrets.DOCKER_HUB_USERNAME }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - uses: docker/setup-buildx-action@v2 + - uses: docker/setup-buildx-action@v3 - uses: docker/build-push-action@v4 with: From 0ac8db91e4a044a68d90c36100ef8b81ee0b3530 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Sep 2023 19:44:08 +0000 Subject: [PATCH 23/60] Bump docker/build-push-action from 4 to 5 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 4 to 5. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/v4...v5) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7931c4a57d..695879c4a1 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -22,7 +22,7 @@ jobs: - uses: docker/setup-buildx-action@v2 - - uses: docker/build-push-action@v4 + - uses: docker/build-push-action@v5 with: context: . file: ./Dockerfile From 215d1e8ec050844f0f9b6df85eb0da568a40717c Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 08:42:49 -0500 Subject: [PATCH 24/60] Update go.mod and go.sum for Python bindings --- bindings/py/go.mod | 4 ++-- bindings/py/go.sum | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bindings/py/go.mod b/bindings/py/go.mod index 8e99ddd2cc..6c419b1598 100644 --- a/bindings/py/go.mod +++ b/bindings/py/go.mod @@ -3,6 +3,6 @@ module github.com/tdewolff/minify/bindings/py go 1.18 require ( - github.com/tdewolff/minify/v2 v2.12.2 - github.com/tdewolff/parse/v2 v2.6.3 + github.com/tdewolff/minify/v2 v2.12.9 + github.com/tdewolff/parse/v2 v2.6.8 ) diff --git a/bindings/py/go.sum b/bindings/py/go.sum index 8f8e038021..9b54af9cf9 100644 --- a/bindings/py/go.sum +++ b/bindings/py/go.sum @@ -8,8 +8,13 @@ github.com/tdewolff/minify/v2 v2.12.1 h1:zcjJTcO0uI+asdT+nd4TjXi3KUmVV/G2kxOKKrg github.com/tdewolff/minify/v2 v2.12.1/go.mod h1:p5pwbvNs1ghbFED/ZW1towGsnnWwzvM8iz8l0eURi9g= github.com/tdewolff/minify/v2 v2.12.2 h1:AKIoVwJj/HgBm+d/fPqpEZ31EtCM5FJfJNGagdR9Ecg= github.com/tdewolff/minify/v2 v2.12.2/go.mod h1:p5pwbvNs1ghbFED/ZW1towGsnnWwzvM8iz8l0eURi9g= +github.com/tdewolff/minify/v2 v2.12.9 h1:dvn5MtmuQ/DFMwqf5j8QhEVpPX6fi3WGImhv8RUB4zA= +github.com/tdewolff/minify/v2 v2.12.9/go.mod h1:qOqdlDfL+7v0/fyymB+OP497nIxJYSvX4MQWA8OoiXU= github.com/tdewolff/parse/v2 v2.6.3 h1:O5rshbkaRmpRtD7k2lG65bEJpcfUMNg5Cx2uRKWVsI8= github.com/tdewolff/parse/v2 v2.6.3/go.mod h1:woz0cgbLwFdtbjJu8PIKxhW05KplTFQkOdX78o+Jgrs= +github.com/tdewolff/parse/v2 v2.6.8 h1:mhNZXYCx//xG7Yq2e/kVLNZw4YfYmeHbhx+Zc0OvFMA= +github.com/tdewolff/parse/v2 v2.6.8/go.mod h1:XHDhaU6IBgsryfdnpzUXBlT6leW/l25yrFBTEb4eIyM= github.com/tdewolff/test v1.0.7 h1:8Vs0142DmPFW/bQeHRP3MV19m1gvndjUb1sn8yy74LM= github.com/tdewolff/test v1.0.7/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= +github.com/tdewolff/test v1.0.9/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 530b47ab5e53bb9d0b9a2f70e2145a0f1130b8d1 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 08:44:30 -0500 Subject: [PATCH 25/60] Switch Python bindings from C extension to CFFI --- bindings/py/MANIFEST.in | 5 +- bindings/py/build_minify.py | 14 +++ bindings/py/minify.c | 148 ----------------------------- bindings/py/minify.go | 1 - bindings/py/minify.pyi | 5 - bindings/py/setup.py | 43 ++++----- bindings/py/src/minify/__init__.py | 75 +++++++++++++++ 7 files changed, 112 insertions(+), 179 deletions(-) create mode 100644 bindings/py/build_minify.py delete mode 100644 bindings/py/minify.c delete mode 100644 bindings/py/minify.pyi create mode 100644 bindings/py/src/minify/__init__.py diff --git a/bindings/py/MANIFEST.in b/bindings/py/MANIFEST.in index 811bb886ee..4500817b4e 100644 --- a/bindings/py/MANIFEST.in +++ b/bindings/py/MANIFEST.in @@ -1,3 +1,4 @@ include README.md -include minify.go minify.c go.mod go.sum -include py.typed minify.pyi +include minify.go go.mod go.sum +include build_minify.py +include py.typed diff --git a/bindings/py/build_minify.py b/bindings/py/build_minify.py new file mode 100644 index 0000000000..1ce9a3f64f --- /dev/null +++ b/bindings/py/build_minify.py @@ -0,0 +1,14 @@ +import cffi + +C_DEFS = """ +char * minifyConfig(char **ckeys, char **cvals, long long length); +char * minifyString(char *cmediatype, char *cinput, long long input_length, char *coutput, long long *output_length); +char * minifyFile(char *cmediatype, char *cinput, char *coutput); +""" + +ffi = cffi.FFI() +ffi.set_source('minify._ffi_minify', None) +ffi.cdef(C_DEFS) + +if __name__ == '__main__': + ffi.compile() diff --git a/bindings/py/minify.c b/bindings/py/minify.c deleted file mode 100644 index d2284e9a67..0000000000 --- a/bindings/py/minify.c +++ /dev/null @@ -1,148 +0,0 @@ -#include - -char *minifyConfig(char **, char **, long long); -char *minifyString(char *, char *, long long, char *, long long *); -char *minifyFile(char *, char *, char *); - -PyObject *config(PyObject *self, PyObject *args) { - PyObject *pyconfig; - if (PyArg_ParseTuple(args, "O", &pyconfig) == 0 || !PyDict_Check(pyconfig)) { - PyErr_SetString(PyExc_ValueError, "expected config argument"); - return NULL; - } else if (!PyDict_Check(pyconfig)) { - PyErr_SetString(PyExc_ValueError, "config must be a dict[str,str|bool|int]"); - return NULL; - } - - Py_ssize_t length = PyDict_Size(pyconfig); - const char **keys = (const char **)malloc(length * sizeof(const char *)); - const char **vals = (const char **)malloc(length * sizeof(const char *)); - - Py_ssize_t pos = 0; - PyObject *pykey, *pyval; - while (PyDict_Next(pyconfig, &pos, &pykey, &pyval)) { - const char *key = PyUnicode_AsUTF8(pykey); // handles deallocation - if (key == NULL) { - PyErr_SetString(PyExc_ValueError, "config must be a dict[str,str|bool|int]"); - free(vals); - free(keys); - return NULL; - } - keys[pos-1] = key; - - int decref = 0; - if (PyBool_Check(pyval) || PyLong_Check(pyval)) { - pyval = PyObject_Str(pyval); - if (pyval == NULL) { - PyErr_SetString(PyExc_ValueError, "config must be a dict[str,str|bool|int]"); - free(vals); - free(keys); - return NULL; - } - decref = 1; - } - const char *val = PyUnicode_AsUTF8(pyval); // handles deallocation - if (val == NULL) { - PyErr_SetString(PyExc_ValueError, "config must be a dict[str,str|bool|int]"); - free(vals); - free(keys); - return NULL; - } - vals[pos-1] = val; - - if (decref == 1) { - Py_DECREF(pyval); - } - } - - char *error = minifyConfig((char **)keys, (char **)vals, length); - free(vals); - free(keys); - if (error != NULL) { - PyErr_SetString(PyExc_ValueError, error); - free(error); - return NULL; - } - Py_RETURN_NONE; -} - -PyObject *string(PyObject *self, PyObject *args) { - PyObject *pymediatype, *pyinput; - if (PyArg_ParseTuple(args, "OO", &pymediatype, &pyinput) == 0) { - PyErr_SetString(PyExc_ValueError, "expected mediatype and input arguments"); - return NULL; - } - - const char *mediatype = PyUnicode_AsUTF8(pymediatype); // handles deallocation - if (mediatype == NULL) { - PyErr_SetString(PyExc_ValueError, "mediatype must be a string"); - return NULL; - } - - Py_ssize_t input_length; // not including trailing NULL-byte - const char *input = PyUnicode_AsUTF8AndSize(pyinput, &input_length); // handles deallocation - if (input == NULL) { - PyErr_SetString(PyExc_ValueError, "input must be a string"); - return NULL; - } - - long long output_length; // not including trailing NULL-byte - char *output = (char *)malloc(input_length); - char *error = minifyString((char *)mediatype, (char *)input, (long long)input_length, output, &output_length); - if (error != NULL) { - PyErr_SetString(PyExc_ValueError, error); - free(error); - return NULL; - } - - PyObject *pyoutput = PyUnicode_DecodeUTF8(output, (Py_ssize_t)output_length, NULL); - free(output); - return pyoutput; -} - -PyObject *file(PyObject *self, PyObject *args) { - PyObject *pymediatype, *pyinput, *pyoutput; - if (PyArg_ParseTuple(args, "OOO", &pymediatype, &pyinput, &pyoutput) == 0) { - PyErr_SetString(PyExc_ValueError, "expected mediatype, input, and output arguments"); - return NULL; - } - - const char *mediatype = PyUnicode_AsUTF8(pymediatype); // handles deallocation - if (mediatype == NULL) { - return NULL; - } - - const char *input = PyUnicode_AsUTF8(pyinput); // handles deallocation - if (input == NULL) { - return NULL; - } - - const char *output = PyUnicode_AsUTF8(pyoutput); // handles deallocation - if (output == NULL) { - return NULL; - } - - char *error = minifyFile((char *)mediatype, (char *)input, (char *)output); - if (error != NULL) { - PyErr_SetString(PyExc_ValueError, error); - free(error); - return NULL; - } - Py_RETURN_NONE; -} - -static PyMethodDef MinifyMethods[] = { - {"config", config, METH_VARARGS, "Configure minify options."}, - {"string", string, METH_VARARGS, "Minify string."}, - {"file", file, METH_VARARGS, "Minify file."}, - {NULL, NULL, 0, NULL} -}; - -static struct PyModuleDef minifymodule = { - PyModuleDef_HEAD_INIT, "minify", NULL, -1, MinifyMethods -}; - -PyMODINIT_FUNC -PyInit_minify(void) { - return PyModule_Create(&minifymodule); -} diff --git a/bindings/py/minify.go b/bindings/py/minify.go index 9a161d40ce..99bd23b716 100644 --- a/bindings/py/minify.go +++ b/bindings/py/minify.go @@ -1,6 +1,5 @@ package main -// #cgo pkg-config: python3-embed import "C" import ( "fmt" diff --git a/bindings/py/minify.pyi b/bindings/py/minify.pyi deleted file mode 100644 index ebd8ae8fd2..0000000000 --- a/bindings/py/minify.pyi +++ /dev/null @@ -1,5 +0,0 @@ -from typing import Dict, Union - -def config(configuration: Dict[str, Union[str,bool,int]]) -> None: ... -def string(mediatype: str, string: str) -> str: ... -def file(mediatype: str, input_filename: str, output_filename: str) -> None: ... diff --git a/bindings/py/setup.py b/bindings/py/setup.py index 15d1306b09..1b2d394366 100644 --- a/bindings/py/setup.py +++ b/bindings/py/setup.py @@ -1,28 +1,11 @@ -import os import pathlib -import shutil -from subprocess import CalledProcessError, check_call -from setuptools import Extension, setup -from setuptools.command.build_ext import build_ext +from setuptools import setup, Distribution from setuptools.errors import CompileError + HERE = pathlib.Path(__file__).parent README = (HERE / "README.md").read_text() -class build_go_ext(build_ext): - """Custom command to build extension from Go source files""" - def build_extension(self, ext): - ext_path = self.get_ext_fullpath(ext.name) - prebuilt = os.environ.get('PREBUILT_EXT_PATH') - if prebuilt: - shutil.copyfile(prebuilt, ext_path) - else: - cmd = ['go', 'build', '-buildmode=c-shared', '-o', ext_path] - #cmd += ext.sources - try: - out = check_call(cmd) - except CalledProcessError as e: - raise CompileError('Go build failed') from e def get_version(): with open('go.mod') as f: @@ -32,6 +15,17 @@ def get_version(): return line.split()[1][1:] raise CompileError('Version retrieval failed') + +class BinaryDistribution(Distribution): + """ + Distribution which always forces binary packages to be platform-specific. + + Based on https://stackoverflow.com/a/36886459/1795505. + """ + def has_ext_modules(self): + return True + + setup( name="tdewolff-minify", version=get_version(), @@ -61,9 +55,12 @@ def get_version(): "Topic :: Software Development :: Pre-processors", "Topic :: Text Processing :: Markup", ], - ext_modules=[ - Extension("minify", ["minify.go"]), - ], - cmdclass={"build_ext": build_go_ext}, + packages=["minify"], + package_dir={"": "src"}, + package_data={"minify": ["_minify.so"]}, + setup_requires=["cffi>=1.0.0"], + cffi_modules=["build_minify.py:ffi"], + install_requires=["cffi>=1.0.0"], zip_safe=False, + distclass=BinaryDistribution, ) diff --git a/bindings/py/src/minify/__init__.py b/bindings/py/src/minify/__init__.py new file mode 100644 index 0000000000..5f72ae7052 --- /dev/null +++ b/bindings/py/src/minify/__init__.py @@ -0,0 +1,75 @@ +import pathlib +from typing import Dict, Union + +from ._ffi_minify import ffi + +__all__ = ['MinifyError', 'config', 'file', 'string'] + + +lib = ffi.dlopen(str(pathlib.Path(__file__).parent / '_minify.so')) + + +class MinifyError(ValueError): + """ + Exception raised when error occurs during minification. + """ + + +def _check_error(cdata): + if cdata: + raise MinifyError(ffi.string(cdata).decode()) + + +def config(configuration: Dict[str, Union[str,bool,int]]) -> None: + """ + Configure minifier behavior. + + Supported configuration keys: + * css-precision (int) + * html-keep-comments (bool) + * html-keep-conditional-comments (bool) + * html-keep-default-attr-vals (bool) + * html-keep-document-tags (bool) + * html-keep-end-tags (bool) + * html-keep-whitespace (bool) + * html-keep-quotes (bool) + * js-precision (int) + * js-keep-var-names (bool) + * js-version (int) + * json-precision (int) + * json-keep-numbers (bool) + * svg-keep-comments (bool) + * svg-precision (int) + * xml-keep-whitespace (bool) + """ + length = len(configuration) + err_msg = lib.minifyConfig( + [ffi.new('char[]', k.encode()) for k in configuration.keys()], + [ffi.new('char[]', str(v).encode()) for v in configuration.values()], + length) + _check_error(err_msg) + + +def string(mediatype: str, string: str) -> str: + """ + Minify code from a string. + + The minifier backend will be selected based on the specified MIME type. + """ + input_bytes = string.encode() + input_len = len(input_bytes) + output_bytes = ffi.new(f'char[{input_len}]') + output_len = ffi.new('long long *') + err_msg = lib.minifyString(mediatype.encode(), input_bytes, input_len, output_bytes, output_len) + _check_error(err_msg) + return ffi.string(output_bytes, output_len[0]).decode() + + +def file(mediatype: str, input_filename: str, output_filename: str) -> None: + """ + Minify a file and write output to another file. + + The minifier backend will be selected based on the specified MIME type. + """ + err_msg = lib.minifyFile(mediatype.encode(), input_filename.encode(), output_filename.encode()) + _check_error(err_msg) From 2b5c17d8fa6c28142f65fe136e0a0ec049c2a395 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 08:44:46 -0500 Subject: [PATCH 26/60] Update .gitignore --- .gitignore | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c9ea38dbc1..a82a9fdb69 100644 --- a/.gitignore +++ b/.gitignore @@ -23,8 +23,10 @@ bindings/js/example/node_modules bindings/js/example/test.min.html bindings/py/go.mod bindings/py/go.sum -bindings/py/minify.h -bindings/py/minify.so -bindings/py/tdewolff_minify.egg-info +bindings/py/*.h +bindings/py/*.so +bindings/py/*.egg-info bindings/py/example/example.min.html bindings/py/dist +bindings/py/build +bindings/py/*.pyc From c237bb218cb37cf48e9fd53054abcee58e074221 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 08:56:42 -0500 Subject: [PATCH 27/60] Fix off-by-one error in Python bindings --- bindings/py/minify.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/py/minify.go b/bindings/py/minify.go index 99bd23b716..5d568a9e5f 100644 --- a/bindings/py/minify.go +++ b/bindings/py/minify.go @@ -25,7 +25,7 @@ func init() { } func goBytes(str *C.char, length C.longlong) []byte { - return (*[1 << 32]byte)(unsafe.Pointer(str))[:length:length] + return (*[1 << 32 - 1]byte)(unsafe.Pointer(str))[:length:length] } func goStringArray(carr **C.char, length C.longlong) []string { @@ -34,7 +34,7 @@ func goStringArray(carr **C.char, length C.longlong) []string { } strs := make([]string, length) - arr := (*[1 << 32]*C.char)(unsafe.Pointer(carr))[:length:length] + arr := (*[1 << 32 - 1]*C.char)(unsafe.Pointer(carr))[:length:length] for i := 0; i < int(length); i++ { strs[i] = C.GoString(arr[i]) } From f6d756a46ac3327dd72238fab3b37fa2051a31b0 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 09:23:12 -0500 Subject: [PATCH 28/60] Update extension build in python workflow --- .github/workflows/python.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 7a5932e335..b920e6a6d3 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -43,7 +43,7 @@ jobs: CIBW_MANYLINUX_I686_IMAGE: quay.io/pypa/manylinux_2_28_i686 CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_28_x86_64 CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64 - CIBW_BEFORE_ALL: .ci/ensure-go.sh + CIBW_BEFORE_ALL: .ci/ensure-go.sh; go build -buildmode=c-shared -o bindings/py/src/minify/_minify.so - name: Upload to GitHub Release uses: softprops/action-gh-release@v0.1.14 @@ -114,7 +114,7 @@ jobs: - uses: actions/download-artifact@v3 with: name: minify-win-${{ matrix.go_target }}.so - path: bindings/py/minify.so + path: bindings/py/src/minify/_minify.so - name: Build wheels uses: pypa/cibuildwheel@v2.15.0 @@ -123,7 +123,6 @@ jobs: env: CIBW_ARCHS: ${{ matrix.cibw_target }} CIBW_BEFORE_ALL: .ci/ensure-go.sh - CIBW_ENVIRONMENT: PREBUILT_EXT_PATH='minify.so' - name: Upload wheels uses: actions/upload-artifact@v3 @@ -157,6 +156,7 @@ jobs: env: CIBW_ARCHS: ${{ matrix.cibw_target }} CIBW_ENVIRONMENT: GOARCH='${{ matrix.go_target }}' + CIBW_BEFORE_ALL: go build -buildmode=c-shared -o bindings/py/src/minify/_minify.so - name: Upload wheels uses: actions/upload-artifact@v3 From fb2b2257d88d682b6999f636ed975d93bd367b2d Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 09:27:48 -0500 Subject: [PATCH 29/60] Revert "Fix off-by-one error in Python bindings" This reverts commit c237bb218cb37cf48e9fd53054abcee58e074221. --- bindings/py/minify.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/py/minify.go b/bindings/py/minify.go index 5d568a9e5f..99bd23b716 100644 --- a/bindings/py/minify.go +++ b/bindings/py/minify.go @@ -25,7 +25,7 @@ func init() { } func goBytes(str *C.char, length C.longlong) []byte { - return (*[1 << 32 - 1]byte)(unsafe.Pointer(str))[:length:length] + return (*[1 << 32]byte)(unsafe.Pointer(str))[:length:length] } func goStringArray(carr **C.char, length C.longlong) []string { @@ -34,7 +34,7 @@ func goStringArray(carr **C.char, length C.longlong) []string { } strs := make([]string, length) - arr := (*[1 << 32 - 1]*C.char)(unsafe.Pointer(carr))[:length:length] + arr := (*[1 << 32]*C.char)(unsafe.Pointer(carr))[:length:length] for i := 0; i < int(length); i++ { strs[i] = C.GoString(arr[i]) } From 5c693ee7ea159260acf59259e2fa1b77b00f33ed Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 09:28:14 -0500 Subject: [PATCH 30/60] Fix go build working dir in python workflow --- .github/workflows/python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index b920e6a6d3..8c3e7061d6 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -43,7 +43,7 @@ jobs: CIBW_MANYLINUX_I686_IMAGE: quay.io/pypa/manylinux_2_28_i686 CIBW_MANYLINUX_X86_64_IMAGE: quay.io/pypa/manylinux_2_28_x86_64 CIBW_MANYLINUX_AARCH64_IMAGE: quay.io/pypa/manylinux_2_28_aarch64 - CIBW_BEFORE_ALL: .ci/ensure-go.sh; go build -buildmode=c-shared -o bindings/py/src/minify/_minify.so + CIBW_BEFORE_ALL: .ci/ensure-go.sh; cd bindings/py; go build -buildmode=c-shared -o src/minify/_minify.so - name: Upload to GitHub Release uses: softprops/action-gh-release@v0.1.14 @@ -156,7 +156,7 @@ jobs: env: CIBW_ARCHS: ${{ matrix.cibw_target }} CIBW_ENVIRONMENT: GOARCH='${{ matrix.go_target }}' - CIBW_BEFORE_ALL: go build -buildmode=c-shared -o bindings/py/src/minify/_minify.so + CIBW_BEFORE_ALL: cd bindings/py; go build -buildmode=c-shared -o src/minify/_minify.so - name: Upload wheels uses: actions/upload-artifact@v3 From c04076adaa9f1813e44464e101f2e210ce85a575 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 09:29:33 -0500 Subject: [PATCH 31/60] Disable 32-bit Python binding builds for now --- .github/workflows/python.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 8c3e7061d6..d54b1f8d80 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -58,7 +58,7 @@ jobs: strategy: matrix: #go_target: ['386', 'amd64', 'arm64'] - go_target: ['386', 'amd64'] + go_target: ['amd64'] include: - go_target: 'amd64' xcompiler: x86_64-w64-mingw32-gcc-win32 @@ -101,12 +101,13 @@ jobs: needs: windows-go-crosscompile strategy: matrix: - go_target: ['386', 'amd64', 'arm64'] + #go_target: ['386', 'amd64', 'arm64'] + go_target: ['amd64', 'arm64'] include: - go_target: 'amd64' cibw_target: 'x86_64' - - go_target: '386' - cibw_target: 'i686' + #- go_target: '386' + # cibw_target: 'i686' - go_target: 'arm64' cibw_target: 'aarch64' steps: From 4bbadcc5ab91d9d2537539a0440e9b560c592aa3 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 09:41:43 -0500 Subject: [PATCH 32/60] Disable 32-bit Windows Python build for now --- .github/workflows/python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index d54b1f8d80..7b443445bc 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -62,8 +62,8 @@ jobs: include: - go_target: 'amd64' xcompiler: x86_64-w64-mingw32-gcc-win32 - - go_target: '386' - xcompiler: i686-w64-mingw32-gcc-win32 + #- go_target: '386' + # xcompiler: i686-w64-mingw32-gcc-win32 steps: From 564c8e59746701beba69e467fe3b298200778703 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 14:58:51 -0500 Subject: [PATCH 33/60] Adjust .gitignore --- .gitignore | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index a82a9fdb69..e2cf6cf8ef 100644 --- a/.gitignore +++ b/.gitignore @@ -23,10 +23,10 @@ bindings/js/example/node_modules bindings/js/example/test.min.html bindings/py/go.mod bindings/py/go.sum -bindings/py/*.h -bindings/py/*.so -bindings/py/*.egg-info +bindings/py/**/*.h +bindings/py/**/*.so +bindings/py/**/*.egg-info bindings/py/example/example.min.html bindings/py/dist bindings/py/build -bindings/py/*.pyc +bindings/py/**/*.pyc From 9ed91ceb808a4e96d2e4e8ed9e48d3f7cc3e1f4d Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 15:00:56 -0500 Subject: [PATCH 34/60] Improve handling of externally compiled module in Python build --- bindings/py/setup.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/bindings/py/setup.py b/bindings/py/setup.py index 1b2d394366..37d7895188 100644 --- a/bindings/py/setup.py +++ b/bindings/py/setup.py @@ -1,6 +1,8 @@ import pathlib -from setuptools import setup, Distribution +from setuptools import setup +from setuptools.command.build_ext import build_ext from setuptools.errors import CompileError +from setuptools.extension import Extension HERE = pathlib.Path(__file__).parent @@ -16,14 +18,11 @@ def get_version(): raise CompileError('Version retrieval failed') -class BinaryDistribution(Distribution): - """ - Distribution which always forces binary packages to be platform-specific. - - Based on https://stackoverflow.com/a/36886459/1795505. - """ - def has_ext_modules(self): - return True +class build_ext_external(build_ext): + """Placeholder for externally-built extension.""" + def build_extension(self, ext: Extension): + if not all(pathlib.Path(p).exists() for p in ext.sources): + raise CompileError(f'Missing external extension files for {ext.name}!') setup( @@ -55,6 +54,10 @@ def has_ext_modules(self): "Topic :: Software Development :: Pre-processors", "Topic :: Text Processing :: Markup", ], + ext_modules=[ + Extension("minify", ["src/minify/_minify.so"]), + ], + cmdclass={"build_ext": build_ext_external}, packages=["minify"], package_dir={"": "src"}, package_data={"minify": ["_minify.so"]}, @@ -62,5 +65,4 @@ def has_ext_modules(self): cffi_modules=["build_minify.py:ffi"], install_requires=["cffi>=1.0.0"], zip_safe=False, - distclass=BinaryDistribution, ) From 6981e637244b5f11e566d4b5e04608432a222693 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 15:17:41 -0500 Subject: [PATCH 35/60] Disable Windows ARM Python build for now --- .github/workflows/python.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 7b443445bc..065e898a76 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -102,14 +102,14 @@ jobs: strategy: matrix: #go_target: ['386', 'amd64', 'arm64'] - go_target: ['amd64', 'arm64'] + go_target: ['amd64'] include: - go_target: 'amd64' cibw_target: 'x86_64' #- go_target: '386' # cibw_target: 'i686' - - go_target: 'arm64' - cibw_target: 'aarch64' + #- go_target: 'arm64' + # cibw_target: 'aarch64' steps: - uses: actions/checkout@v3 - uses: actions/download-artifact@v3 From 09278a0ea25d2a9b95cc783075d662cf76bd8caa Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 15:19:01 -0500 Subject: [PATCH 36/60] Try to fix broken build constraints on macOS --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 065e898a76..813c13f5cc 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -156,7 +156,7 @@ jobs: package-dir: bindings/py env: CIBW_ARCHS: ${{ matrix.cibw_target }} - CIBW_ENVIRONMENT: GOARCH='${{ matrix.go_target }}' + CIBW_ENVIRONMENT: GOARCH='${{ matrix.go_target }} CGO_ENABLED=1' CIBW_BEFORE_ALL: cd bindings/py; go build -buildmode=c-shared -o src/minify/_minify.so - name: Upload wheels From fdd17d2e650921e4a1ae9ee218092232ba314a38 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 15:38:19 -0500 Subject: [PATCH 37/60] Fix CIBW architecture labels for Windows Python build --- .github/workflows/python.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 813c13f5cc..aa9e5fc4dc 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -105,11 +105,11 @@ jobs: go_target: ['amd64'] include: - go_target: 'amd64' - cibw_target: 'x86_64' + cibw_target: 'AMD64' #- go_target: '386' - # cibw_target: 'i686' + # cibw_target: 'x86' #- go_target: 'arm64' - # cibw_target: 'aarch64' + # cibw_target: 'ARM64' steps: - uses: actions/checkout@v3 - uses: actions/download-artifact@v3 From e111658ed037c179df8d3452366c13823d62a166 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 15:38:37 -0500 Subject: [PATCH 38/60] Disable macOS ARM Python build for now --- .github/workflows/python.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index aa9e5fc4dc..75feec325e 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -135,12 +135,13 @@ jobs: runs-on: macos-latest strategy: matrix: - go_target: ['amd64', 'arm64'] + #go_target: ['amd64', 'arm64'] + go_target: ['amd64'] include: - go_target: 'amd64' cibw_target: 'x86_64' - - go_target: 'arm64' - cibw_target: 'arm64' + #- go_target: 'arm64' + # cibw_target: 'arm64' steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 From d32f1587747cc48c1eca05981bc3a090efea8851 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 15:47:57 -0500 Subject: [PATCH 39/60] Remove spurious go installation command from Windows Python build --- .github/workflows/python.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 75feec325e..193c0c4280 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -123,7 +123,6 @@ jobs: package-dir: bindings/py env: CIBW_ARCHS: ${{ matrix.cibw_target }} - CIBW_BEFORE_ALL: .ci/ensure-go.sh - name: Upload wheels uses: actions/upload-artifact@v3 From 65bfe281d32f0ed0ea9141c4b49b13048fc81169 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 15:57:06 -0500 Subject: [PATCH 40/60] Try crosscompilation for macOS Python bindings --- .github/workflows/python.yml | 77 +++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 193c0c4280..7662a777bd 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -16,15 +16,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - #go_target: ['386', 'amd64', 'arm64'] - go_target: ['amd64', 'arm64'] include: - - go_target: 'amd64' - cibw_target: 'x86_64' - #- go_target: '386' - # cibw_target: 'i686' - - go_target: 'arm64' - cibw_target: 'aarch64' + - go_target: amd64 + cibw_target: x86_64 + #- go_target:'386 + # cibw_target: i686 + - go_target: arm64 + cibw_target: aarch64 steps: - uses: actions/checkout@v3 @@ -53,17 +51,23 @@ jobs: with: path: ./wheelhouse/*.whl - windows-go-crosscompile: + go-crosscompile: runs-on: ubuntu-latest strategy: matrix: - #go_target: ['386', 'amd64', 'arm64'] - go_target: ['amd64'] include: - - go_target: 'amd64' + - go_os: windows + go_target: amd64 xcompiler: x86_64-w64-mingw32-gcc-win32 - #- go_target: '386' + #- go_os: windows + # go_target: 386 # xcompiler: i686-w64-mingw32-gcc-win32 + - go_os: darwin + go_target: amd64 + xcompiler: + - go_os: darwin + go_target: arm64 + xcompiler: steps: @@ -88,33 +92,31 @@ jobs: run: | sudo apt-get install mingw-w64 cd bindings/py - CC=${{ matrix.xcompiler }} CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so + CC=${{ matrix.xcompiler }} CGO_ENABLED=1 GOOS=${{ matrix.go_os }} GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - name: Upload go library uses: actions/upload-artifact@v3 with: - name: minify-win-${{ matrix.go_target }}.so + name: minify-${{ matrix.go_os }}-${{ matrix.go_target }}.so path: bindings/py/minify.so windows: runs-on: windows-latest - needs: windows-go-crosscompile + needs: go-crosscompile strategy: matrix: - #go_target: ['386', 'amd64', 'arm64'] - go_target: ['amd64'] include: - - go_target: 'amd64' - cibw_target: 'AMD64' - #- go_target: '386' - # cibw_target: 'x86' - #- go_target: 'arm64' - # cibw_target: 'ARM64' + - go_target: amd64 + cibw_target: AMD64 + #- go_target: 386 + # cibw_target: x86 + #- go_target: arm64 + # cibw_target: ARM64 steps: - uses: actions/checkout@v3 - uses: actions/download-artifact@v3 with: - name: minify-win-${{ matrix.go_target }}.so + name: minify-windows-${{ matrix.go_target }}.so path: bindings/py/src/minify/_minify.so - name: Build wheels @@ -132,23 +134,26 @@ jobs: macos: runs-on: macos-latest + needs: go-crosscompile strategy: matrix: - #go_target: ['amd64', 'arm64'] - go_target: ['amd64'] include: - - go_target: 'amd64' - cibw_target: 'x86_64' - #- go_target: 'arm64' - # cibw_target: 'arm64' + - go_target: amd64 + cibw_target: x86_64 + #- go_target: arm64 + # cibw_target: arm64 steps: - uses: actions/checkout@v3 + - uses: actions/download-artifact@v3 + with: + name: minify-darwin-${{ matrix.go_target }}.so + path: bindings/py/src/minify/_minify.so - uses: actions/setup-python@v4 with: python-version: '3.11' - - uses: actions/setup-go@v4 - with: - go-version: '>=1.17' + #- uses: actions/setup-go@v4 + # with: + # go-version: '>=1.17' - name: Build wheels uses: pypa/cibuildwheel@v2.15.0 @@ -156,8 +161,8 @@ jobs: package-dir: bindings/py env: CIBW_ARCHS: ${{ matrix.cibw_target }} - CIBW_ENVIRONMENT: GOARCH='${{ matrix.go_target }} CGO_ENABLED=1' - CIBW_BEFORE_ALL: cd bindings/py; go build -buildmode=c-shared -o src/minify/_minify.so + #CIBW_ENVIRONMENT: GOARCH='${{ matrix.go_target }} CGO_ENABLED=1' + #CIBW_BEFORE_ALL: cd bindings/py; go build -buildmode=c-shared -o src/minify/_minify.so - name: Upload wheels uses: actions/upload-artifact@v3 From d936c61d1e0fe77eb0cb8d09f10cd35fe3899210 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 16:00:30 -0500 Subject: [PATCH 41/60] Fix for Python extension crosscompilation --- .github/workflows/python.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 7662a777bd..84963e7150 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -88,11 +88,17 @@ jobs: run: | cd bindings/py go get github.com/tdewolff/minify/v2@$(git describe --tags --abbrev=0) - - name: Prebuild extension + - name: Prebuild windows extension + if: matrix.go_os == 'windows' run: | sudo apt-get install mingw-w64 cd bindings/py CC=${{ matrix.xcompiler }} CGO_ENABLED=1 GOOS=${{ matrix.go_os }} GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so + - name: Prebuild macos extension + if: matrix.go_os == 'macos' + run: | + cd bindings/py + CGO_ENABLED=1 GOOS=${{ matrix.go_os }} GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - name: Upload go library uses: actions/upload-artifact@v3 From 96d8d458650c62475dee55e2ca9765f75d3d0028 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 16:01:24 -0500 Subject: [PATCH 42/60] Fix typo in macOS Python extension crosscompilation --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 84963e7150..7b8d5a0ae6 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -95,7 +95,7 @@ jobs: cd bindings/py CC=${{ matrix.xcompiler }} CGO_ENABLED=1 GOOS=${{ matrix.go_os }} GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - name: Prebuild macos extension - if: matrix.go_os == 'macos' + if: matrix.go_os == 'darwin' run: | cd bindings/py CGO_ENABLED=1 GOOS=${{ matrix.go_os }} GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so From 6c10ff35dbc78ccd85588442721c9f4d3bc95887 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 16:26:45 -0500 Subject: [PATCH 43/60] Try to fix macOS Python crosscompilation --- .github/workflows/python.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 7b8d5a0ae6..d67570861c 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -64,10 +64,10 @@ jobs: # xcompiler: i686-w64-mingw32-gcc-win32 - go_os: darwin go_target: amd64 - xcompiler: + clang_target: x86_64 - go_os: darwin go_target: arm64 - xcompiler: + clang_target: arm64 steps: @@ -98,7 +98,11 @@ jobs: if: matrix.go_os == 'darwin' run: | cd bindings/py - CGO_ENABLED=1 GOOS=${{ matrix.go_os }} GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so + export CGO_ENABLED=1 + export GOOS=${{ matrix.go_os }} + export GOARCH=${{ matrix.go_target }} + export CFLAGS="-Wno-error=unused-command-line-argument -target ${{ matrix.clang_target }}-unknown-darwin-unknown" + go build -buildmode=c-shared -o minify.so - name: Upload go library uses: actions/upload-artifact@v3 From f46945cc9a8a0177814ce8af3654ba265033b3c9 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 16:34:29 -0500 Subject: [PATCH 44/60] Try to fix macOS Python crosscompilation --- .github/workflows/python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index d67570861c..e57771c93c 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -101,7 +101,8 @@ jobs: export CGO_ENABLED=1 export GOOS=${{ matrix.go_os }} export GOARCH=${{ matrix.go_target }} - export CFLAGS="-Wno-error=unused-command-line-argument -target ${{ matrix.clang_target }}-unknown-darwin-unknown" + #export CFLAGS="-Wno-error=unused-command-line-argument -target ${{ matrix.clang_target }}-unknown-darwin-unknown" + export CC=gcc go build -buildmode=c-shared -o minify.so - name: Upload go library From f338f2f060c0b0d4e5681fbe579d0fbc54d81181 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 16:53:30 -0500 Subject: [PATCH 45/60] Disable macOS Python build for now --- .github/workflows/python.yml | 76 ++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index e57771c93c..93da71823e 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -51,24 +51,15 @@ jobs: with: path: ./wheelhouse/*.whl - go-crosscompile: + windows-go-crosscompile: runs-on: ubuntu-latest strategy: matrix: include: - - go_os: windows - go_target: amd64 + - go_target: amd64 xcompiler: x86_64-w64-mingw32-gcc-win32 - #- go_os: windows # go_target: 386 # xcompiler: i686-w64-mingw32-gcc-win32 - - go_os: darwin - go_target: amd64 - clang_target: x86_64 - - go_os: darwin - go_target: arm64 - clang_target: arm64 - steps: - uses: actions/checkout@v3 @@ -89,31 +80,20 @@ jobs: cd bindings/py go get github.com/tdewolff/minify/v2@$(git describe --tags --abbrev=0) - name: Prebuild windows extension - if: matrix.go_os == 'windows' run: | sudo apt-get install mingw-w64 cd bindings/py - CC=${{ matrix.xcompiler }} CGO_ENABLED=1 GOOS=${{ matrix.go_os }} GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - - name: Prebuild macos extension - if: matrix.go_os == 'darwin' - run: | - cd bindings/py - export CGO_ENABLED=1 - export GOOS=${{ matrix.go_os }} - export GOARCH=${{ matrix.go_target }} - #export CFLAGS="-Wno-error=unused-command-line-argument -target ${{ matrix.clang_target }}-unknown-darwin-unknown" - export CC=gcc - go build -buildmode=c-shared -o minify.so + CC=${{ matrix.xcompiler }} CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so - name: Upload go library uses: actions/upload-artifact@v3 with: - name: minify-${{ matrix.go_os }}-${{ matrix.go_target }}.so + name: minify-windows-${{ matrix.go_target }}.so path: bindings/py/minify.so windows: runs-on: windows-latest - needs: go-crosscompile + needs: windows-go-crosscompile strategy: matrix: include: @@ -143,9 +123,53 @@ jobs: name: wheels path: ./wheelhouse/*.whl + macos-go-crosscompile: + if: false + runs-on: ubuntu-latest + strategy: + matrix: + include: + - go_target: amd64 + clang_target: x86_64 + - go_target: arm64 + clang_target: arm64 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/setup-go@v4 + with: + go-version: '>=1.17' + - name: Fetch go package + if: startsWith(github.ref, 'refs/tags/') + run: | + cd bindings/py + go get github.com/tdewolff/minify/v2@${GITHUB_REF#refs/tags/} + - name: Fetch go package + if: startsWith(github.ref, 'refs/tags/') == false + run: | + cd bindings/py + go get github.com/tdewolff/minify/v2@$(git describe --tags --abbrev=0) + - name: Prebuild macos extension + run: | + cd bindings/py + export CGO_ENABLED=1 + export GOOS=darwin + export GOARCH=${{ matrix.go_target }} + #export CFLAGS="-Wno-error=unused-command-line-argument -target ${{ matrix.clang_target }}-unknown-darwin-unknown" + export CC=gcc + go build -buildmode=c-shared -o minify.so + + - name: Upload go library + uses: actions/upload-artifact@v3 + with: + name: minify-darwin-${{ matrix.go_target }}.so + path: bindings/py/minify.so macos: + if: false runs-on: macos-latest - needs: go-crosscompile + needs: macos-go-crosscompile strategy: matrix: include: From 1137698e9c76a8e93fd9755f494e62cd186e1659 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 17:32:32 -0500 Subject: [PATCH 46/60] Fix QEMU filter for Linux ARM Python build --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 93da71823e..18f90b8f80 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -28,7 +28,7 @@ jobs: - uses: actions/checkout@v3 - name: Set up QEMU - if: matrix.cibw_target == 'arm64' + if: matrix.go_target == 'arm64' uses: docker/setup-qemu-action@v2 with: platforms: arm64 From 70af36f856fe6f0e1f1656c6a68c813ddb559fc6 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 17:33:15 -0500 Subject: [PATCH 47/60] Disable dependency on macos for Python release --- .github/workflows/python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 18f90b8f80..b829d716aa 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -228,7 +228,8 @@ jobs: name: Release runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/') - needs: [linux, windows, macos, sdist] + #needs: [linux, windows, macos, sdist] + needs: [linux, windows, sdist] steps: - name: Collect artifacts uses: actions/download-artifact@v3 From c76785afd95222bd3f4ab5a29c81000186579739 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 19:59:36 -0500 Subject: [PATCH 48/60] Increase cibuildwheel verbosity for windows Python build --- .github/workflows/python.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index b829d716aa..8425c6fbd6 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -116,6 +116,7 @@ jobs: package-dir: bindings/py env: CIBW_ARCHS: ${{ matrix.cibw_target }} + CIBW_BUILD_VERBOSITY: 1 - name: Upload wheels uses: actions/upload-artifact@v3 From f7de692e9dbe099305c4045e6569578efcd35d4d Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 20:03:59 -0500 Subject: [PATCH 49/60] Fix inconsistencies in Python workflow artifact management --- .github/workflows/python.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 8425c6fbd6..cb0a690c94 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -203,6 +203,7 @@ jobs: - name: Upload wheels uses: actions/upload-artifact@v3 with: + name: wheels path: ./wheelhouse/*.whl sdist: @@ -223,7 +224,7 @@ jobs: uses: actions/upload-artifact@v3 with: name: wheels - path: dist + path: bindings/py/dist/* release: name: Release @@ -234,6 +235,9 @@ jobs: steps: - name: Collect artifacts uses: actions/download-artifact@v3 + with: + name: wheels + path: dist - name: Upload to GitHub Release uses: softprops/action-gh-release@v0.1.14 - name: Publish to PyPI From 338f159c45aafa838eeaa48c22d446f44e76583f Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 20:09:47 -0500 Subject: [PATCH 50/60] Try to fix missing .so on windows Python builds --- bindings/py/setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/py/setup.py b/bindings/py/setup.py index 37d7895188..cda61deec5 100644 --- a/bindings/py/setup.py +++ b/bindings/py/setup.py @@ -61,6 +61,7 @@ def build_extension(self, ext: Extension): packages=["minify"], package_dir={"": "src"}, package_data={"minify": ["_minify.so"]}, + include_package_data=True, setup_requires=["cffi>=1.0.0"], cffi_modules=["build_minify.py:ffi"], install_requires=["cffi>=1.0.0"], From 3419d9451fd492e0462e6cdd05bf7f93445032ae Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 20:20:33 -0500 Subject: [PATCH 51/60] Try to fix missing .so on windows Python builds (2) --- bindings/py/MANIFEST.in | 1 + bindings/py/setup.py | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/bindings/py/MANIFEST.in b/bindings/py/MANIFEST.in index 4500817b4e..f8a50bf715 100644 --- a/bindings/py/MANIFEST.in +++ b/bindings/py/MANIFEST.in @@ -1,4 +1,5 @@ include README.md include minify.go go.mod go.sum +include src/minify/_minify.so include build_minify.py include py.typed diff --git a/bindings/py/setup.py b/bindings/py/setup.py index cda61deec5..494c19a058 100644 --- a/bindings/py/setup.py +++ b/bindings/py/setup.py @@ -60,8 +60,6 @@ def build_extension(self, ext: Extension): cmdclass={"build_ext": build_ext_external}, packages=["minify"], package_dir={"": "src"}, - package_data={"minify": ["_minify.so"]}, - include_package_data=True, setup_requires=["cffi>=1.0.0"], cffi_modules=["build_minify.py:ffi"], install_requires=["cffi>=1.0.0"], From ccc9937506faa657377ee95f7a50287ce07b15f3 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 20:40:36 -0500 Subject: [PATCH 52/60] Try to fix missing .so on Python builds (3) --- bindings/py/setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/py/setup.py b/bindings/py/setup.py index 494c19a058..ae3fc93cc9 100644 --- a/bindings/py/setup.py +++ b/bindings/py/setup.py @@ -60,6 +60,7 @@ def build_extension(self, ext: Extension): cmdclass={"build_ext": build_ext_external}, packages=["minify"], package_dir={"": "src"}, + include_package_data=True, setup_requires=["cffi>=1.0.0"], cffi_modules=["build_minify.py:ffi"], install_requires=["cffi>=1.0.0"], From 8f0b8db9ae1464d6272ca7a601f64ea00adc7afe Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 20:49:04 -0500 Subject: [PATCH 53/60] Try to fix missing .so on windows Python builds (4) --- .github/workflows/python.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index cb0a690c94..f6530702df 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -108,7 +108,9 @@ jobs: - uses: actions/download-artifact@v3 with: name: minify-windows-${{ matrix.go_target }}.so - path: bindings/py/src/minify/_minify.so + - name: Insert pre-built library + run: | + mv minify-windows-${{ matrix.go_target }}.so bindings/py/src/minify/_minify.so - name: Build wheels uses: pypa/cibuildwheel@v2.15.0 From 07b03594ce0713d51e4e37de23f4708f42ceb8f9 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 20:53:08 -0500 Subject: [PATCH 54/60] Try to debug missing .so on windows Python builds (5) --- .github/workflows/python.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index f6530702df..c5288589c0 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -110,6 +110,7 @@ jobs: name: minify-windows-${{ matrix.go_target }}.so - name: Insert pre-built library run: | + ls mv minify-windows-${{ matrix.go_target }}.so bindings/py/src/minify/_minify.so - name: Build wheels From 1ff8f0b819d485041934fbcdb9c5daac02c46683 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 20:57:19 -0500 Subject: [PATCH 55/60] Fix missing .so on windows Python builds (6) --- .github/workflows/python.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index c5288589c0..ae1ee11452 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -83,13 +83,13 @@ jobs: run: | sudo apt-get install mingw-w64 cd bindings/py - CC=${{ matrix.xcompiler }} CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o minify.so + CC=${{ matrix.xcompiler }} CGO_ENABLED=1 GOOS=windows GOARCH=${{ matrix.go_target }} go build -buildmode=c-shared -o _minify.so - name: Upload go library uses: actions/upload-artifact@v3 with: name: minify-windows-${{ matrix.go_target }}.so - path: bindings/py/minify.so + path: bindings/py/_minify.so windows: runs-on: windows-latest @@ -108,10 +108,7 @@ jobs: - uses: actions/download-artifact@v3 with: name: minify-windows-${{ matrix.go_target }}.so - - name: Insert pre-built library - run: | - ls - mv minify-windows-${{ matrix.go_target }}.so bindings/py/src/minify/_minify.so + path: bindings/py/src/minify - name: Build wheels uses: pypa/cibuildwheel@v2.15.0 From 3e6a1fff80ca00118c63916253efefb106c32c76 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Tue, 17 Oct 2023 21:14:38 -0500 Subject: [PATCH 56/60] Ensure correct files are added to GitHub release by Python workflow --- .github/workflows/python.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index ae1ee11452..cccf060a89 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -240,6 +240,8 @@ jobs: path: dist - name: Upload to GitHub Release uses: softprops/action-gh-release@v0.1.14 + with: + files: dist/* - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 with: From 2dc8268c630acea9178c46d654181f46494275ad Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Wed, 18 Oct 2023 16:50:39 -0500 Subject: [PATCH 57/60] Adjust artifact naming for Python workflow --- .github/workflows/python.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index cccf060a89..3a9abc8f50 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -49,6 +49,7 @@ jobs: - name: Upload wheels uses: actions/upload-artifact@v3 with: + name: wheels-linux-${{ matrix.go_target }} path: ./wheelhouse/*.whl windows-go-crosscompile: @@ -121,7 +122,7 @@ jobs: - name: Upload wheels uses: actions/upload-artifact@v3 with: - name: wheels + name: wheels-windows-${{ matrix.go_target }} path: ./wheelhouse/*.whl macos-go-crosscompile: @@ -203,7 +204,7 @@ jobs: - name: Upload wheels uses: actions/upload-artifact@v3 with: - name: wheels + name: wheels-macos-${{ matrix.go_target }} path: ./wheelhouse/*.whl sdist: @@ -236,8 +237,9 @@ jobs: - name: Collect artifacts uses: actions/download-artifact@v3 with: - name: wheels path: dist + - name: Omit non-release files + run: rm dist/*.so - name: Upload to GitHub Release uses: softprops/action-gh-release@v0.1.14 with: From 426399a44f8e954b6385791ed3d07edf8f21d154 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Wed, 18 Oct 2023 16:56:09 -0500 Subject: [PATCH 58/60] Production-ready Github workflow triggers for Python --- .github/workflows/python.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 3a9abc8f50..38d910a601 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -4,9 +4,11 @@ on: push: branches: - master - - python-packaging tags: - '*' + pull_request: + branches: + - master permissions: contents: read From b637e6fe8ce8a7367245c3337d70802cabfb98a6 Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Sat, 21 Oct 2023 11:31:12 -0500 Subject: [PATCH 59/60] Match Python bindings workflow triggers to Go package workflow --- .github/workflows/python.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 38d910a601..7cf93157de 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -2,13 +2,8 @@ name: Python on: push: - branches: - - master tags: - - '*' - pull_request: - branches: - - master + - 'v*' permissions: contents: read From 999bec134346ecde112b5ad86adfd723a9c5e0fd Mon Sep 17 00:00:00 2001 From: Daniel Foerster Date: Sat, 21 Oct 2023 11:38:58 -0500 Subject: [PATCH 60/60] Bring back the possibility for building Go lib from within Python binding build --- bindings/py/setup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bindings/py/setup.py b/bindings/py/setup.py index ae3fc93cc9..0374277305 100644 --- a/bindings/py/setup.py +++ b/bindings/py/setup.py @@ -3,6 +3,7 @@ from setuptools.command.build_ext import build_ext from setuptools.errors import CompileError from setuptools.extension import Extension +from subprocess import CalledProcessError, check_call HERE = pathlib.Path(__file__).parent @@ -22,7 +23,10 @@ class build_ext_external(build_ext): """Placeholder for externally-built extension.""" def build_extension(self, ext: Extension): if not all(pathlib.Path(p).exists() for p in ext.sources): - raise CompileError(f'Missing external extension files for {ext.name}!') + try: + check_call(['go', 'build', '-buildmode=c-shared', '-o', *ext.sources]) + except CalledProcessError as e: + raise CompileError('Go compilation failed!') from e setup(