Closed gregmagolan closed 3 months ago
Fixes https://github.com/aspect-build/rules_js/issues/1530.
Related to https://github.com/bazelbuild/bazel/issues/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 https://github.com/aspect-build/rules_js/issues/1530.
:<PLATFORM>_toolchain_target
target_compatible_with
:<PLATFORM>_toolchain
exec_compatible_with
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", )
Fixes https://github.com/aspect-build/rules_js/issues/1530.
Related to https://github.com/bazelbuild/bazel/issues/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 definestarget_compatible_with
) should be registered before:<PLATFORM>_toolchain
(which definesexec_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 https://github.com/aspect-build/rules_js/issues/1530.