Skip to content

Commit ed7064f

Browse files
authored
Add Bazel Central Registry (BCR) publishing support (#262)
* Replace Node.js version header generator with C++ implementation Replaces the Node.js-based generate-version-header.js script with a C++ implementation to eliminate the Node.js runtime dependency from the build process. The new C++ tool reads package.json and generates the same version.h header file. Also fixes Closure Compiler errors under strict mode in extension_field_binary_info.js and map.js by properly assigning goog.requireType calls to const variables instead of using standalone goog.requireType calls. Changes: - Add generator/generate-version-header.cc with C++ implementation - Remove generate-version-header.js - Update generator/BUILD.bazel to use cc_binary instead of Node.js script - Add rules_cc dependency to MODULE.bazel - Update BUILD.bazel to remove deleted script from exports_files - Fix goog.requireType usage in extension_field_binary_info.js and map.js * Add BCR boilerplate * Add //:javascript target * Add patch to remove dist-related bazel targets from root BUILD file * Mark rules_pkg as a dev dependency * bcr: remove non-google maintainer * Remove version string in MODULE.bazel * Add e2e/bcr to bazelignore Also add .bazelrc configuration to disallow auto-importing previously native symbols (e.g. sh_binary)
1 parent a908831 commit ed7064f

19 files changed

+674
-114
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
e2e/bcr

.bazelrc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
22
build:macos --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
3+
build:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17
34

45
build:dbg --compilation_mode=dbg
56

@@ -29,12 +30,12 @@ build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr
2930
build --features=layering_check
3031
common --enable_platform_specific_config
3132

32-
build:windows --cxxopt=/std:c++17
33-
build:windows --host_cxxopt=/std:c++17
34-
3533
common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1
3634

3735

3836
# Allow building with MSVC, which is being deprecated.
3937
# See: https://github.com/protocolbuffers/protobuf/issues/20085
4038
build --define=protobuf_allow_msvc=true
39+
40+
# To facilitate testing in bazelci incompatible flags
41+
build --incompatible_autoload_externally=

.bcr/metadata.template.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"homepage": "https://github.com/protocolbuffers/protobuf-javascript",
3+
"maintainers": [
4+
{
5+
"name": "Stephanie DiBenedetto",
6+
"email": "[email protected]",
7+
"github": "dibenede"
8+
}
9+
],
10+
"repository": [
11+
"github:protocolbuffers/protobuf-javascript"
12+
],
13+
"versions": [],
14+
"yanked_versions": {}
15+
}

.bcr/patches/remove-dist.patch

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
diff --git a/BUILD.bazel b/BUILD.bazel
2+
index b64b057..a7d6524 100644
3+
--- a/BUILD.bazel
4+
+++ b/BUILD.bazel
5+
@@ -2,10 +2,6 @@
6+
#
7+
# See also code generation logic under generator/
8+
9+
-load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
10+
-load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
11+
-load("//:protobuf_javascript_release.bzl", "package_naming")
12+
-
13+
exports_files(["package.json"])
14+
15+
config_setting(
16+
@@ -33,72 +29,6 @@ config_setting(
17+
values = {"cpu": "darwin_x86_64"},
18+
)
19+
20+
-package_naming(
21+
- name = "protobuf_javascript_pkg_naming",
22+
- platform = select({
23+
- ":k8": "linux-x86_64", # currently the only supported build type in Github Actions
24+
- ":x64_x86_windows": "win32",
25+
- ":x64_windows": "win64",
26+
- ":darwin_arm64": "osx-aarch_64",
27+
- ":darwin_x86_64": "osx-x86_64",
28+
- "//conditions:default": "", # continues with current behavior when no --cpu is specified allowing existing internal builds to function
29+
- }),
30+
-)
31+
-
32+
-pkg_files(
33+
- name = "plugin_files",
34+
- srcs = ["//generator:protoc-gen-js"],
35+
- attributes = pkg_attributes(mode = "0555"),
36+
- prefix = "bin/",
37+
-)
38+
-
39+
-pkg_files(
40+
- name = "dist_files",
41+
- srcs = glob(
42+
- [
43+
- "google/protobuf/*.js",
44+
- "google/protobuf/compiler/*.js",
45+
- ],
46+
- allow_empty = True,
47+
- ) + [
48+
- "LICENSE.md",
49+
- "LICENSE-asserts.md",
50+
- "README.md",
51+
- "google-protobuf.js",
52+
- "package.json",
53+
- ],
54+
- strip_prefix = strip_prefix.from_root(""),
55+
-)
56+
-
57+
-pkg_tar(
58+
- name = "dist_tar",
59+
- srcs = [
60+
- ":dist_files",
61+
- ":plugin_files",
62+
- ],
63+
- extension = "tar.gz",
64+
- package_file_name = "protobuf-javascript-{version}-{platform}.tar.gz",
65+
- package_variables = ":protobuf_javascript_pkg_naming",
66+
-)
67+
-
68+
-pkg_zip(
69+
- name = "dist_zip",
70+
- srcs = [
71+
- ":dist_files",
72+
- ":plugin_files",
73+
- ],
74+
- package_file_name = "protobuf-javascript-{version}-{platform}.zip",
75+
- package_variables = ":protobuf_javascript_pkg_naming",
76+
-)
77+
-
78+
-filegroup(
79+
- name = "dist_all",
80+
- srcs = [
81+
- ":dist_tar",
82+
- ":dist_zip",
83+
- ],
84+
-)
85+
-
86+
filegroup(
87+
name = "javascript",
88+
srcs = [

.bcr/presubmit.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bcr_test_module:
2+
module_path: "e2e/bcr"
3+
matrix:
4+
platform: ["debian11", "ubuntu2404", "macos"]
5+
bazel: [7.x, 8.x]
6+
tasks:
7+
run_tests:
8+
name: "Run test module"
9+
platform: ${{ platform }}
10+
bazel: ${{ bazel }}
11+
test_targets:
12+
- "//..."

.bcr/source.template.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"integrity": "",
3+
"strip_prefix": "{REPO}-{TAG}",
4+
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz"
5+
}

.github/workflows/publish.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Publish new releases to Bazel Central Registry.
2+
name: Publish to BCR
3+
on:
4+
# Run the publish workflow after a successful release
5+
# Will be triggered from the release.yaml workflow
6+
workflow_call:
7+
inputs:
8+
tag_name:
9+
required: true
10+
type: string
11+
secrets:
12+
publish_token:
13+
required: true
14+
# In case of problems, let release engineers retry by manually dispatching
15+
# the workflow from the GitHub UI
16+
workflow_dispatch:
17+
inputs:
18+
tag_name:
19+
description: git tag being released
20+
required: true
21+
type: string
22+
jobs:
23+
publish:
24+
uses: bazel-contrib/publish-to-bcr/.github/workflows/[email protected]
25+
with:
26+
draft: false
27+
tag_name: ${{ inputs.tag_name }}
28+
# GitHub repository which is a fork of the upstream where the Pull Request will be opened.
29+
registry_fork: protocolbuffers/bazel-central-registry
30+
permissions:
31+
attestations: write
32+
contents: write
33+
id-token: write
34+
secrets:
35+
# Necessary to push to the BCR fork, and to open a pull request against a registry
36+
publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }}

