diff --git a/BUILD.bazel b/BUILD.bazel index 7ffb4f3978..ca3ddaed7d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -116,7 +116,6 @@ pkg_npm( "//third_party/npm/node_modules/named-amd:package_contents", "//toolchains/cypress:package_contents", "//toolchains/esbuild:package_contents", - "//toolchains/node:package_contents", ], ) diff --git a/docs/Toolchains.md b/docs/Toolchains.md index a9e3bd2e05..49ac02f637 100644 --- a/docs/Toolchains.md +++ b/docs/Toolchains.md @@ -52,76 +52,6 @@ Defaults to `""` Defaults to `None` -## node_toolchain - -**USAGE** - -
-node_toolchain(name, target_tool, target_tool_path)
-
- -Defines a node toolchain. - -For usage see https://docs.bazel.build/versions/main/toolchains.html#defining-toolchains. - - -**ATTRIBUTES** - - -

name

- -(*Name, mandatory*): A unique name for this target. - - -

target_tool

- -(*Label*): A hermetically downloaded nodejs executable target for the target platform. - -Defaults to `None` - -

target_tool_path

- -(*String*): Path to an existing nodejs executable for the target platform. - -Defaults to `""` - - -## node_toolchain_configure - -**USAGE** - -
-node_toolchain_configure(name, repo_mapping, target_tool, target_tool_path)
-
- -Creates an external repository with a node_toolchain //:toolchain target properly configured. - -**ATTRIBUTES** - - -

name

- -(*Name, mandatory*): A unique name for this repository. - - -

repo_mapping

- -(*Dictionary: String -> String, mandatory*): A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.

