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

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

Merged
merged 1 commit into from
Jun 6, 2024

Conversation

gregmagolan
Copy link
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",
)

MODULE.bazel Show resolved Hide resolved
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