Skip to content

Commit 5b134f8

Browse files
authored
chore(docs): document module extensions (#3898)
These are the primary API under bzlmod Also pull out the docgen snippet so we can call it from a different pipeline, like I did in rules_ts and rules_js
1 parent e59bf17 commit 5b134f8

6 files changed

Lines changed: 63 additions & 20 deletions

File tree

.github/workflows/release_docs.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# Add generated API docs to the release
3+
# see https://github.com/bazelbuild/bazel-central-registry/blob/main/docs/stardoc.md
4+
set -o errexit -o nounset -o pipefail
5+
6+
docs="$(mktemp -d)"
7+
targets="$(mktemp)"
8+
out=$1
9+
bazel --output_base="$docs" query --output=label --output_file="$targets" 'kind("starlark_doc_extract rule", //...)'
10+
bazel --output_base="$docs" build --target_pattern_file="$targets"
11+
tar --create --auto-compress \
12+
--directory "$(bazel --output_base="$docs" info bazel-bin)" \
13+
--file "${out}" .

.github/workflows/release_prep.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ PREFIX="rules_nodejs-${TAG:1}"
1010
ARCHIVE="rules_nodejs-$TAG.tar.gz"
1111
git archive --format=tar --prefix="${PREFIX}/" "${TAG}" | gzip > "$ARCHIVE"
1212
SHA=$(shasum -a 256 "$ARCHIVE" | awk '{print $1}')
13-
14-
# Add generated API docs to the release, see https://github.com/bazelbuild/bazel-central-registry/issues/5593
15-
docs="$(mktemp -d)"; targets="$(mktemp)"
16-
bazel --output_base="$docs" query --output=label --output_file="$targets" 'kind("starlark_doc_extract rule", //...)'
17-
bazel --output_base="$docs" build --target_pattern_file="$targets" --remote_download_regex='.*doc_extract\.binaryproto'
18-
tar --create --auto-compress \
19-
--directory "$(bazel --output_base="$docs" info bazel-bin)" \
20-
--file "$GITHUB_WORKSPACE/${ARCHIVE%.tar.gz}.docs.tar.gz" .
13+
./.github/workflows/release_docs.sh "$GITHUB_WORKSPACE/${ARCHIVE%.tar.gz}.docs.tar.gz"
2114

2215
cat << EOF
2316
## Using Bzlmod with Bazel 6 or greater

WORKSPACE

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ workspace(name = "rules_nodejs")
1616

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

19-
http_archive(
20-
name = "bazel_features",
21-
sha256 = "5ab1a90d09fd74555e0df22809ad589627ddff263cff82535815aa80ca3e3562",
22-
strip_prefix = "bazel_features-1.39.0",
23-
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.39.0/bazel_features-v1.39.0.tar.gz",
24-
)
25-
26-
load("@bazel_features//:deps.bzl", "bazel_features_deps")
27-
28-
bazel_features_deps()
29-
3019
#
3120
# Install rules_nodejs dev dependencies
3221
#
@@ -35,6 +24,10 @@ load("//:repositories.bzl", "rules_nodejs_dev_dependencies")
3524

3625
rules_nodejs_dev_dependencies()
3726

27+
load("@bazel_features//:deps.bzl", "bazel_features_deps")
28+
29+
bazel_features_deps()
30+
3831
#
3932
# Setup rules_nodejs npm dependencies
4033
#
@@ -84,6 +77,10 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
8477

8578
bazel_skylib_workspace()
8679

80+
load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
81+
82+
compatibility_proxy_repo()
83+
8784
# Buildifier
8885
load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")
8986

nodejs/BUILD.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ load(":node_toolchain_alias.bzl", "node_runtime_alias", "node_toolchain_alias")
66

77
package(default_visibility = ["//visibility:public"])
88

9+
bzl_library(
10+
name = "extensions",
11+
srcs = ["extensions.bzl"],
12+
deps = [":repositories"],
13+
)
14+
915
bzl_library(
1016
name = "providers",
1117
srcs = ["providers.bzl"],
@@ -26,6 +32,16 @@ bzl_library(
2632
],
2733
)
2834

35+
bzl_library(
36+
name = "toolchain",
37+
srcs = ["toolchain.bzl"],
38+
deps = [
39+
"//nodejs/private:current_node_cc_headers",
40+
"//nodejs/private:os_name",
41+
"@rules_cc//cc:defs_bzl",
42+
],
43+
)
44+
2945
# This is the target rule authors should put in their "toolchains"
3046
# attribute in order to get a node interpreter for the correct
3147
# platform.

nodejs/extensions.bzl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
"extensions for bzlmod"
1+
"""Module extensions for nodejs toolchain registration in MODULE.bazel
2+
3+
Example usage, assuming a `.nvmrc` file is present in the same directory as the `MODULE.bazel` file:
4+
5+
```starlark
6+
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
7+
node.toolchain(node_version_from_nvmrc = "//:.nvmrc")
8+
use_repo(node, "nodejs_toolchains")
9+
```
10+
"""
211

312
load(
413
":repositories.bzl",
@@ -67,11 +76,13 @@ _ATTRS = {
6776
allow_single_file = True,
6877
doc = """The .nvmrc file containing the version of Node.js to use.
6978
79+
This is recommended to ensure Bazel uses the same Node.js version as non-Bazel tooling.
7080
If set then the version found in the .nvmrc file is used instead of the one specified by node_version.""",
7181
),
7282
"include_headers": attr.bool(
7383
doc = """Set headers field in NodeInfo provided by this toolchain.
7484
85+
Required to compile native code into a Node.js binary.
7586
This setting creates a dependency on a c++ toolchain.
7687
""",
7788
),

repositories.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ def rules_nodejs_dev_dependencies():
3030
These are in this file to keep version information in one place, and make the WORKSPACE
3131
shorter.
3232
"""
33+
http_archive(
34+
name = "bazel_features",
35+
sha256 = "5ab1a90d09fd74555e0df22809ad589627ddff263cff82535815aa80ca3e3562",
36+
strip_prefix = "bazel_features-1.39.0",
37+
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.39.0/bazel_features-v1.39.0.tar.gz",
38+
)
3339

3440
http_archive(
3541
name = "bazel_skylib",
@@ -50,3 +56,10 @@ def rules_nodejs_dev_dependencies():
5056
strip_prefix = "buildifier-prebuilt-8.0.0",
5157
urls = ["http://github.com/keith/buildifier-prebuilt/archive/8.0.0.tar.gz"],
5258
)
59+
60+
http_archive(
61+
name = "rules_cc",
62+
sha256 = "458b658277ba51b4730ea7a2020efdf1c6dcadf7d30de72e37f4308277fa8c01",
63+
strip_prefix = "rules_cc-0.2.16",
64+
url = "https://github.com/bazelbuild/rules_cc/releases/download/0.2.16/rules_cc-0.2.16.tar.gz",
65+
)

0 commit comments

Comments
 (0)