Skip to content

Commit 72f5f23

Browse files
guwalexeagle
authored andcommitted
Address PR feedback, drop host runtime
1 parent afa293a commit 72f5f23

File tree

5 files changed

+20
-49
lines changed

5 files changed

+20
-49
lines changed

e2e/smoke/defs.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def _my_nodejs_impl(ctx):
44
if ctx.attr.toolchain:
55
nodeinfo = ctx.attr.toolchain[platform_common.ToolchainInfo].nodeinfo
66
else:
7-
nodeinfo = ctx.toolchains["@rules_nodejs//nodejs:runtime_toolchain_type"].nodeinfo
7+
nodeinfo = ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo
88
ctx.actions.run(
99
inputs = [ctx.file.entry_point],
1010
executable = nodeinfo.node,
@@ -20,5 +20,5 @@ my_nodejs = rule(
2020
"out": attr.output(),
2121
"toolchain": attr.label(),
2222
},
23-
toolchains = ["@rules_nodejs//nodejs:runtime_toolchain_type"],
23+
toolchains = ["@rules_nodejs//nodejs:toolchain_type"],
2424
)

nodejs/BUILD.bazel

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
load("@bazel_lib//:bzl_library.bzl", "bzl_library")
33
load("//nodejs/private:nodejs_toolchains_repo.bzl", "PLATFORMS")
44
load("//nodejs/private:user_build_settings.bzl", "user_args")
5-
load(":node_toolchain_alias.bzl", "node_host_runtime_alias", "node_runtime_alias", "node_toolchain_alias")
5+
load(":node_toolchain_alias.bzl", "node_runtime_alias", "node_toolchain_alias")
66

77
package(default_visibility = ["//visibility:public"])
88

@@ -55,12 +55,11 @@ toolchain_type(name = "toolchain_type")
5555
toolchain_type(name = "runtime_toolchain_type")
5656

5757
# Points to toolchain[":runtime_toolchain_type"]
58+
# Use this for executing and packaging Node applications for target platform (eg., js_binary, js_test or js_image_oci).
5859
node_runtime_alias(name = "current_node_runtime")
5960

60-
# Host configuration of ":current_node_runtime"
61-
node_host_runtime_alias(name = "current_host_node_runtime")
62-
6361
# Points to toolchain[":toolchain_type"]
62+
# Use this for tools (eg., when action execution is needed).
6463
node_toolchain_alias(name = "current_node_toolchain")
6564

6665
# The platforms that are supported by the Node toolchains.

nodejs/node_toolchain_alias.bzl

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"""Node toolchain aliases using toolchain resolution."""
1616

1717
load(":semantics.bzl", "semantics")
18-
load(":toolchain.bzl", "NodeInfo")
1918

2019
def _node_runtime_alias(ctx):
2120
"""Implementation of node_runtime_alias using toolchain resolution."""
@@ -35,47 +34,17 @@ node_runtime_alias = rule(
3534
toolchains = [semantics.NODE_RUNTIME_TOOLCHAIN],
3635
)
3736

38-
def _node_host_runtime_alias(ctx):
39-
"""Implementation of node_host_runtime_alias using toolchain resolution."""
40-
runtime = ctx.attr._runtime
41-
toolchain = runtime[NodeInfo]
42-
template_variable_info = runtime[platform_common.TemplateVariableInfo]
43-
default_info = runtime[DefaultInfo]
44-
toolchain_info = platform_common.ToolchainInfo(nodeinfo = toolchain)
45-
return [
46-
toolchain,
47-
template_variable_info,
48-
toolchain_info,
49-
default_info,
50-
]
51-
52-
node_host_runtime_alias = rule(
53-
implementation = _node_host_runtime_alias,
54-
attrs = {
55-
"_runtime": attr.label(
56-
default = Label("//nodejs:current_node_runtime"),
57-
providers = [
58-
NodeInfo,
59-
platform_common.TemplateVariableInfo,
60-
],
61-
cfg = "exec",
62-
),
63-
},
64-
provides = [
65-
NodeInfo,
66-
platform_common.TemplateVariableInfo,
67-
platform_common.ToolchainInfo,
68-
],
69-
)
70-
7137
def _node_toolchain_alias(ctx):
7238
"""An implementation of node_toolchain_alias using toolchain resolution."""
7339
toolchain_info = ctx.toolchains[semantics.NODE_TOOLCHAIN_TYPE]
7440
toolchain = toolchain_info.nodeinfo
75-
41+
template_variable_info = toolchain_info.template_variables
42+
default_info = toolchain_info.default
7643
return [
7744
toolchain_info,
7845
toolchain,
46+
template_variable_info,
47+
default_info,
7948
]
8049

