fix(bind): handle library paths with directories in generated bindings - #37
Merged
Conversation
The Python, PyTorch, and Rust binding generators all mishandled `library`
fields that include a directory component (e.g. when the kernel is built
with `-o lib/libfoo.so`):
- bind_python / bind_pytorch emitted `Path(__file__).with_name("lib/libfoo.so")`
which raises ValueError — `with_name` rejects any name containing `/`.
Every `--python` and `--pytorch` binding produced under that flow was
unimportable.
- bind_rust emitted `#[link(name = "lib/libfoo")]` which is invalid Rust;
link names must be a bare library stem with no path or Unix `lib` prefix.
Fix splits the path: Python bindings now emit a chain like
`_Path(__file__).parent / "lib" / "libfoo.so"`; Rust bindings strip the
directory + `lib` prefix to produce `#[link(name = "foo")]`.
Two new helpers in bind_common (`python_lib_path_expr`, `rust_link_stem`)
keep the logic in one place. Refreshed `docs/public-api.txt` for the
public-api CI gate. Four new tests cover the fix.
Closes #1
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.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.
Summary
Path.with_name(which raisesValueError); they now emit a_Path(__file__).parent / "lib" / "libfoo.so"chain that survives any-o <dir>/<file>.solayout.#[link(name = "lib/libfoo")](invalid Rust); they now strip the directory and the Unixlibprefix to produce#[link(name = "foo")].bind_commonhelpers (python_lib_path_expr,rust_link_stem);docs/public-api.txtrefreshed for the public-api CI gate.Test plan
cargo clippy --release --all-targetsclean.ea bind my_kernel.ea --pythonafter building with-o lib/libmy_kernel.soproduces an importable module; callingadd_one(41)returns42.cargo public-api --simplifiedmatches the refreshed snapshot.🤖 Generated with Claude Code