Skip to content

feat: allow opt-in for new backends - #409

Draft
b-long wants to merge 44 commits into
masterfrom
feature/replacing-pybindgen
Draft

b-long wants to merge 44 commits into
masterfrom
feature/replacing-pybindgen

Conversation

@b-long

@b-long b-long commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

⚠️ work-in-progress ⚠️

Relates-to: #408

Adds opt-in alternatives to pybindgen, chosen with GOPY_BACKEND. The default stays pybindgen. The only change to its output is the generated Makefile fix described below.

Backend Needs gopy exe Status
capi nothing beyond Python yes full suite passes
cffi cffi no full suite passes
pybind11 pybind11, C++ compiler no full suite passes
nanobind nanobind, C++ compiler no full suite passes

Each backend has its own CI job on Linux, macOS and Windows (Python 3.11 and 3.12), with pybindgen not installed. A benchmark job compares per-call time and memory across all backends and uploads the table as a build artifact.

Notes

  • capi keeps the default backend's Go shim and build, but writes the C module itself instead of calling pybindgen. Its output matches pybindgen's argument handling and errors. It's the simplest way to drop the pybindgen dependency.
  • cffi, pybind11 and nanobind share a plain-C Go shim that avoids the CPython C API. The Python side is either a cffi module or a compiled C++ module. Because of that shim:
    • gopy exe rejects them up front, since exe mode embeds the interpreter through the C API.
    • A function is skipped if its signature needs a raw PyObject*, such as a callback type the shim can't translate or complex numbers outside the supported cases. gopy prints ignoring function not supported by GOPY_BACKEND=<name>: ... for each one.
  • Change to the default backend: the Makefile that gopy gen writes for pybindgen (and capi) used to link _<pkg> against a separate <pkg>_go library with no rpath, so the result didn't import as-is. It now has cgo compile <pkg>.c into one shared library, the same way gopy build does. TestMakefile now runs for every backend.
  • gopy pkg and gopy exe now restore the working directory when they finish.
  • New test coverage: _examples/callbacks, additions to _examples/pyerrors and _examples/slices, plus Go unit tests in bind/ for backend selection, callbacks and the C++ build.

@b-long b-long mentioned this pull request Sep 19, 2026
Comment thread main_test.go Outdated
Comment thread cmd_build.go Outdated
@b-long

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant