Skip to content

feat: declare cdef public/api headers as outputs#93

Merged
henryiii merged 2 commits into
mainfrom
feat/header-outputs
Jul 12, 2026
Merged

feat: declare cdef public/api headers as outputs#93
henryiii merged 2 commits into
mainfrom
feat/header-outputs

Conversation

@henryiii

@henryiii henryiii commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

When a .pyx uses cdef public / cdef api, Cython writes <name>.h / <name>_api.h next to the generated source, but cython_transpile never declared them, so other targets could not depend on them and their paths were unknown.

This adds two opt-in keywords, PUBLIC_HEADER_VARIABLE <var> and API_HEADER_VARIABLE <var>. When given, cython_transpile:

  • computes the header path from the output file basename (<out_dir>/<stem>.h, <out_dir>/<stem>_api.h, matching where Cython actually writes them),
  • declares it as an additional OUTPUT of the generating command so downstream targets can depend on it, and
  • returns the path in the caller-provided variable.

Explicit keywords were chosen over auto-detection: scanning the source for cdef public / cdef api is fragile (comments, strings, .pxd includes) and would silently declare outputs Cython may not emit.

A new public_headers test fixture builds a separate C target that #includes the generated header (via OBJECT_DEPENDS) and asserts both headers exist after the wheel build; it fails without the output declaration because the consumer races ahead of Cython.

Docs comment block in UseCython.cmake and README.md updated.

Addresses item 1 of the first comment on #84.

A .pyx with `cdef public` / `cdef api` declarations makes Cython write
`<name>.h` / `<name>_api.h` next to the generated source. Add
`PUBLIC_HEADER_VARIABLE` and `API_HEADER_VARIABLE` keywords to
`cython_transpile` that declare those headers as additional outputs of the
generating command and return their paths, so other targets can depend on
them cleanly.

Addresses item 1 of the first comment on #84.

Assisted-by: ClaudeCode:claude-opus-4-8
@henryiii
henryiii force-pushed the feat/header-outputs branch from 2930e88 to 20056a0 Compare July 10, 2026 19:27
@henryiii
henryiii marked this pull request as ready for review July 12, 2026 02:59
Cython names cdef public/api headers and annotate HTML by replacing the
output file's last extension (os.path.splitext), but NAME_WE strips the
longest extension, so OUTPUT names like mod.generated.c declared and
returned paths that were never created.

Assisted-by: ClaudeCode:claude-fable-5
@henryiii
henryiii merged commit ee42ac7 into main Jul 12, 2026
28 checks passed
@henryiii
henryiii deleted the feat/header-outputs branch July 12, 2026 04:09
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