Skip to content

Commit 708d1ec

Browse files
committed
Introduce runtime_toolchain_type
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
1 parent 66ce22f commit 708d1ec

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

docs/Toolchains.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
API docs for [Toolchain](https://docs.bazel.build/versions/main/toolchains.html) support.
44

55
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.
616

717
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.
818

@@ -13,9 +23,9 @@ To run a custom toolchain (i.e., to run a node binary not supported by the built
1323
1) A rule which can build or load a node binary from your repository
1424
(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).
1525
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.
1929
4) A call to [the `register_toolchains` function](https://bazel.build/rules/lib/globals#register_toolchains) in your `WORKSPACE`
2030
that refers to the `toolchain` rule defined in step 3.
2131

0 commit comments

Comments
 (0)