From a02cf07833bbe1c4076c5598c505df6e1886a4c2 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 24 Jun 2024 16:59:16 +0200 Subject: [PATCH 1/2] Bazel: add `nodejs` mirror This patches `rules_nodejs` with the contents of https://github.com/bazelbuild/rules_nodejs/pull/3763 in order to allow specifying a mirror for nodejs, as nodejs.org has hit us with intermittent downtimes. --- MODULE.bazel | 6 +- .../rules_nodejs/6.2.0-codeql.1/MODULE.bazel | 51 ++++++++++++ .../patches/allow_node_urls.patch | 83 +++++++++++++++++++ .../patches/module_dot_bazel_version.patch | 14 ++++ .../rules_nodejs/6.2.0-codeql.1/presubmit.yml | 14 ++++ .../rules_nodejs/6.2.0-codeql.1/source.json | 10 +++ .../modules/rules_nodejs/metadata.json | 5 ++ 7 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/MODULE.bazel create mode 100644 misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/allow_node_urls.patch create mode 100644 misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/module_dot_bazel_version.patch create mode 100644 misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/presubmit.yml create mode 100644 misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/source.json create mode 100644 misc/bazel/registry/modules/rules_nodejs/metadata.json diff --git a/MODULE.bazel b/MODULE.bazel index 84879779c678..b0957b89a75c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -16,7 +16,7 @@ local_path_override( bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "rules_go", version = "0.48.0") bazel_dep(name = "rules_pkg", version = "0.10.1") -bazel_dep(name = "rules_nodejs", version = "6.2.0") +bazel_dep(name = "rules_nodejs", version = "6.2.0-codeql.1") bazel_dep(name = "rules_python", version = "0.32.2") bazel_dep(name = "bazel_skylib", version = "1.6.1") bazel_dep(name = "abseil-cpp", version = "20240116.0", repo_name = "absl") @@ -85,6 +85,10 @@ use_repo( node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node") node.toolchain( name = "nodejs", + node_urls = [ + "https://nodejs.org/dist/v{version}/{filename}", + "https://mirrors.dotsrc.org/nodejs/release/v{version}/{filename}", + ], node_version = "18.15.0", ) use_repo(node, "nodejs", "nodejs_toolchains") diff --git a/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/MODULE.bazel b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/MODULE.bazel new file mode 100644 index 000000000000..ffdcb6bf09e8 --- /dev/null +++ b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/MODULE.bazel @@ -0,0 +1,51 @@ +"bzlmod declaration for bazelbuild/rules_nodejs" + +module( + name = "rules_nodejs", + version = "6.2.0-codeql.1", + compatibility_level = 1, +) + +# Lower-bounds (minimum) versions for direct runtime dependencies +bazel_dep(name = "bazel_skylib", version = "1.4.1") +bazel_dep(name = "platforms", version = "0.0.5") + +node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node") + +# Note, this gets the default version of Node.js from +# https://github.com/bazelbuild/rules_nodejs/blob/main/nodejs/repositories.bzl#L11 +node.toolchain() +use_repo(node, "nodejs_toolchains") + +# Toolchain registration under bzlmod should match the order of WORKSPACE registration +# which is the order specified in the PLATFORMS dict https://github.com/bazelbuild/rules_nodejs/blob/4c373209b058d46f2a5f9ab9f8abf11b161ae459/nodejs/private/nodejs_toolchains_repo.bzl#L20. +# For each platform, `:_toolchain_target` should be registered before `:_toolchain`, +# https://github.com/bazelbuild/rules_nodejs/blob/4c373209b058d46f2a5f9ab9f8abf11b161ae459/nodejs/repositories.bzl#L461/. +# See https://github.com/bazelbuild/bazel/issues/19645 and https://github.com/bazelbuild/rules_nodejs/pull/3750 for more context. +register_toolchains("@nodejs_toolchains//:linux_amd64_toolchain_target") + +register_toolchains("@nodejs_toolchains//:linux_amd64_toolchain") + +register_toolchains("@nodejs_toolchains//:linux_arm64_toolchain_target") + +register_toolchains("@nodejs_toolchains//:linux_arm64_toolchain") + +register_toolchains("@nodejs_toolchains//:linux_s390x_toolchain_target") + +register_toolchains("@nodejs_toolchains//:linux_s390x_toolchain") + +register_toolchains("@nodejs_toolchains//:linux_ppc64le_toolchain_target") + +register_toolchains("@nodejs_toolchains//:linux_ppc64le_toolchain") + +register_toolchains("@nodejs_toolchains//:darwin_amd64_toolchain_target") + +register_toolchains("@nodejs_toolchains//:darwin_amd64_toolchain") + +register_toolchains("@nodejs_toolchains//:darwin_arm64_toolchain_target") + +register_toolchains("@nodejs_toolchains//:darwin_arm64_toolchain") + +register_toolchains("@nodejs_toolchains//:windows_amd64_toolchain_target") + +register_toolchains("@nodejs_toolchains//:windows_amd64_toolchain") diff --git a/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/allow_node_urls.patch b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/allow_node_urls.patch new file mode 100644 index 000000000000..47fb7a25bc8b --- /dev/null +++ b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/allow_node_urls.patch @@ -0,0 +1,83 @@ +diff --git a/nodejs/extensions.bzl b/nodejs/extensions.bzl +index 1de6f363..1d9d21f0 100644 +--- a/nodejs/extensions.bzl ++++ b/nodejs/extensions.bzl +@@ -1,6 +1,12 @@ + "extensions for bzlmod" + +-load(":repositories.bzl", "DEFAULT_NODE_REPOSITORY", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains") ++load( ++ ":repositories.bzl", ++ "DEFAULT_NODE_REPOSITORY", ++ "DEFAULT_NODE_URL", ++ "DEFAULT_NODE_VERSION", ++ "nodejs_register_toolchains", ++) + + def _toolchain_extension(module_ctx): + registrations = {} +@@ -8,33 +14,37 @@ def _toolchain_extension(module_ctx): + for toolchain in mod.tags.toolchain: + if toolchain.name != DEFAULT_NODE_REPOSITORY and not mod.is_root: + fail("Only the root module may provide a name for the node toolchain.") +- + if toolchain.name in registrations.keys(): + if toolchain.name == DEFAULT_NODE_REPOSITORY: + # Prioritize the root-most registration of the default node toolchain version and + # ignore any further registrations (modules are processed breadth-first) + continue +- if toolchain.node_version == registrations[toolchain.name].node_version and toolchain.node_version_from_nvmrc == registrations[toolchain.name].node_version_from_nvmrc: ++ if (toolchain.node_version != registrations[toolchain.name].node_version or ++ toolchain.node_version_from_nvmrc != registrations[toolchain.name].node_version_from_nvmrc): ++ fail("Multiple conflicting toolchains declared for name {} ({} and {})".format( ++ toolchain.name, ++ toolchain.node_version, ++ registrations[toolchain.name].node_version, ++ )) ++ elif toolchain.node_urls != registrations[toolchain.name].node_urls: ++ fail("Multiple toolchains with conflicting urls declared for name {} ({} and {})".format( ++ toolchain.name, ++ toolchain.node_urls, ++ registrations[toolchain.name].node_urls, ++ )) ++ else: + # No problem to register a matching toolchain twice + continue +- fail("Multiple conflicting toolchains declared for name {} ({} and {})".format( +- toolchain.name, +- toolchain.node_version, +- registrations[toolchain.name], +- )) + else: +- registrations[toolchain.name] = struct( +- node_version = toolchain.node_version, +- node_version_from_nvmrc = toolchain.node_version_from_nvmrc, +- include_headers = toolchain.include_headers, +- ) ++ registrations[toolchain.name] = toolchain + +- for k, v in registrations.items(): ++ for k, t in registrations.items(): + nodejs_register_toolchains( + name = k, +- node_version = v.node_version, +- node_version_from_nvmrc = v.node_version_from_nvmrc, +- include_headers = v.include_headers, ++ node_version = t.node_version, ++ node_version_from_nvmrc = t.node_version_from_nvmrc, ++ node_urls = t.node_urls, ++ include_headers = t.include_headers, + register = False, + ) + +@@ -62,6 +72,10 @@ If set then the version found in the .nvmrc file is used instead of the one spec + This setting creates a dependency on a c++ toolchain. + """, + ), ++ "node_urls": attr.string_list( ++ doc = "Custom list of URL formats to use to download NodeJS, containing {version} and {filename}", ++ default = [DEFAULT_NODE_URL], ++ ), + }), + }, + ) diff --git a/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/module_dot_bazel_version.patch b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/module_dot_bazel_version.patch new file mode 100644 index 000000000000..33b7e5140507 --- /dev/null +++ b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/module_dot_bazel_version.patch @@ -0,0 +1,14 @@ +=================================================================== +--- a/MODULE.bazel ++++ b/MODULE.bazel +@@ -1,9 +1,9 @@ + "bzlmod declaration for bazelbuild/rules_nodejs" + + module( + name = "rules_nodejs", +- version = "0.0.0", ++ version = "6.2.0", + compatibility_level = 1, + ) + + # Lower-bounds (minimum) versions for direct runtime dependencies diff --git a/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/presubmit.yml b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/presubmit.yml new file mode 100644 index 000000000000..3a43aa4775f9 --- /dev/null +++ b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/presubmit.yml @@ -0,0 +1,14 @@ +bcr_test_module: + module_path: "e2e/smoke" + matrix: + bazel: ["7.x"] + platform: ["debian10", "macos", "ubuntu2004", "windows"] + tasks: + run_tests: + name: "Run test module" + bazel: ${{ bazel }} + platform: ${{ platform }} + test_targets: + - "//..." + test_flags: + - "--test_tag_filters=-skip-on-bazelci-windows" diff --git a/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/source.json b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/source.json new file mode 100644 index 000000000000..8a627df02a04 --- /dev/null +++ b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/source.json @@ -0,0 +1,10 @@ +{ + "integrity": "sha256-h8YXHFvntpU41Gldne0priYmxe12qa3u3ON7Y8c772c=", + "strip_prefix": "rules_nodejs-6.2.0", + "url": "https://github.com/bazelbuild/rules_nodejs/releases/download/v6.2.0/rules_nodejs-v6.2.0.tar.gz", + "patches": { + "module_dot_bazel_version.patch": "sha256-T4mwfyYatnFjIKG+tL8m9++41/1AG7zMPpZQFdqoIK4=", + "allow_node_urls.patch": "sha256-vbZx3du+2gzTDopNgUOzWJVznt3055nsQuwCfgieLGY=" + }, + "patch_strip": 1 +} diff --git a/misc/bazel/registry/modules/rules_nodejs/metadata.json b/misc/bazel/registry/modules/rules_nodejs/metadata.json new file mode 100644 index 000000000000..2b3827d48289 --- /dev/null +++ b/misc/bazel/registry/modules/rules_nodejs/metadata.json @@ -0,0 +1,5 @@ +{ + "versions": [ + "6.2.0-codeql.1" + ] +} From 0669186713736d1e8e698a09fe572a8c557e0900 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 24 Jun 2024 17:09:40 +0200 Subject: [PATCH 2/2] Bazel: remove unneeded upstream `rules_nodejs` patch --- .../patches/module_dot_bazel_version.patch | 14 -------------- .../rules_nodejs/6.2.0-codeql.1/source.json | 1 - 2 files changed, 15 deletions(-) delete mode 100644 misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/module_dot_bazel_version.patch diff --git a/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/module_dot_bazel_version.patch b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/module_dot_bazel_version.patch deleted file mode 100644 index 33b7e5140507..000000000000 --- a/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/patches/module_dot_bazel_version.patch +++ /dev/null @@ -1,14 +0,0 @@ -=================================================================== ---- a/MODULE.bazel -+++ b/MODULE.bazel -@@ -1,9 +1,9 @@ - "bzlmod declaration for bazelbuild/rules_nodejs" - - module( - name = "rules_nodejs", -- version = "0.0.0", -+ version = "6.2.0", - compatibility_level = 1, - ) - - # Lower-bounds (minimum) versions for direct runtime dependencies diff --git a/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/source.json b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/source.json index 8a627df02a04..f1966a0fa04d 100644 --- a/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/source.json +++ b/misc/bazel/registry/modules/rules_nodejs/6.2.0-codeql.1/source.json @@ -3,7 +3,6 @@ "strip_prefix": "rules_nodejs-6.2.0", "url": "https://github.com/bazelbuild/rules_nodejs/releases/download/v6.2.0/rules_nodejs-v6.2.0.tar.gz", "patches": { - "module_dot_bazel_version.patch": "sha256-T4mwfyYatnFjIKG+tL8m9++41/1AG7zMPpZQFdqoIK4=", "allow_node_urls.patch": "sha256-vbZx3du+2gzTDopNgUOzWJVznt3055nsQuwCfgieLGY=" }, "patch_strip": 1