Skip to content

Conversation

@alexeagle
Copy link
Contributor

@alexeagle alexeagle commented Nov 23, 2025

This technique is sometimes needed when a proc_macro derives information from the build, and it needs to be consumed by some other tool.

For example this one generates a JSON file as an intermediate output
https://github.com/napi-rs/napi-rs/blob/main/crates/macro/src/expand/typedef/type_def.rs#L11-L12
and then expects developers to call this via a Node.js binary which wraps rustc and also transforms that file to a TypeScript type definition file.

Under Bazel, this is better modeled as a rust_shared_library that produces the binding file (.so or .dylib for example) along with that JSON output, then run the Node.js binary as a separate target.

@alexeagle alexeagle marked this pull request as ready for review November 26, 2025 23:40
@UebelAndre UebelAndre self-requested a review November 27, 2025 06:11
@alexeagle
Copy link
Contributor Author

@UebelAndre ping!

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generally looks reasonable - could you add a small test showing this working? Thanks!

@alexeagle
Copy link
Contributor Author

@illicitonion done, thanks PTAL

…s will be created

This technique is sometimes needed when a proc_macro derives information from the build, and it needs to be consumed by some other tool

sort

cursor wrote a new unit test for this PR

fmt
@alexeagle
Copy link
Contributor Author

Test failures do not look related to my change, FWICT

Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, thanks! A couple of small things :)

],
proc_macro_deps = [":write_outdirs_macro"],
rustc_env = {
"EXTRA_OUTDIRS": "test_dir,another_dir",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make sure the output dirs support location expansion? That's how I'd expect this to be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added to the docstring:

"The paths are always relative to the output directory of the current Bazel package."

I would not expect them to support location expansion, but only because https://bazel.build/rules/lib/toplevel/attr#output_list doesn't have an equivalent output_dir_list, so there's no way during analysis to resolve such expansions.

Seems like a missing feature in Bazel to me.

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.

3 participants