diff --git a/docs/Toolchains.md b/docs/Toolchains.md index 33170fd077..b7626f7eca 100644 --- a/docs/Toolchains.md +++ b/docs/Toolchains.md @@ -10,7 +10,7 @@ API docs for [Toolchain](https://docs.bazel.build/versions/main/toolchains.html) When you call `nodejs_register_toolchains()` in your `WORKSPACE` file it will setup a node toolchain for executing tools on all currently supported platforms. -If you have an advanced use-case you can also register your own toolchains. See [node_toolchain](./Core.md#node_toolchain) +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. ## Node.js binary for the target platform @@ -34,10 +34,24 @@ The workaround is to perform the npm_install inside a docker container so that i Follow https://github.com/bazelbuild/rules_nodejs/issues/506 for updates on support for node-gyp cross-compilation. -## node_toolchain +## Registering a custom toolchain -See <./Core.md#node_toolchain> +To run a custom toolchain (i.e., to run a node binary not supported by the built-in toolchains), you'll need four things: +1) A rule which can build or load a node binary from your repository + (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). +2) A [`node_toolchain` rule](Core.html#node_toolchain) which depends on your binary defined in step 1 as its `target_tool`. +3) A [`toolchain` rule](https://bazel.build/reference/be/platform#toolchain) that depends on your `node_toolchain` rule defined in step 2 as its `toolchain` + and on `@rules_nodejs//nodejs:toolchain_type` as its `toolchain_type`. Make sure to define appropriate platform restrictions as described in the + documentation for the `toolchain` rule. +4) A call to [the `register_toolchains` function](https://bazel.build/rules/lib/globals#register_toolchains) in your `WORKSPACE` + that refers to the `toolchain` rule defined in step 3. + +Examples of steps 2-4 can be found in the [documentation for `node_toolchain`](Core.html#node_toolchain). + +If necessary, you can substitute building the node binary as part of the build with using a locally installed version by skipping step 1 and replacing step 2 with: + +2) A `node_toolchain` rule which has the path of the system binary as its `target_tool_path` ## cypress_toolchain diff --git a/toolchains/index.for_docs.bzl b/toolchains/index.for_docs.bzl index 56c2bec549..9c1e2a189b 100644 --- a/toolchains/index.for_docs.bzl +++ b/toolchains/index.for_docs.bzl @@ -4,7 +4,7 @@ API docs for [Toolchain](https://docs.bazel.build/versions/main/toolchains.html) When you call `nodejs_register_toolchains()` in your `WORKSPACE` file it will setup a node toolchain for executing tools on all currently supported platforms. -If you have an advanced use-case you can also register your own toolchains. See [node_toolchain](./Core.md#node_toolchain) +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. ## Node.js binary for the target platform @@ -28,10 +28,24 @@ The workaround is to perform the npm_install inside a docker container so that i Follow https://github.com/bazelbuild/rules_nodejs/issues/506 for updates on support for node-gyp cross-compilation. -## node_toolchain +## Registering a custom toolchain -See <./Core.md#node_toolchain> +To run a custom toolchain (i.e., to run a node binary not supported by the built-in toolchains), you'll need four things: +1) A rule which can build or load a node binary from your repository + (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). +2) A [`node_toolchain` rule](Core.html#node_toolchain) which depends on your binary defined in step 1 as its `target_tool`. +3) A [`toolchain` rule](https://bazel.build/reference/be/platform#toolchain) that depends on your `node_toolchain` rule defined in step 2 as its `toolchain` + and on `@rules_nodejs//nodejs:toolchain_type` as its `toolchain_type`. Make sure to define appropriate platform restrictions as described in the + documentation for the `toolchain` rule. +4) A call to [the `register_toolchains` function](https://bazel.build/rules/lib/globals#register_toolchains) in your `WORKSPACE` + that refers to the `toolchain` rule defined in step 3. + +Examples of steps 2-4 can be found in the [documentation for `node_toolchain`](Core.html#node_toolchain). + +If necessary, you can substitute building the node binary as part of the build with using a locally installed version by skipping step 1 and replacing step 2 with: + +2) A `node_toolchain` rule which has the path of the system binary as its `target_tool_path` """ load("//toolchains/cypress:cypress_repositories.bzl", _cypress_repositories = "cypress_repositories")