diff --git a/internal/common/os_name.bzl b/internal/common/os_name.bzl index 586d98b397..1ae71c8d88 100644 --- a/internal/common/os_name.bzl +++ b/internal/common/os_name.bzl @@ -16,8 +16,9 @@ """ OS_ARCH_NAMES = [ - ("darwin", "amd64"), ("windows", "amd64"), + ("darwin", "amd64"), + ("darwin", "arm64"), ("linux", "amd64"), ("linux", "arm64"), ("linux", "s390x"), @@ -35,28 +36,33 @@ def os_name(rctx): A string describing the os for a repository rule """ os_name = rctx.os.name.lower() - if os_name.startswith("mac os"): + if os_name.find("windows") != -1: return OS_NAMES[0] - elif os_name.find("windows") != -1: - return OS_NAMES[1] + + # This is not ideal, but bazel doesn't directly expose arch. + arch = rctx.execute(["uname", "-m"]).stdout.strip() + if os_name.startswith("mac os"): + if arch == "x86_64": + return OS_NAMES[1] + elif arch == "arm64": + return OS_NAMES[2] elif os_name.startswith("linux"): - # This is not ideal, but bazel doesn't directly expose arch. - arch = rctx.execute(["uname", "-m"]).stdout.strip() - if arch == "aarch64": + if arch == "x86_64": return OS_NAMES[3] - elif arch == "s390x": + elif arch == "aarch64": return OS_NAMES[4] - else: - return OS_NAMES[2] - else: - fail("Unsupported operating system: " + os_name) + elif arch == "s390x": + return OS_NAMES[5] -def is_darwin_os(rctx): - return os_name(rctx) == OS_NAMES[0] + fail("Unsupported operating system {} architecture {}".format(os_name, arch)) def is_windows_os(rctx): - return os_name(rctx) == OS_NAMES[1] + return os_name(rctx) == OS_NAMES[0] + +def is_darwin_os(rctx): + name = os_name(rctx) + return name == OS_NAMES[1] or name == OS_NAMES[2] def is_linux_os(rctx): name = os_name(rctx) - return name == OS_NAMES[2] or name == OS_NAMES[3] or name == OS_NAMES[4] + return name == OS_NAMES[3] or name == OS_NAMES[4] or name == OS_NAMES[5] diff --git a/internal/node/node_repositories.bzl b/internal/node/node_repositories.bzl index f0910883c8..57a00e2fc5 100644 --- a/internal/node/node_repositories.bzl +++ b/internal/node/node_repositories.bzl @@ -24,6 +24,8 @@ load("//internal/node:node_versions.bzl", "NODE_VERSIONS") load("//third_party/github.com/bazelbuild/bazel-skylib:lib/paths.bzl", "paths") load("//toolchains/node:node_toolchain_configure.bzl", "node_toolchain_configure") +_DEFAULT_NODE_VERSION = "12.13.0" + # @unsorted-dict-items _YARN_VERSIONS = { "1.3.2": ("yarn-v1.3.2.tar.gz", "yarn-v1.3.2", "6cfe82e530ef0837212f13e45c1565ba53f5199eec2527b85ecbcd88bf26821d"), @@ -172,7 +174,7 @@ and `{filename}` with the matching entry from the `node_repositories` attribute. """, ), "node_version": attr.string( - default = "12.13.0", + default = _DEFAULT_NODE_VERSION, doc = "the specific version of NodeJS to install or, if vendored_node is specified, the vendored version of node", ), "package_json": attr.label_list( @@ -235,6 +237,7 @@ If this list is empty, we won't download yarn at all. BUILT_IN_NODE_PLATFORMS = [ "darwin_amd64", + "darwin_arm64", "linux_amd64", "linux_arm64", "windows_amd64", @@ -258,6 +261,15 @@ done SCRIPT_DIR="$(cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd)" """ +def _node_exists_for_platform(node_version, os_name): + "Whether a node binary is available for this platform" + if not node_version: + node_version = _DEFAULT_NODE_VERSION + node_major_version = int(node_version.split(".")[0]) + + # There is no Apple Silicon native version of node before 16 + return node_major_version >= 16 or os_name != "darwin_arm64" + def _download_node(repository_ctx): """Used to download a NodeJS runtime package. @@ -276,6 +288,8 @@ def _download_node(repository_ctx): host_os = repository_ctx.name.split("nodejs_", 1)[1] node_version = repository_ctx.attr.node_version + if not _node_exists_for_platform(node_version, host_os): + return node_repositories = repository_ctx.attr.node_repositories # We insert our default value here, not on the attribute's default, so it isn't documented. @@ -755,7 +769,8 @@ def node_repositories(**kwargs): Also register bazel toolchains, and make other convenience repositories. - Note, the documentation is generated from the node_repositories_rule, not this macro. + Args: + **kwargs: the documentation is generated from the node_repositories_rule, not this macro. """ # 0.14.0: @bazel_tools//tools/bash/runfiles is required for nodejs @@ -772,6 +787,8 @@ def node_repositories(**kwargs): # This needs to be setup so toolchains can access nodejs for all different versions for os_arch_name in OS_ARCH_NAMES: os_name = "_".join(os_arch_name) + if not _node_exists_for_platform(kwargs.get("node_version"), os_name): + continue node_repository_name = "nodejs_%s" % os_name _maybe( node_repositories_rule,