Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions nodejs/private/nodejs_toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,27 @@ resolved_toolchain(name = "resolved_toolchain", visibility = ["//visibility:publ

for [platform, meta] in PLATFORMS.items():
build_content += """
# Toolchain resolution is quite complex when it has to choose between both target and exec platform.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this comment be in the generated code like this or outside? Should it be repeated for each platform like it is atm?

Copy link
Author

@guw guw Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would you like to put it? I can move it outside.

# When building any target it has both exec and target platform set.
# On the other hand the toolchain resolution tries to find the first one that matches. The order is lexicographical
# based on native.toolchain's name.
# This means that when you build a target for linux-arm64 on linux-amd64
# toolchain resolution would match following toolchains:
# toolchain(name=linux-amd64, exec_compatible_with==linux-amd64)
# toolchain(name=linux-arm64, target_compatible_with=linux-arm64)
# and "linux-amd64" would be chosen as the first one lexicographically.
# Such result would lead to issues for cross platform builds, for example amd64 choosing wrongling for arm64 target.
# To circumvent this, we define 2 types of toolchains:
# - target toolchain that matches target platform constraint (but doesn't bother about exec).
# - exec toolchain that must match both exec and target platform.
# As a result, targets that have target platform different from exec platform will only be able to pick
# target toolchains.
# On the other hand we assume that if one wants to execute the rule, target platform should match exec platform.
# In such cases it doesn't matter whether the target or exec toolchain is picked.
toolchain(
name = "{platform}_toolchain",
exec_compatible_with = {compatible_with},
target_compatible_with = {compatible_with},
toolchain = "@{user_node_repository_name}_{platform}//:toolchain",
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
)
Expand Down