Skip to content

fix: register Node.js toolchains in correct order#3750

Merged
gregmagolan merged 1 commit intomainfrom
toolchain_ordering
Jun 6, 2024
Merged

fix: register Node.js toolchains in correct order#3750
gregmagolan merged 1 commit intomainfrom
toolchain_ordering

Conversation

@gregmagolan
Copy link
Copy Markdown
Collaborator

@gregmagolan gregmagolan commented Jun 6, 2024

Fixes aspect-build/rules_js#1530.

Related to bazelbuild/bazel#19645.

Toolchain registration ordering matters since it affects which toolchain Bazel resolves. This PR makes the bzlmod registration match the registration order in WORKSPACE.

In particular, the :<PLATFORM>_toolchain_target (which defines target_compatible_with) should be registered before :<PLATFORM>_toolchain (which defines exec_compatible_with) for each platform. In WORKSPACE this is done here: https://github.com/bazelbuild/rules_nodejs/blob/4c373209b058d46f2a5f9ab9f8abf11b161ae459/nodejs/repositories.bzl#L461/. This is important so that Bazel selects the target compatible toolchain before it selects the execution compatible toolchain. The opposite ordering causes the issue seen in aspect-build/rules_js#1530.

toolchain(
  name = "linux_amd64_toolchain_target",
  toolchain_type = "//nodejs:toolchain_type",
  target_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
  toolchain = "@@_main~node~nodejs_linux_amd64//:toolchain",
)
toolchain(
  name = "linux_amd64_toolchain",
  toolchain_type = "//nodejs:toolchain_type",
  exec_compatible_with = ["@platforms//os:linux", "@platforms//cpu:x86_64"],
  toolchain = "@@_main~node~nodejs_linux_amd64//:toolchain",
)

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.

[Bug]: js_image_layer is broken with bzlmod

2 participants