Repository navigation
feat: allow opt-in for new backends #288
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [ master ] | |
| pull_request: | |
| branches: [ '**' ] | |
| env: | |
| TAGS: "-tags=ci" | |
| COVERAGE: "-coverpkg=github.com/go-python/gopy/..." | |
| # Init() in main_test will make sure all backends are available if | |
| # GOPY_TRAVIS_CI is set | |
| GOPY_TRAVIS_CI: 1 | |
| GOTRACEBACK: crash | |
| GO111MODULE: auto | |
| jobs: | |
| build: | |
| name: Build (${{ matrix.platform }}, Go ${{ matrix.go-version }}, Python ${{ matrix.python-version }}) | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # TODO: Consider official support matrix (OS and Go versions) and adjust this matrix accordingly | |
| go-version: [1.25.x, 1.24.x, 1.23.x, 1.22.x] | |
| platform: [ubuntu-latest, windows-latest, macos-15] | |
| python-version: ['3.11', '3.12'] | |
| runs-on: ${{ matrix.platform }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| cache: true | |
| - name: Install Linux packages | |
| if: matrix.platform == 'ubuntu-latest' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install curl libffi-dev python3-cffi python3-pip | |
| # install pybindgen | |
| python3 -m pip install --user -U pybindgen | |
| # install goimports | |
| go install golang.org/x/tools/cmd/goimports@latest | |
| - name: Install macOS packages | |
| if: startsWith(matrix.platform, 'macos-') | |
| run: | | |
| python3 -m pip install -U pybindgen | |
| go install golang.org/x/tools/cmd/goimports@latest | |
| - name: Install Windows packages | |
| if: matrix.platform == 'windows-latest' | |
| run: | | |
| # install pybindgen and psutil (for memory tracking in tests) | |
| python -m pip install -U pybindgen psutil | |
| # install goimports | |
| go install golang.org/x/tools/cmd/goimports@latest | |
| - name: Build-Linux | |
| if: matrix.platform == 'ubuntu-latest' | |
| run: | | |
| make | |
| - name: Test Linux | |
| if: matrix.platform == 'ubuntu-latest' | |
| run: | | |
| make test | |
| - name: Build-macOS | |
| if: startsWith(matrix.platform, 'macos-') | |
| run: | | |
| make | |
| - name: Test macOS | |
| if: startsWith(matrix.platform, 'macos-') | |
| run: | | |
| make test | |
| - name: Build-Windows | |
| if: matrix.platform == 'windows-latest' | |
| run: | | |
| go build -v ./... | |
| - name: Test Windows | |
| if: matrix.platform == 'windows-latest' | |
| run: | | |
| go test -v ./... | |
| - name: Upload-Coverage | |
| if: matrix.platform == 'ubuntu-latest' | |
| uses: codecov/codecov-action@v4 | |
| # Builds and tests the opt-in cffi backend (GOPY_BACKEND=cffi). Runs beside | |
| # the main matrix, on one Go version, and stops at the first failure. | |
| cffi: | |
| name: cffi backend (${{ matrix.platform }}, Python ${{ matrix.python-version }}) | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| platform: [ubuntu-latest, windows-latest, macos-15] | |
| python-version: ['3.11', '3.12'] | |
| runs-on: ${{ matrix.platform }} | |
| env: | |
| GOPY_BACKEND: cffi | |
| # print the python stack if the process crashes, e.g. at exit | |
| PYTHONFAULTHANDLER: 1 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: pip | |
| cache-dependency-path: .github/requirements-cffi.txt | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.25.x | |
| cache: true | |
| - name: Install packages | |
| run: | | |
| python -m pip install -r .github/requirements-cffi.txt | |
| go install golang.org/x/tools/cmd/goimports@v0.29.0 | |
| - name: Build | |
| run: go build -v ./... | |
| - name: Test | |
| run: go test -v ./... | |
| # Builds and tests the opt-in pybind11 backend (GOPY_BACKEND=pybind11). | |
| # Runs beside the main matrix, on one Go version, and stops at the first | |
| # failure. Shares its cgo shim with cffi (see noAPIShim in bind/cffi.go); | |
| # what's new here is compiling a C++ file against that shim with a real | |
| # C++ compiler, so unlike the cffi job this needs no extra system packages | |
| # (a C++ compiler is already required for CGO_ENABLED=1 on every platform). | |
| pybind11: | |
| name: pybind11 backend (${{ matrix.platform }}, Python ${{ matrix.python-version }}) | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| platform: [ubuntu-latest, windows-latest, macos-15] | |
| python-version: ['3.11', '3.12'] | |
| runs-on: ${{ matrix.platform }} | |
| env: | |
| GOPY_BACKEND: pybind11 | |
| # CXX defaults to "c++" in buildCXXModule (cmd_build.go), which isn't a | |
| # recognized command on windows-latest's MinGW toolchain (the same one | |
| # CGO_ENABLED=1 already needs there, so no extra install is needed). | |
| CXX: g++ | |
| PYTHONFAULTHANDLER: 1 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: pip | |
| cache-dependency-path: .github/requirements-pybind11.txt | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.25.x | |
| cache: true | |
| - name: Install packages | |
| run: | | |
| python -m pip install -r .github/requirements-pybind11.txt | |
| go install golang.org/x/tools/cmd/goimports@v0.29.0 | |
| - name: Build | |
| run: go build -v ./... | |
| # -timeout raises go test's own default (10m): each test here compiles | |
| # twice (cgo, then a separate C++ step), against cffi's one, and once | |
| # measured at ~18.5s/test average on windows-latest, 32 tests alone used | |
| # 590s of the default budget. | |
| - name: Test | |
| run: go test -v -timeout=30m ./... | |
| # Builds and tests the opt-in nanobind backend (GOPY_BACKEND=nanobind). | |
| # Same shape as the pybind11 job above (the two share a cgo shim and a | |
| # build step, see buildCXXModule in cmd_build.go); nanobind additionally | |
| # compiles its own runtime (nb_combined.cpp) into every module, which | |
| # needs no extra system packages either. | |
| nanobind: | |
| name: nanobind backend (${{ matrix.platform }}, Python ${{ matrix.python-version }}) | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| platform: [ubuntu-latest, windows-latest, macos-15] | |
| python-version: ['3.11', '3.12'] | |
| runs-on: ${{ matrix.platform }} | |
| env: | |
| GOPY_BACKEND: nanobind | |
| # see the pybind11 job | |
| CXX: g++ | |
| PYTHONFAULTHANDLER: 1 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: pip | |
| cache-dependency-path: .github/requirements-nanobind.txt | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.25.x | |
| cache: true | |
| - name: Install packages | |
| run: | | |
| python -m pip install -r .github/requirements-nanobind.txt | |
| go install golang.org/x/tools/cmd/goimports@v0.29.0 | |
| - name: Build | |
| run: go build -v ./... | |
| # -timeout: see the pybind11 job | |
| - name: Test | |
| run: go test -v -timeout=30m ./... | |
| # Builds and tests the opt-in capi backend (GOPY_BACKEND=capi). Runs beside | |
| # the main matrix, on one Go version, and stops at the first failure. Builds | |
| # exactly as the default backend does, except that build.py writes the C | |
| # module itself (see bind/capi_build.py), so pybindgen isn't installed here. | |
| capi: | |
| name: capi backend (${{ matrix.platform }}, Python ${{ matrix.python-version }}) | |
| strategy: | |
| fail-fast: true | |
| matrix: | |
| platform: [ubuntu-latest, windows-latest, macos-15] | |
| python-version: ['3.11', '3.12'] | |
| runs-on: ${{ matrix.platform }} | |
| env: | |
| GOPY_BACKEND: capi | |
| # print the python stack if the process crashes, e.g. at exit | |
| PYTHONFAULTHANDLER: 1 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: pip | |
| cache-dependency-path: .github/requirements-capi.txt | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.25.x | |
| cache: true | |
| - name: Install packages | |
| run: | | |
| python -m pip install -r .github/requirements-capi.txt | |
| go install golang.org/x/tools/cmd/goimports@v0.29.0 | |
| - name: Build | |
| run: go build -v ./... | |
| - name: Test | |
| run: go test -v ./... | |
| # Compares per-call overhead across backends (see _examples/bench/run.sh): | |
| # not a pass/fail check, just a table uploaded as a build artifact. Runs | |
| # on ubuntu-latest only -- the comparison is between backends, not OSes. | |
| benchmark: | |
| name: benchmark backends | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: Install Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: 1.25.x | |
| cache: true | |
| - name: Install packages | |
| run: | | |
| python -m pip install pybindgen cffi pybind11 nanobind | |
| go install golang.org/x/tools/cmd/goimports@v0.29.0 | |
| - name: Run benchmark | |
| run: bash _examples/bench/run.sh | tee benchmark.txt | |
| - name: Upload benchmark table | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: benchmark | |
| path: benchmark.txt |