Skip to content

Commit

Permalink
fix: condition on target instead of exec (#3373)
Browse files Browse the repository at this point in the history
* fix: condition on target

* fix: introduce second toolchain that is conditioned on the target platform
  • Loading branch information
thesayyn authored Mar 29, 2022
1 parent 2e2267d commit 43159a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
38 changes: 22 additions & 16 deletions nodejs/private/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,46 @@ with only the toolchain attribute pointing into the platform-specific repositori
"""

PLATFORMS = {
"darwin_amd64": struct(
"linux_amd64": struct(
compatible_with = [
"@platforms//os:macos",
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
),
"darwin_arm64": struct(
"linux_arm64": struct(
compatible_with = [
"@platforms//os:macos",
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
),
"linux_amd64": struct(
"linux_s390x": struct(
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
"@platforms//cpu:s390x",
],
),
"linux_arm64": struct(
"linux_ppc64le": struct(
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:aarch64",
"@platforms//cpu:ppc",
],
),
"windows_amd64": struct(
"darwin_amd64": struct(
compatible_with = [
"@platforms//os:windows",
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
),
"linux_s390x": struct(
"darwin_arm64": struct(
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:s390x",
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
),
"linux_ppc64le": struct(
"windows_amd64": struct(
compatible_with = [
"@platforms//os:linux",
"@platforms//cpu:ppc",
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
),
}
Expand Down Expand Up @@ -108,6 +108,12 @@ toolchain(
toolchain = "@{user_node_repository_name}_{platform}//:node_toolchain",
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
)
toolchain(
name = "{platform}_toolchain_target",
target_compatible_with = {compatible_with},
toolchain = "@{user_node_repository_name}_{platform}//:node_toolchain",
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
)
""".format(
platform = platform,
name = repository_ctx.attr.name,
Expand Down
5 changes: 4 additions & 1 deletion nodejs/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,10 @@ def nodejs_register_toolchains(name, register = True, **kwargs):
**kwargs
)
if register:
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
native.register_toolchains(
"@%s_toolchains//:%s_toolchain_target" % (name, platform),
"@%s_toolchains//:%s_toolchain" % (name, platform),
)

nodejs_repo_host_os_alias(
name = name + "_host",
Expand Down

0 comments on commit 43159a5

Please sign in to comment.