You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to discussions in #3854 having two toolchains of the same type
for different things is troublesome. It's better to have separate
runtime as well as compile toolchains.
This commit creates a new runtime_toolchain_type and registers
toolchains without execution constraints for this type. Once merged,
rules_ts can start consuming the new toolchain type in its js_binary
rule to ensure the correct Node for the correct target environment is
selected.
Fixed [Bug]: Execution toolchain defined without
`target_compatible_with` makes it a candidate to selection
Fixes#3854
Work towards #3795
## PR Checklist
Please check if your PR fulfills the following requirements:
- [x] Tests for the changes have been added (for bug fixes / features)
- [x] Docs have been added / updated (for bug fixes / features)
## PR Type
What kind of change does this PR introduce?
<!-- Please check the one that applies to this PR using "x". -->
- [x] Bugfix
- [x] Feature (please, look at the "Scope of the project" section in the
README.md file)
- [x] Documentation content changes
## Does this PR introduce a breaking change?
- [ ] Yes
- [x] No
It tries to remain compatible and support existing consumers.
## Other information
This is an alternative to #3800.
# Toolchain registration under bzlmod should match the order of WORKSPACE registration
21
24
# which is the order specified in the PLATFORMS dict https://github.com/bazel-contrib/rules_nodejs/blob/4c373209b058d46f2a5f9ab9f8abf11b161ae459/nodejs/private/nodejs_toolchains_repo.bzl#L20.
22
-
# For each platform, `:<PLATFORM>_toolchain_target` should be registered before `:<PLATFORM>_toolchain`,
25
+
# For each platform, `:<PLATFORM>_runtime_toolchain` should be registered before `:<PLATFORM>_toolchain`,
Copy file name to clipboardExpand all lines: docs/Toolchains.md
+13-3Lines changed: 13 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,16 @@
3
3
API docs for [Toolchain](https://docs.bazel.build/versions/main/toolchains.html) support.
4
4
5
5
When you call `nodejs_register_toolchains()` in your `WORKSPACE` file it will setup a node toolchain for executing tools on all currently supported platforms.
6
+
In `bzlmod` default toolchains are registered automatically when you depend on `rules_nodejs`.
7
+
8
+
There are two toolchain types:
9
+
10
+
1) The transpilation toolchain, which provides the Node runtime used to execute the transpiler (and type checker), as well as various helper tools and settings.
11
+
(`@rules_nodejs//nodejs:toolchain_type`)
12
+
2) The Node runtime that executable Node outputs (e.g., js_binary) will run on.
13
+
(`@rules_nodejs//nodejs:runtime_toolchain_type`)
14
+
15
+
See [//nodjes/BUILD.bazel](https://github.com/bazel-contrib/rules_nodejs/blob/main/nodejs/BUILD.bazel) for details.
6
16
7
17
If you have an advanced use-case and want to use a version of node not supported by this repository, you can also register your own toolchains.
8
18
@@ -13,9 +23,9 @@ To run a custom toolchain (i.e., to run a node binary not supported by the built
13
23
1) A rule which can build or load a node binary from your repository
14
24
(a checked-in binary or a build using a relevant [`rules_foreign_cc` build rule](https://bazelbuild.github.io/rules_foreign_cc/) will do nicely).
15
25
2) A [`nodejs_toolchain` rule](Core.html#nodejs_toolchain) which depends on your binary defined in step 1 as its `node`.
16
-
3)A[`toolchain`rule](https://bazel.build/reference/be/platform#toolchain)that depends on your `nodejs_toolchain` rule defined in step 2 as its `toolchain`
17
-
and on `@rules_nodejs//nodejs:toolchain_type` as its `toolchain_type`. Make sure to define appropriate platform restrictions as described in the
18
-
documentation for the `toolchain` rule.
26
+
3)Two[`toolchain`rules](https://bazel.build/reference/be/platform#toolchain)each depends on your `nodejs_toolchain` rule defined in step 2 as its `toolchain`
27
+
and one on `@rules_nodejs//nodejs:toolchain_type` as its `toolchain_type` and the other one `@rules_nodejs//nodejs:runtime_toolchain_type`.
28
+
Make sure to define appropriate platform restrictions as described in the documentation for the `toolchain` rule.
19
29
4) A call to [the `register_toolchains` function](https://bazel.build/rules/lib/globals#register_toolchains) in your `WORKSPACE`
20
30
that refers to the `toolchain` rule defined in step 3.
actual = "@rules_nodejs//nodejs:current_node_runtime",
82
+
deprecation = """
83
+
Use one of the following instead:
84
+
- @rules_nodejs//nodejs:current_node_runtime
85
+
- @rules_nodejs//nodejs:current_host_node_runtime
86
+
- @rules_nodejs//nodejs:current_node_toolchain
87
+
See https://github.com/bazel-contrib/rules_nodejs/issues/3795.
88
+
""",
89
+
visibility = ["//visibility:public"],
90
+
)
105
91
106
-
"""
92
+
'''
107
93
108
94
for [platform, meta] inPLATFORMS.items():
109
95
build_content+="""
110
96
toolchain(
111
97
name = "{platform}_toolchain",
112
98
exec_compatible_with = {compatible_with},
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)
0 commit comments