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

chore: bzlmod #3647

Merged
merged 2 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions .bcr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Bazel Central Registry

When the ruleset is released, we want it to be published to the
Bazel Central Registry automatically:
<https://registry.bazel.build>

This folder contains configuration files to automate the publish step.
See <https://github.com/bazel-contrib/publish-to-bcr/blob/main/templates/README.md>
for authoritative documentation about these files.
5 changes: 5 additions & 0 deletions .bcr/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See https://github.com/bazel-contrib/publish-to-bcr#a-note-on-release-automation

fixedReleaser:
login: alexeagle
email: [email protected]
7 changes: 7 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"homepage": "https://github.com/bazelbuild/rules_nodejs",
"maintainers": [],
"repository": ["github:bazelbuild/rules_nodejs"],
"versions": [],
"yanked_versions": {}
}
10 changes: 10 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bcr_test_module:
module_path: 'e2e/smoke'
matrix:
platform: ['debian10', 'macos', 'ubuntu2004', 'windows']
tasks:
run_tests:
name: 'Run test module'
platform: ${{ platform }}
test_targets:
- '//...'
5 changes: 5 additions & 0 deletions .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"integrity": "**leave this alone**",
"strip_prefix": "{REPO}-{VERSION}",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_nodejs-{TAG}.tar.gz"
}
19 changes: 19 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"bzlmod declaration for bazelbuild/rules_nodejs"

module(
name = "rules_nodejs",
compatibility_level = 1,
version = "0.0.0",
)

bazel_dep(name = "bazel_skylib", version = "1.1.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/5.8.0/nodejs/repositories.bzl#L11
node.toolchain(name = "nodejs")

use_repo(node, "nodejs_toolchains")
register_toolchains("@nodejs_toolchains//:all")
12 changes: 7 additions & 5 deletions examples/toolchain/BUILD.bazel → e2e/smoke/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ my_nodejs(
)

# this tests to make sure that the first version imported in the workspace is used as default
diff_test(
name = "node_version_default_toolchain_test",
file1 = "write_node_version_16",
file2 = "thing_no_toolchain",
)
# FIXME: under bzlmod, the first toolchain registered is in the rules_nodejs/MODULE.bazel
# which is the "latest version" of node, not the one in our local MODULE.bazel file.
# diff_test(
# name = "node_version_default_toolchain_test",
# file1 = "write_node_version_16",
# file2 = "thing_no_toolchain",
# )

# Output contains the version number of node that is used.
# This is used in tests later to verify the toolchain specified is resolved correctly
Expand Down
65 changes: 65 additions & 0 deletions e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"bzlmod dependencies"
module(
name = "rules_nodejs_smoke_test",
compatibility_level = 1,
version = "0.0.0",
)

bazel_dep(name = "rules_nodejs", dev_dependency = True, version = "0.0.0")
bazel_dep(name = "bazel_skylib", dev_dependency = True, version = "1.3.0")

local_path_override(
module_name = "rules_nodejs",
path = "../..",
)

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/5.8.0/nodejs/repositories.bzl#L11
node.toolchain(
name = "node16",
node_version = "16.5.0",
)

node.toolchain(
name = "node15",
node_version = "15.14.0",
)

# FIXME(6.0): a repo rule with name=foo should create a repo named @foo, not @foo_toolchains
use_repo(
node,
"node16_toolchains",
"node15_linux_amd64",
"node15_darwin_amd64",
"node15_windows_amd64",
"node16_linux_amd64",
"node16_darwin_amd64",
"node16_windows_amd64",
)

http = use_extension("//:deps.bzl", "http")

http.archive(
name = "npm_acorn-8.5.0",
build_file_content = """
load("@rules_nodejs//third_party/github.com/bazelbuild/bazel-skylib:rules/copy_file.bzl", "copy_file")

# Turn a source directory into a TreeArtifact for RBE-compat
copy_file(
name = "npm_acorn-8.5.0",
src = "package",
# This attribute comes from rules_nodejs patch of
# https://github.com/bazelbuild/bazel-skylib/pull/323
is_directory = True,
# We must give this as the directory in order for it to appear on NODE_PATH
out = "acorn",
visibility = ["//visibility:public"],
)
""",
sha256 = "d8f9d40c4656537a60bf0c6daae6f0553f54df5ff2518f86464b7c785f20376b",
urls = ["https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz"],
)

use_repo(http, "npm_acorn-8.5.0")
5 changes: 5 additions & 0 deletions e2e/smoke/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# smoke test

This e2e exercises the repo from an end-users perpective.
It catches mistakes in our install instructions, or usages that fail when called from an "external" repository to rules_nodejs.
It is also used by the presubmit check for the Bazel Central Registry.
File renamed without changes.
1 change: 1 addition & 0 deletions e2e/smoke/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Replaces WORKSPACE.bazel under --enable_bzlmod
File renamed without changes.
29 changes: 29 additions & 0 deletions e2e/smoke/deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Module extension to fetch dependencies

Most users are better served using aspect_rules_js to fetch dependencies.

This is just http_archive wrapped, see
https://github.com/bazelbuild/bazel/issues/17141
"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def _http_impl(ctx):
for mod in ctx.modules:
for pkg in mod.tags.archive:
http_archive(
name = pkg.name,
build_file_content = pkg.build_file_content,
sha256 = pkg.sha256,
urls = pkg.urls,
)

http = module_extension(
implementation = _http_impl,
tag_classes = {"archive": tag_class(attrs = {
"name": attr.string(),
"build_file_content": attr.string(),
"sha256": attr.string(),
"urls": attr.string_list(),
})},
)
alexeagle marked this conversation as resolved.
Show resolved Hide resolved