Repository navigation
Add library-source modes and read symbols from the binary - #94
Merged
Merged
Conversation
Symbol validation reads the export table of the ELF, Mach-O, PE, or WebAssembly file instead of loading it with ctypes.CDLL, so expected-symbols and header-symbol-prefix work for cross builds and Pyodide. Only validate = true still loads the library. A Python extension artifact can now link a cdylib artifact through `links`. `library-source` (or HATCH_RS_LIBRARY_SOURCE) picks between bundled, external, static, and direct. Bundled builds get a soname or @rpath install name and an rpath from the extension to the library. External builds skip the library and resolve it from HATCH_RS_LIBRARY_ROOT, library-root, pkg-config, or the conda prefix, with no rpath. library-source-features maps each mode to the extension crate's Cargo features, since Cargo cannot switch dependencies from the environment. The C ABI fixture generates its header with the cbindgen CLI and the extension links the library; a second fixture writes its header from build.rs. The reserved cpp-compat, depfile, and cbindgen-mode fields are removed. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
A library shipped under lib/ needs a layout-neutral identity whether or not an extension in the same wheel links it yet. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
timkpaine
force-pushed
the
split-library
branch
from
November 10, 2026 17:13
2156e20 to
8bc679c
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #94 +/- ##
==========================================
+ Coverage 91.67% 91.77% +0.10%
==========================================
Files 13 15 +2
Lines 2079 2518 +439
==========================================
+ Hits 1906 2311 +405
- Misses 173 207 +34 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A vtable field such as foo_status (*open)(...) names a type before the parenthesis, not an exported function. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
Compare link arguments as argv entries instead of the shell-quoted display, and resolve the fixture package directory so os.add_dll_directory gets an absolute path under python -c. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
7 of 8 tasks
Cargo keeps its metadata hash in the DLL name unless the crate's Cargo.toml declares cdylib, and the import library records that hashed name, so the extension loaded a DLL the wheel never ships. Check the import library names the shipped DLL and declare cdylib in the fixture crate. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Symbol validation now reads the export table of the copied ELF, Mach-O, PE, or WebAssembly file (
hatch_rs/symbols.py, no dependencies) instead of loading it withctypes.CDLL, soexpected-symbolsandheader-symbol-prefixwork for cross builds and Pyodide. Onlyvalidate = truestill loads the library.A Python extension artifact can link a
cdylibartifact throughlinks.library-source(orHATCH_RS_LIBRARY_SOURCE) selectsbundled,external,static, ordirect:bundledbuilds the library, gives it-soname libfoo.soon Linux or an@rpath/libfoo.dylibinstall name on macOS (rustc sets neither), and links the extension with-L/-l dylibplus an rpath from the extension to the library ($ORIGIN/lib,@loader_path/lib). Windows packages the import library.externalskips the build and resolves the library fromHATCH_RS_LIBRARY_ROOT,library-root,pkg-config, or$PREFIX/$CONDA_PREFIX, adds no rpath, and still runs header, symbol, and validation-command checks against it. The artifact manifest records it asexternal-library.staticanddirectskip the library and link nothing.library-source-featuresmaps each mode to the extension crate's Cargo features, since Cargo cannot switch dependencies from an environment variable.HATCH_RS_LIBRARY_<NAME>_DIRand_INCLUDE_DIRreachbuild.rs.Fixtures: the C ABI fixture generates its header with the cbindgen CLI (header no longer checked in) and its extension links the library; tests build it in
bundled,external(against a separate prefix, imported with only the loader path set), anddirectmode, with symbol inspection showing the library is compiled in only underdirect. A new fixture writes its header frombuild.rsthrough the cbindgen build-dependency and validates it on the library artifact.Removed the reserved
cpp-compat,depfile, andcbindgen-modefields. Abuild.rsheader needs no mode: it exists after the Cargo build, soexpected-headerson the library artifact validates it. CI installscbindgen@0.29.4next to the license collector.This is the first step of the split-library pattern needed by fsspec-rs (1kbgz/fsspec-rs#78).
Type of Change
Checklist
make lint)make test)