Skip to content

Write component macro debug output without including it - #2122

Open
Anurag-S1ngh wants to merge 1 commit into
hyperlight-dev:mainfrom
Anurag-S1ngh:fix/1107-component-macro-debug-race
Open

Anurag-S1ngh wants to merge 1 commit into
hyperlight-dev:mainfrom
Anurag-S1ngh:fix/1107-component-macro-debug-race

Conversation

@Anurag-S1ngh

Copy link
Copy Markdown

Summary

HYPERLIGHT_COMPONENT_MACRO_DEBUG wrote the generated code to a file and then read it back with include!(). When a crate invoked the bindgen macros more than once, a later invocation could overwrite the file before the earlier include!() was expanded, so the compiled code did not match the macro input. The macro now emits the tokens it generated directly, while still writing the file for inspection.

Changes

  • emit_decls returns the token stream it was given instead of an include! of the debug file.
  • Extracted write_debug_file and added tests for the returned tokens and the # path substitution.
  • Updated the macro documentation to describe the file as a dump for inspection.

Testing

  • cargo test -p hyperlight-component-util --lib
  • cargo clippy -p hyperlight-component-util -p hyperlight-component-macro --all-targets
  • cargo fmt -p hyperlight-component-util -p hyperlight-component-macro -- --check

cargo test -p hyperlight-component-util also runs doctests, and substitute::Shiftable has a pre-existing doctest failure that is unrelated to this change.

Closes #1107

The debug file set by HYPERLIGHT_COMPONENT_MACRO_DEBUG was read back
with include!(), so when a crate invoked the bindgen macros more than
once the included file could hold another invocation's expansion. Emit
the generated tokens directly and keep writing the file for
inspection.

Signed-off-by: Anurag Singh <anuragsingh2313@gmail.com>
@Anurag-S1ngh
Anurag-S1ngh force-pushed the fix/1107-component-macro-debug-race branch from 0c44248 to 52000ee Compare November 29, 2026 08:10

This branch has not been deployed

No deployments
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.

When using the HYPERLIGHT_COMPONENT_MACRO_DEBUG flag with multiple calls the files are not loaded properly

1 participant