Skip to content

Validate C ABI libraries and link extensions against them - #141

Merged
python-templates-automerge[bot] merged 5 commits into
mainfrom
validate-c-abi-libraries
Nov 13, 2026
Merged

python-templates-automerge[bot] merged 5 commits into
mainfrom
validate-c-abi-libraries

Conversation

@timkpaine

@timkpaine timkpaine commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Description

Add C ABI support to libraries entries, using the validation and library lookup code in hatch-native.

  • libraries entries accept the hatch-rs validation fields: expected-headers, expected-abi-strings, header-symbol-prefix, expected-symbols, validate, and validation-commands. A top-level artifacts list validates files that libraries does not list, such as CMake install output.
  • artifact-manifest writes a JSON file into the wheel that lists each packaged binary.
  • An entry's depends lists generic libraries declared before it. The entry links each one and gets an $ORIGIN or @loader_path rpath to its directory. On Windows it links the import library, which is packaged next to the DLL. depends raises for Emscripten builds.
  • library-source (or HATCH_CPP_LIBRARY_SOURCE) selects bundled (the default), external, or direct for libraries listed in depends. static and python-package raise.
  • Library output directories are created before compiling, so a library can be built into a lib/ subdirectory.

This adds a dependency on hatch-native>=0.1.0,<0.2. hatch-native is on PyPI, and its conda-forge recipe is in review (conda-forge/staged-recipes#35661), so the hatch-cpp feedstock cannot take a release with this change until that recipe merges.

The tests pass on macOS locally and on Linux in CI. CI in this repository has no Windows job, so the Windows import library code is untested.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / code cleanup
  • CI / build configuration
  • Other (describe below)

Checklist

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

Libraries entries accept the hatch-rs validation fields through
hatch-native: expected headers, ABI strings, a header symbol prefix,
expected exports, an optional ctypes load, and validation commands. A
top-level artifacts list validates files that libraries does not name,
such as CMake install output, by path or by library name. The
artifact-manifest option records each packaged binary in a JSON file in
the wheel. Library output directories are created before compiling, so
a library can be built into a lib/ subdirectory.

Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
An entry's depends names generic libraries declared before it. The
entry links each one's output and gets an $ORIGIN or @loader_path rpath
to its directory. On Windows it links the import library, which is
packaged next to the DLL. Generic libraries get a SONAME or an @rpath
install name unless the project sets one, so the link does not record a
build-tree path. depends raises for Emscripten builds.

Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
library-source, or HATCH_CPP_LIBRARY_SOURCE, picks bundled (the default
and the existing behavior), external, or direct. In external mode the
library is not built: hatch-native finds it under library-root,
HATCH_CPP_LIBRARY_ROOT, pkg-config, or the conda prefix, the consumer
links it without an rpath, and validation checks the external file. In
direct mode its sources are compiled into each consumer. static and
python-package raise until hatch-cpp supports them.

Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
A validate instance method is an incompatible override of pydantic's BaseModel.validate classmethod, which fails ty.

Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

110 tests  +23   110 ✅ +23   1m 27s ⏱️ +26s
  1 suites ± 0     0 💤 ± 0 
  1 files   ± 0     0 ❌ ± 0 

Results for commit c334665. ± Comparison against base commit ed37b9b.

♻️ This comment has been updated with latest results.

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.95222% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.31%. Comparing base (ed37b9b) to head (c334665).

Files with missing lines Patch % Lines
hatch_cpp/config.py 95.45% 5 Missing ⚠️
hatch_cpp/plugin.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #141      +/-   ##
==========================================
+ Coverage   95.95%   96.31%   +0.35%     
==========================================
  Files          15       16       +1     
  Lines        1287     1574     +287     
==========================================
+ Hits         1235     1516     +281     
- Misses         52       58       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timkpaine timkpaine added the tag: automerge Automatically merge this PR when status checks pass label Nov 13, 2026
@python-templates-automerge
python-templates-automerge Bot merged commit c4c5605 into main Nov 13, 2026
7 checks passed
@python-templates-automerge
python-templates-automerge Bot deleted the validate-c-abi-libraries branch November 13, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tag: automerge Automatically merge this PR when status checks pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant