Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel: add nodejs mirror #16822

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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, `:<PLATFORM>_toolchain_target` should be registered before `:<PLATFORM>_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")
Original file line number Diff line number Diff line change
@@ -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],
+ ),
}),
},
)
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"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": {
"allow_node_urls.patch": "sha256-vbZx3du+2gzTDopNgUOzWJVznt3055nsQuwCfgieLGY="
},
"patch_strip": 1
}
5 changes: 5 additions & 0 deletions misc/bazel/registry/modules/rules_nodejs/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"versions": [
"6.2.0-codeql.1"
]
}
Loading