Skip to content

[Bug]: Execution toolchain defined without target_compatible_with makes it a candidate to selection #3854

@guw

Description

@guw

What happened?

rules_nodejs registers two toolchains:

toolchain(
name = "{platform}_toolchain",
exec_compatible_with = {compatible_with},
toolchain = "@{user_node_repository_name}_{platform}//:toolchain",
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
)
toolchain(
name = "{platform}_toolchain_target",
target_compatible_with = {compatible_with},
toolchain = "@{user_node_repository_name}_{platform}//:toolchain",
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
)

One is for execution on the host (execution toolchain) and another one for cross-compilation. However, the execution toolchain is defined without target_compatible_with, which makes it applicable to all possible targets (no constraints). In our situation this leads to an issue where NodeJS Linux AMD64 is picked wrongly instead of Linux ARM64 when building multi-platform containers on AMD64 machine.

This issue appeared after migrating to bzlmod. In our pre-bzlmod WORKSPACE setup we manually registered NodeJS toolchains ourselves and the problem does not occur.

Version

Development (host) and target OS/architectures:

  • Host: Linux AMD64
  • Target: Linux ARM64
  • bzlmod

Output of bazel --version:

  • 7.6.1

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

  • 6.4.0

How to reproduce

  • needs a multi-platform oci image build with transitions to produce arm64 image on amd64 host

Any other information?

Note, the second target specific toolchains was introduced in #3373. It seems to rely purely on lexicographic ordering. I do wonder if this is the correct approach and if both toolchain definitions are needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions