Skip to content

Ship a C++ wrapper header and test consumers of the C ABI wheel - #219

Merged
timkpaine merged 3 commits into
mainfrom
rust-c-abi-consumer
Nov 12, 2026
Merged

timkpaine merged 3 commits into
mainfrom
rust-c-abi-consumer

Conversation

@timkpaine

Copy link
Copy Markdown
Member

Description

Stacked on #218. Two additions to the rust variant with add_c_abi:

  • rust/capi/include/<module>.hpp, a hand-written C++ wrapper over the generated C header (RAII Example, exceptions from status/null returns, abi_version()), shipped beside the C header under <module>/include/<module>. It shows that any extra header in rust/capi/include can be shipped by adding an outputs entry on the library artifact.
  • Consumer tests: the generated project's test suite compiles a C program against get_include()/get_library_dirs()/get_libraries() and a C++ program against the wrapper, runs them, and checks the output (1 consumer). On MSVC the import library shipped under lib/ is linked and the DLL directory is put on PATH for the run; elsewhere an rpath to the package's lib/ is set. The tests skip when no compiler is on PATH and under Pyodide.

Verified locally: the regenerated project passes make lint, make checks, and make test (4 Python tests including both consumers, 3 Rust tests), and the wheel contains the extension, the library, and both headers.

Type of Change

  • New feature

Checklist

  • Linting passes (make lint)
  • Tests pass (make test)
  • New tests added for new functionality
  • Documentation updated (if applicable)
  • Changelog / version bump (if applicable)

Base automatically changed from rust-c-abi to main November 11, 2026 18:11
With add_c_abi, rust/capi/include/<module>.hpp wraps the C ABI in RAII
handles and exceptions and is shipped next to the generated C header
under <module>/include/<module>. The generated project's tests compile a
C program against get_include()/get_library_dirs() and a C++ program
against the wrapper, run them, and check their output, so a wheel that
cannot be consumed fails its own tests. The checks skip without a
compiler on PATH and under Pyodide.

Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
The DLL ships inside the wheel under <module>/lib, so delvewheel must not search PATH for it. Found on fsspec-rs, which hit the same failure.

Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
@timkpaine
timkpaine merged commit cfd7b6e into main Nov 12, 2026
46 checks passed
@timkpaine
timkpaine deleted the rust-c-abi-consumer branch November 12, 2026 03:12
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