Skip to content

feat: add node_data attribute to nodejs_toolchain#3911

Open
djedward wants to merge 1 commit intobazel-contrib:mainfrom
djedward:main
Open

feat: add node_data attribute to nodejs_toolchain#3911
djedward wants to merge 1 commit intobazel-contrib:mainfrom
djedward:main

Conversation

@djedward
Copy link
Copy Markdown

@djedward djedward commented Apr 9, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Only the node binary itself can be provided for a toolchain. No supporting files may be included.

Issue Number: N/A

What is the new behavior?

This introduces a new, optional, node_data attribute to nodejs_toolchain to allow for additional runtime files to be provided with the node binary. Though this is likely not a common need, we ran into issues for some of our node toolchains which have wrapper scripts to handle special setups. I'm working on a corresponding update to rules_js to use this new attribute as well.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

All of the links in the existing documentation to nodejs_toolchain appear to go to non-existent places, so outside of the documetation in the toolchain.bzl, I didn't add any.

The node_data attribute allows for additional runtime files
to be provided with the node binary.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1862e131c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

allow_single_file = True,
),
"node_path": attr.string(),
"node_data": attr.label_list(allow_files = True),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve node_data in exec configuration

The new node_data attribute is declared without cfg = "exec", while node is explicitly exec-configured. In toolchain rules this causes node_data labels/selects to resolve in the target configuration, so cross-platform builds can pair an exec-platform Node binary with target-platform companion files (for example, host x86_64 tool with arm64-target node_data), which can break wrapper scripts or native runtime dependencies at execution time.

Useful? React with 👍 / 👎.

@jbedard
Copy link
Copy Markdown
Collaborator

jbedard commented Apr 9, 2026

Can you provide an example of when this would be used instead of simply using js_binary(data) on the binary target itself?

@djedward
Copy link
Copy Markdown
Author

Our use-case is that our node team produces our node toolchain with a wrapper script:

bin/
├── node (shell script with internal-specific setup)
├── node_real (the real node binary, can't run without the shell setup)

So when we setup the toolchain for other teams to consume, we need a way for both of these files to be present in the sandbox. One hack we played with was including it in the npm_srcs and then all js_binary uses could specify include_npm. It works, but quite hacky/confusing to consumers. Similarly, providing a way for it to be specified in js_binary data could potentially work, but since it is part of the toolchain, it felt wrong to push onto consumers.

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.

2 participants