For example, an entry `"@foo": "@bar"` declares that, for any time this repository depends on `@foo` (such as a dependency on `@foo//some:target`, it should actually resolve that dependency within globally-declared `@bar` (`@bar//some:target`). - - -

target_tool

- -(*Label*): Target for a downloaded nodejs binary for the target os. - -Defaults to `None` - -

target_tool_path

- -(*String*): Absolute path to a pre-installed nodejs binary for the target os. - -Defaults to `""` - - ## configure_esbuild_toolchains **USAGE** diff --git a/e2e/nodejs_image/BUILD.bazel b/e2e/nodejs_image/BUILD.bazel index f15e5c4dc3..714691a198 100644 --- a/e2e/nodejs_image/BUILD.bazel +++ b/e2e/nodejs_image/BUILD.bazel @@ -12,7 +12,7 @@ nodejs_binary( entry_point = "main.js", ) -# bazel run --platforms=@build_bazel_rules_nodejs//toolchains/node:linux_amd64 //:nodejs_image +# bazel run --platforms=@rules_nodejs//:linux_amd64 //:nodejs_image nodejs_image( name = "nodejs_image", binary = ":main", diff --git a/internal/node/BUILD.bazel b/internal/node/BUILD.bazel index 30d499e081..5add4d5653 100644 --- a/internal/node/BUILD.bazel +++ b/internal/node/BUILD.bazel @@ -31,7 +31,6 @@ bzl_library( "//internal/npm_install:bzl", "//nodejs:bzl", "//third_party/github.com/bazelbuild/bazel-skylib:bzl", - "//toolchains/node:bzl", "@rules_nodejs//nodejs:bzl", ], ) diff --git a/internal/node/node_repositories.bzl b/internal/node/node_repositories.bzl index 0a6c72ef37..3ae7b0ef80 100644 --- a/internal/node/node_repositories.bzl +++ b/internal/node/node_repositories.bzl @@ -22,7 +22,6 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("//internal/common:check_bazel_version.bzl", "check_bazel_version") load("//nodejs/private:os_name.bzl", "OS_ARCH_NAMES", "node_exists_for_os", "os_name") load("//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", node_repositories_rule = "node_repositories") -load("//toolchains/node:node_toolchain_configure.bzl", "node_toolchain_configure") load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains") def node_repositories(**kwargs): @@ -57,12 +56,6 @@ def node_repositories(**kwargs): name = node_repository_name, **kwargs ) - target_tool = "@%s//:node_bin" % node_repository_name - native.register_toolchains("@build_bazel_rules_nodejs//toolchains/node:node_%s_toolchain" % os_name) - node_toolchain_configure( - name = "%s_config" % node_repository_name, - target_tool = target_tool, - ) # Install new toolchain under "nodejs" repository name prefix nodejs_register_toolchains(name = "nodejs") diff --git a/internal/node/test/nodejs_toolchain_test.bzl b/internal/node/test/nodejs_toolchain_test.bzl index cfa55b3af4..5d30bce762 100644 --- a/internal/node/test/nodejs_toolchain_test.bzl +++ b/internal/node/test/nodejs_toolchain_test.bzl @@ -16,7 +16,7 @@ This test verifies that if --platforms=@rules_nodejs//nodejs: is set then the correct node path is available to rules via -ctx.toolchains["@build_bazel_rules_nodejs//toolchains/node:toolchain_type"].nodeinfo.tool_files[0].path +ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo.tool_files[0].path """ load("//nodejs:repositories.bzl", "NODE_EXTRACT_DIR") @@ -46,7 +46,7 @@ def _nodejs_toolchain_test(ctx): script, _SCRIPT_TEMPLATE.format( expected_node_path = expected_node_path, - toolchain_node_path = ctx.toolchains["@build_bazel_rules_nodejs//toolchains/node:toolchain_type"].nodeinfo.tool_files[0].path, + toolchain_node_path = ctx.toolchains["@rules_nodejs//nodejs:toolchain_type"].nodeinfo.tool_files[0].path, ), is_executable = True, ) @@ -57,7 +57,7 @@ nodejs_toolchain_test = rule( attrs = _ATTRS, test = True, toolchains = [ - "@build_bazel_rules_nodejs//toolchains/node:toolchain_type", + "@rules_nodejs//nodejs:toolchain_type", "@bazel_tools//tools/sh:toolchain_type", ], ) diff --git a/toolchains/BUILD.bazel b/toolchains/BUILD.bazel index 962a2a991a..08747a20c9 100644 --- a/toolchains/BUILD.bazel +++ b/toolchains/BUILD.bazel @@ -9,6 +9,5 @@ stardoc( deps = [ "//toolchains/cypress:bzl", "//toolchains/esbuild:bzl", - "//toolchains/node:bzl", ], ) diff --git a/toolchains/index.for_docs.bzl b/toolchains/index.for_docs.bzl index b271eaf37e..9e55f67951 100644 --- a/toolchains/index.for_docs.bzl +++ b/toolchains/index.for_docs.bzl @@ -10,12 +10,8 @@ load("//toolchains/cypress:cypress_repositories.bzl", _cypress_repositories = "c load("//toolchains/cypress:cypress_toolchain.bzl", _cypress_toolchain = "cypress_toolchain") load("//toolchains/esbuild:esbuild_repositories.bzl", _esbuild_repositories = "esbuild_repositories") load("//toolchains/esbuild:toolchain.bzl", _configure_esbuild_toolchains = "configure_esbuild_toolchains") -load("//toolchains/node:node_toolchain_configure.bzl", _node_toolchain_configure = "node_toolchain_configure") -load("//toolchains/node:node_toolchain.bzl", _node_toolchain = "node_toolchain") cypress_repositories = _cypress_repositories cypress_toolchain = _cypress_toolchain esbuild_repositories = _esbuild_repositories configure_esbuild_toolchains = _configure_esbuild_toolchains -node_toolchain_configure = _node_toolchain_configure -node_toolchain = _node_toolchain diff --git a/toolchains/node/BUILD.bazel b/toolchains/node/BUILD.bazel deleted file mode 100644 index 300d40bd98..0000000000 --- a/toolchains/node/BUILD.bazel +++ /dev/null @@ -1,139 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -package(default_visibility = ["//visibility:private"]) - -licenses(["notice"]) # Apache 2.0 - -bzl_library( - name = "bzl", - srcs = glob(["*.bzl"]), - visibility = ["//visibility:public"], -) - -filegroup( - name = "package_contents", - srcs = glob(["*"]), - visibility = ["//:__pkg__"], -) - -# node toolchain type -toolchain_type( - name = "toolchain_type", - visibility = ["//visibility:public"], -) - -# Allow targets to use a toolchains attribute, such as sh_binary and genrule -# This way they can reference the NODE_PATH make variable. -alias( - name = "toolchain", - actual = select({ - "@bazel_tools//src/conditions:darwin_arm64": "@nodejs_darwin_arm64_config//:toolchain", - "@bazel_tools//src/conditions:darwin_x86_64": "@nodejs_darwin_amd64_config//:toolchain", - "@bazel_tools//src/conditions:linux_aarch64": "@nodejs_linux_arm64_config//:toolchain", - "@bazel_tools//src/conditions:linux_s390x": "@nodejs_linux_s390x_config//:toolchain", - "@bazel_tools//src/conditions:linux_x86_64": "@nodejs_linux_amd64_config//:toolchain", - "@bazel_tools//src/conditions:windows": "@nodejs_windows_amd64_config//:toolchain", - "@bazel_tools//src/conditions:linux_ppc64le": "@nodejs_linux_ppc64le_config//:toolchain", - "//conditions:default": "@nodejs_linux_amd64_config//:toolchain", - }), - visibility = ["//visibility:public"], -) - -# Allow targets to declare a dependency on the node binary for the current host platform -alias( - name = "node_bin", - actual = select({ - "@bazel_tools//src/conditions:darwin_arm64": "@nodejs_darwin_arm64//:node_bin", - "@bazel_tools//src/conditions:darwin_x86_64": "@nodejs_darwin_amd64//:node_bin", - "@bazel_tools//src/conditions:linux_aarch64": "@nodejs_linux_arm64//:node_bin", - "@bazel_tools//src/conditions:linux_s390x": "@nodejs_linux_s390x//:node_bin", - "@bazel_tools//src/conditions:linux_x86_64": "@nodejs_linux_amd64//:node_bin", - "@bazel_tools//src/conditions:linux_ppc64le": "@nodejs_linux_ppc64le//:node_bin", - "@bazel_tools//src/conditions:windows": "@nodejs_windows_amd64//:node_bin", - "//conditions:default": "@nodejs_linux_amd64//:node_bin", - }), - visibility = ["//visibility:public"], -) - -toolchain( - name = "node_linux_amd64_toolchain", - target_compatible_with = [ - "@platforms//os:linux", - "@platforms//cpu:x86_64", - ], - toolchain = "@nodejs_linux_amd64_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_linux_arm64_toolchain", - target_compatible_with = [ - "@platforms//os:linux", - "@platforms//cpu:aarch64", - ], - toolchain = "@nodejs_linux_arm64_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_darwin_amd64_toolchain", - target_compatible_with = [ - "@platforms//os:osx", - "@platforms//cpu:x86_64", - ], - toolchain = "@nodejs_darwin_amd64_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_darwin_arm64_toolchain", - target_compatible_with = [ - "@platforms//os:osx", - "@platforms//cpu:aarch64", - ], - toolchain = "@nodejs_darwin_arm64_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_windows_amd64_toolchain", - target_compatible_with = [ - "@platforms//os:windows", - "@platforms//cpu:x86_64", - ], - toolchain = "@nodejs_windows_amd64_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_linux_s390x_toolchain", - target_compatible_with = [ - "@platforms//os:linux", - "@platforms//cpu:s390x", - ], - toolchain = "@nodejs_linux_s390x_config//:toolchain", - toolchain_type = ":toolchain_type", -) - -toolchain( - name = "node_linux_ppc64le_toolchain", - target_compatible_with = [ - "@platforms//os:linux", - "@platforms//cpu:ppc", - ], - toolchain = "@nodejs_linux_ppc64le_config//:toolchain", - toolchain_type = ":toolchain_type", -) diff --git a/toolchains/node/BUILD.tpl b/toolchains/node/BUILD.tpl deleted file mode 100644 index 909fd9ece2..0000000000 --- a/toolchains/node/BUILD.tpl +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""This BUILD file is auto-generated from toolchains/node/BUILD.tpl -""" - -package(default_visibility = ["//visibility:public"]) - -load("@build_bazel_rules_nodejs//toolchains/node:node_toolchain.bzl", "node_toolchain") - -node_toolchain( - name = "toolchain", -%{TOOL_ATTRS} -) diff --git a/toolchains/node/node_toolchain.bzl b/toolchains/node/node_toolchain.bzl deleted file mode 100644 index 09034ce40e..0000000000 --- a/toolchains/node/node_toolchain.bzl +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""This module implements the node toolchain rule. -""" - -NodeInfo = provider( - doc = "Information about how to invoke the node executable.", - fields = { - "target_tool_path": "Path to the nodejs executable for the target platform.", - "tool_files": """Files required in runfiles to make the nodejs executable available. - -May be empty if the target_tool_path points to a locally installed node binary.""", - }, -) - -# Avoid using non-normalized paths (workspace/../other_workspace/path) -def _to_manifest_path(ctx, file): - if file.short_path.startswith("../"): - return file.short_path[3:] - else: - return ctx.workspace_name + "/" + file.short_path - -def _node_toolchain_impl(ctx): - if ctx.attr.target_tool and ctx.attr.target_tool_path: - fail("Can only set one of target_tool or target_tool_path but both were set.") - if not ctx.attr.target_tool and not ctx.attr.target_tool_path: - fail("Must set one of target_tool or target_tool_path.") - - tool_files = [] - target_tool_path = ctx.attr.target_tool_path - - if ctx.attr.target_tool: - tool_files = ctx.attr.target_tool.files.to_list() - target_tool_path = _to_manifest_path(ctx, tool_files[0]) - - return [ - platform_common.ToolchainInfo( - nodeinfo = NodeInfo( - target_tool_path = target_tool_path, - tool_files = tool_files, - ), - ), - # Make the $(NODE_PATH) variable available in places like genrules. - # See https://docs.bazel.build/versions/main/be/make-variables.html#custom_variables - platform_common.TemplateVariableInfo({ - "NODE_PATH": target_tool_path, - }), - ] - -node_toolchain = rule( - implementation = _node_toolchain_impl, - attrs = { - "target_tool": attr.label( - doc = "A hermetically downloaded nodejs executable target for the target platform.", - mandatory = False, - allow_single_file = True, - ), - "target_tool_path": attr.string( - doc = "Path to an existing nodejs executable for the target platform.", - mandatory = False, - ), - }, - doc = """Defines a node toolchain. - -For usage see https://docs.bazel.build/versions/main/toolchains.html#defining-toolchains. -""", -) diff --git a/toolchains/node/node_toolchain_configure.bzl b/toolchains/node/node_toolchain_configure.bzl deleted file mode 100644 index 870f17f803..0000000000 --- a/toolchains/node/node_toolchain_configure.bzl +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Defines a repository rule for configuring the node executable. -""" - -def _impl(repository_ctx): - if repository_ctx.attr.target_tool and repository_ctx.attr.target_tool_path: - fail("Can only set one of target_tool or target_tool_path but both where set.") - - if repository_ctx.attr.target_tool: - substitutions = {"%{TOOL_ATTRS}": " target_tool = \"%s\"\n" % repository_ctx.attr.target_tool} - else: - if repository_ctx.attr.target_tool_path: - default_tool_path = repository_ctx.attr.target_tool_path - else: - default_tool_path = repository_ctx.which("node") - if not default_tool_path: - fail("No node found on local path. node must available on the PATH or target_tool_path must be provided") - substitutions = {"%{TOOL_ATTRS}": " target_tool_path = \"%s\"\n" % default_tool_path} - - repository_ctx.template( - "BUILD", - Label("@build_bazel_rules_nodejs//toolchains/node:BUILD.tpl"), - substitutions, - False, - ) - -node_toolchain_configure = repository_rule( - implementation = _impl, - attrs = { - "target_tool": attr.label( - doc = "Target for a downloaded nodejs binary for the target os.", - mandatory = False, - allow_single_file = True, - ), - "target_tool_path": attr.string( - doc = "Absolute path to a pre-installed nodejs binary for the target os.", - mandatory = False, - ), - }, - doc = """Creates an external repository with a node_toolchain //:toolchain target properly configured.""", -)