.github/workflows/release.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Cut a release whenever a new tag is pushed to the repo.
2+
name: Release
3+
on:
4+
# Can be triggered from the tag.yaml workflow
5+
workflow_call:
6+
inputs:
7+
tag_name:
8+
required: true
9+
type: string
10+
secrets:
11+
publish_token:
12+
required: true
13+
# Or, developers can manually push a tag from their clone
14+
push:
15+
tags:
16+
- "v*.*.*"
17+
permissions:
18+
id-token: write
19+
attestations: write
20+
contents: write
21+
jobs:
22+
release:
23+
uses: bazel-contrib/.github/.github/workflows/[email protected]
24+
with:
25+
prerelease: false
26+
release_files: protobuf-javascript-*.tar.gz
27+
tag_name: ${{ inputs.tag_name || github.ref_name }}
28+
secrets: inherit
29+
publish:
30+
needs: release
31+
uses: ./.github/workflows/publish.yaml
32+
with:
33+
tag_name: ${{ inputs.tag_name || github.ref_name }}
34+
secrets:
35+
publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }}

.github/workflows/release_prep.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
#!/usr/bin/env bash
3+
4+
set -o errexit -o nounset -o pipefail
5+
6+
# Set by GH actions, see
7+
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
8+
readonly TAG=$1
9+
# The prefix is chosen to match what GitHub generates for source archives.
10+
# This guarantees that users can easily switch from a released artifact to a source archive
11+
# with minimal differences in their code (e.g. strip_prefix remains the same)
12+
readonly PREFIX="protobuf_javascript-${TAG}"
13+
readonly ARCHIVE="${PREFIX}.tar.gz"
14+
15+
# NB: configuration for 'git archive' is in /.gitattributes
16+
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
17+
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')
18+
19+
# The stdout of this program will be used as the top of the release notes for this release.
20+
cat << EOF
21+
## Using bzlmod with Bazel 7 or later:
22+
23+
Add to your \`MODULE.bazel\` file:
24+
25+
\`\`\`starlark
26+
bazel_dep(name = "protobuf_javascript", version = "${TAG}")
27+
\`\`\`
28+
EOF

BUILD.bazel

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,41 @@ filegroup(
9898
":dist_zip",
9999
],
100100
)
101+
102+
filegroup(
103+
name = "javascript",
104+
srcs = [
105+
"asserts.js",
106+
"binary/any_field_type.js",
107+
"binary/arith.js",
108+
"binary/binary_constants.js",
109+
"binary/bytesource.js",
110+
"binary/bytesource_alias.js",
111+
"binary/decoder.js",
112+
"binary/decoder_alias.js",
113+
"binary/encoder.js",
114+
"binary/encoder_alias.js",
115+
"binary/errors.js",
116+
"binary/internal_buffer.js",
117+
"binary/reader.js",
118+
"binary/reader_alias.js",
119+
"binary/repeated_field_type.js",
120+
"binary/scalar_field_type.js",
121+
"binary/test_utils.js",
122+
"binary/utf8.js",
123+
"binary/utils.js",
124+
"binary/writer.js",
125+
"binary/writer_alias.js",
126+
"bytestring.js",
127+
"debug.js",
128+
"extension_field_binary_info.js",
129+
"extension_field_info.js",
130+
"internal_bytes.js",
131+
"internal_options.js",
132+
"internal_public.js",
133+
"map.js",
134+
"message.js",
135+
"unsafe_bytestring.js",
136+
],
137+
visibility = ["//visibility:public"],
138+
)

0 commit comments

Comments
 (0)