Skip to content

fix(bind): handle library paths with directories in generated bindings - #37

Merged
petlukk merged 1 commit into
mainfrom
fix/issue1-bind-lib-path
May 19, 2026
Merged

fix(bind): handle library paths with directories in generated bindings#37
petlukk merged 1 commit into
mainfrom
fix/issue1-bind-lib-path

Conversation

@petlukk

@petlukk petlukk commented May 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • Closes ea bind: generated Python uses Path.with_name("./lib/foo.so") which is rejected as invalid #1. Python and PyTorch bindings no longer pass slashed paths to Path.with_name (which raises ValueError); they now emit a _Path(__file__).parent / "lib" / "libfoo.so" chain that survives any -o <dir>/<file>.so layout.
  • Rust bindings no longer emit #[link(name = "lib/libfoo")] (invalid Rust); they now strip the directory and the Unix lib prefix to produce #[link(name = "foo")].
  • Logic centralized in two bind_common helpers (python_lib_path_expr, rust_link_stem); docs/public-api.txt refreshed for the public-api CI gate.

Test plan

  • 4 new tests added (3 path-with-slash + 1 plain-name regression guard) — verified RED before the fix, GREEN after.
  • Full release suite: 987 passed, 0 failed (was 983).
  • cargo clippy --release --all-targets clean.
  • End-to-end repro from issue ea bind: generated Python uses Path.with_name("./lib/foo.so") which is rejected as invalid #1 now succeeds: ea bind my_kernel.ea --python after building with -o lib/libmy_kernel.so produces an importable module; calling add_one(41) returns 42.
  • cargo public-api --simplified matches the refreshed snapshot.

🤖 Generated with Claude Code

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>
@petlukk
petlukk merged commit 82161c6 into main May 19, 2026
4 checks passed
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.

ea bind: generated Python uses Path.with_name("./lib/foo.so") which is rejected as invalid

1 participant