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 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
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
41 changes: 41 additions & 0 deletions e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"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")
bazel_dep(name = "aspect_bazel_lib", dev_dependency = True, version = "1.30.2")

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",
)
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.
36 changes: 17 additions & 19 deletions examples/toolchain/WORKSPACE → e2e/smoke/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.2/rules_nodejs-core-5.8.2.tar.gz"],
)

# Note: skylib 1.1.1 has some bug on Windows with diff_test, which we use in this example
http_archive(
name = "bazel_skylib",
sha256 = "afbe4d9d033c007940acd24bb9becf1580a0280ae0b2ebbb5a7cb12912d2c115",
strip_prefix = "bazel-skylib-ffad33e9bfc60bdfa98292ca655a4e7035792046",
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/ffad33e9bfc60bdfa98292ca655a4e7035792046.tar.gz"],
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz",
],
)

http_archive(
name = "aspect_bazel_lib",
sha256 = "97fa63d95cc9af006c4c7b2123ddd2a91fb8d273012f17648e6423bae2c69470",
strip_prefix = "bazel-lib-1.30.2",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.30.2/bazel-lib-v1.30.2.tar.gz",
)

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies()

load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")

# The order matters because Bazel will provide the first registered toolchain when a rule asks Bazel to select it
Expand All @@ -32,21 +44,7 @@ nodejs_register_toolchains(

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"],
)
""",
build_file = "acorn.BUILD",
sha256 = "d8f9d40c4656537a60bf0c6daae6f0553f54df5ff2518f86464b7c785f20376b",
urls = ["https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz"],
)
10 changes: 10 additions & 0 deletions e2e/smoke/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Replaces WORKSPACE.bazel under --enable_bzlmod

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

http_archive(
name = "npm_acorn-8.5.0",
build_file = "acorn.BUILD",
sha256 = "d8f9d40c4656537a60bf0c6daae6f0553f54df5ff2518f86464b7c785f20376b",
urls = ["https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz"],
)
File renamed without changes.
10 changes: 10 additions & 0 deletions e2e/smoke/external/acorn.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@aspect_bazel_lib//lib:copy_directory.bzl", "copy_directory")

# Turn a source directory into a TreeArtifact for RBE-compat
copy_directory(
name = "npm_acorn-8.5.0",
src = "package",
# We must give this as the directory in order for it to appear on NODE_PATH
out = "acorn",
visibility = ["//visibility:public"],
)