8150
node_toolchain_alias = rule(

nodejs/private/nodejs_toolchains_repo.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ See https://github.com/bazel-contrib/rules_nodejs/issues/3795.
9696
toolchain(
9797
name = "{platform}_toolchain",
9898
exec_compatible_with = {compatible_with},
99-
target_compatible_with = {compatible_with}, # https://github.com/bazel-contrib/rules_nodejs/issues/3854
99+
target_compatible_with = {compatible_with}, # prevent Node from this toolchain being bundled by js_image_oci to incompatible target platforms (https://github.com/bazel-contrib/rules_nodejs/issues/3854)
100100
toolchain = "@{user_node_repository_name}_{platform}//:toolchain",
101101
toolchain_type = "@rules_nodejs//nodejs:toolchain_type",
102102
)

nodejs/semantics.bzl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@
1313
# limitations under the License.
1414
"""Rules NodeJS Semantics"""
1515

16+
_NODE_TOOLCHAIN_TYPE = Label("//nodejs:toolchain_type")
17+
_NODE_RUNTIME_TOOLCHAIN_TYPE = Label("//nodejs:runtime_toolchain_type")
18+
1619
def _find_node_toolchain(ctx):
17-
return ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo
20+
return ctx.toolchains[_NODE_TOOLCHAIN_TYPE].nodeinfo
1821

1922
def _find_node_runtime_toolchain(ctx):
20-
return ctx.toolchains["@rules_nodejs//nodejs:runtime_toolchain_type"].nodeinfo
23+
return ctx.toolchains[_NODE_RUNTIME_TOOLCHAIN_TYPE].nodeinfo
2124

2225
semantics = struct(
23-
NODE_TOOLCHAIN_LABEL = "@rules_nodejs//nodejs:current_node_toolchain",
24-
NODE_TOOLCHAIN_TYPE = "@rules_nodejs//nodejs:toolchain_type",
25-
NODE_TOOLCHAIN = config_common.toolchain_type("@rules_nodejs//nodejs:toolchain_type", mandatory = True),
26+
NODE_TOOLCHAIN_LABEL = Label("//nodejs:current_node_toolchain"),
27+
NODE_TOOLCHAIN_TYPE = _NODE_TOOLCHAIN_TYPE,
28+
NODE_TOOLCHAIN = config_common.toolchain_type(_NODE_TOOLCHAIN_TYPE, mandatory = True),
2629
find_node_toolchain = _find_node_toolchain,
27-
NODE_RUNTIME_TOOLCHAIN_TYPE = "@rules_nodejs//nodejs:runtime_toolchain_type",
28-
NODE_RUNTIME_TOOLCHAIN = config_common.toolchain_type("@rules_nodejs//nodejs:runtime_toolchain_type", mandatory = True),
30+
NODE_RUNTIME_TOOLCHAIN_TYPE = _NODE_RUNTIME_TOOLCHAIN_TYPE,
31+
NODE_RUNTIME_TOOLCHAIN = config_common.toolchain_type(_NODE_RUNTIME_TOOLCHAIN_TYPE, mandatory = True),
2932
find_node_runtime_toolchain = _find_node_runtime_toolchain,
3033
)

0 commit comments

Comments
 (0)