Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: @nodejs//:node_bin does not resolve to the correct path in repository_rule #3809

Open
allsey87 opened this issue Dec 14, 2024 · 0 comments
Labels

Comments

@allsey87
Copy link

allsey87 commented Dec 14, 2024

What happened?

The label @nodejs//:node_bin does not resolve to the correct path to the Node.js binary when used inside of repository_rule. The path I get is:

external/rules_nodejs~~node~nodejs/node_bin

While the correct path (on my system) should be:

external/rules_nodejs~~node~nodejs_linux_amd64/bin/nodejs/bin/node

Version

Development (host) and target OS/architectures:

x86_64 GNU/Linux

Output of bazel --version:

bazel 7.2.1

Version of rules_nodejs, or other relevant rules from your WORKSPACE or MODULE.bazel file:

6.3.2

Language(s) and/or frameworks involved:

None

How to reproduce

I have created a template repository that can be opened in Github Codespaces here (just click the "Use this template" and "Open in a codespace" buttons): https://github.com/allsey87/nodejs_bazel_mre

Once the Codespace has been built, run: bazel build //:repository_nodejs and note the incorrect path printed inside of bazel-bin/repository_nodejs.txt.

Alternatively, these three files make up the same MRE of the problem:

MODULE.bazel

bazel_dep(name = "rules_nodejs", version = "6.3.2")

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version = "20.14.0")
use_repo(node, "nodejs", "nodejs_toolchains")

test_repository = use_repo_rule("//:repository.bzl", "test_repository")
test_repository(name = "repository_nodejs")

repository.bzl

def _test_repository_impl(ctx):
    ctx.file(".config", "{}".format(ctx.path(ctx.attr._nodejs)))
    ctx.file("BUILD.bazel", """
filegroup(
    name = "config",
    srcs = [".config"],
    visibility = ["//visibility:public"],
)
""")

test_repository = repository_rule(
    _test_repository_impl,
    attrs = {
        "_nodejs": attr.label(
            default = Label("@nodejs//:node_bin"),
            executable = True,
            cfg = "exec"
        )
    }
)

BUILD.bazel

# This rule does not result in nodejs being fetched and gives us an absolute path that ends with:
# external/rules_nodejs~~node~nodejs/node_bin (incorrect)
# The correct path should be:
# external/rules_nodejs~~node~nodejs_linux_amd64/bin/nodejs/bin/node
genrule(
    name = "repository_nodejs",
    outs = ["repository_nodejs.txt"],
    cmd = "cat $(execpath @repository_nodejs//:config) >> $(OUTS)",
    tools = [
        "@repository_nodejs//:config"
    ]
)
@allsey87 allsey87 added the bug label Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant