Skip to content
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
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e2e/bcr
7 changes: 4 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build:macos --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17

build:dbg --compilation_mode=dbg

Expand Down Expand Up @@ -29,12 +30,12 @@ build:ubsan --copt=-fno-sanitize=function --copt=-fno-sanitize=vptr
build --features=layering_check
common --enable_platform_specific_config

build:windows --cxxopt=/std:c++17
build:windows --host_cxxopt=/std:c++17

common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1


# Allow building with MSVC, which is being deprecated.
# See: https://github.com/protocolbuffers/protobuf/issues/20085
build --define=protobuf_allow_msvc=true

# To facilitate testing in bazelci incompatible flags
build --incompatible_autoload_externally=
15 changes: 15 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"homepage": "https://github.com/protocolbuffers/protobuf-javascript",
"maintainers": [
{
"name": "Stephanie DiBenedetto",
"email": "dibenede@google.com",
"github": "dibenede"
}
],
"repository": [
"github:protocolbuffers/protobuf-javascript"
],
"versions": [],
"yanked_versions": {}
}
88 changes: 88 additions & 0 deletions .bcr/patches/remove-dist.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
diff --git a/BUILD.bazel b/BUILD.bazel
index b64b057..a7d6524 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -2,10 +2,6 @@
#
# See also code generation logic under generator/

-load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
-load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
-load("//:protobuf_javascript_release.bzl", "package_naming")
-
exports_files(["package.json"])

config_setting(
@@ -33,72 +29,6 @@ config_setting(
values = {"cpu": "darwin_x86_64"},
)

-package_naming(
- name = "protobuf_javascript_pkg_naming",
- platform = select({
- ":k8": "linux-x86_64", # currently the only supported build type in Github Actions
- ":x64_x86_windows": "win32",
- ":x64_windows": "win64",
- ":darwin_arm64": "osx-aarch_64",
- ":darwin_x86_64": "osx-x86_64",
- "//conditions:default": "", # continues with current behavior when no --cpu is specified allowing existing internal builds to function
- }),
-)
-
-pkg_files(
- name = "plugin_files",
- srcs = ["//generator:protoc-gen-js"],
- attributes = pkg_attributes(mode = "0555"),
- prefix = "bin/",
-)
-
-pkg_files(
- name = "dist_files",
- srcs = glob(
- [
- "google/protobuf/*.js",
- "google/protobuf/compiler/*.js",
- ],
- allow_empty = True,
- ) + [
- "LICENSE.md",
- "LICENSE-asserts.md",
- "README.md",
- "google-protobuf.js",
- "package.json",
- ],
- strip_prefix = strip_prefix.from_root(""),
-)
-
-pkg_tar(
- name = "dist_tar",
- srcs = [
- ":dist_files",
- ":plugin_files",
- ],
- extension = "tar.gz",
- package_file_name = "protobuf-javascript-{version}-{platform}.tar.gz",
- package_variables = ":protobuf_javascript_pkg_naming",
-)
-
-pkg_zip(
- name = "dist_zip",
- srcs = [
- ":dist_files",
- ":plugin_files",
- ],
- package_file_name = "protobuf-javascript-{version}-{platform}.zip",
- package_variables = ":protobuf_javascript_pkg_naming",
-)
-
-filegroup(
- name = "dist_all",
- srcs = [
- ":dist_tar",
- ":dist_zip",
- ],
-)
-
filegroup(
name = "javascript",
srcs = [
12 changes: 12 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bcr_test_module:
module_path: "e2e/bcr"
matrix:
platform: ["debian11", "ubuntu2404", "macos"]
bazel: [7.x, 8.x]
tasks:
run_tests:
name: "Run test module"
platform: ${{ platform }}
bazel: ${{ bazel }}
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": "",
"strip_prefix": "{REPO}-{TAG}",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/{REPO}-{TAG}.tar.gz"
}
36 changes: 36 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Publish new releases to Bazel Central Registry.
name: Publish to BCR
on:
# Run the publish workflow after a successful release
# Will be triggered from the release.yaml workflow
workflow_call:
inputs:
tag_name:
required: true
type: string
secrets:
publish_token:
required: true
# In case of problems, let release engineers retry by manually dispatching
# the workflow from the GitHub UI
workflow_dispatch:
inputs:
tag_name:
description: git tag being released
required: true
type: string
jobs:
publish:
uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v0.2.3
with:
draft: false
tag_name: ${{ inputs.tag_name }}
# GitHub repository which is a fork of the upstream where the Pull Request will be opened.
registry_fork: protocolbuffers/bazel-central-registry
permissions:
attestations: write
contents: write
id-token: write
secrets:
# Necessary to push to the BCR fork, and to open a pull request against a registry
publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }}
35 changes: 35 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Cut a release whenever a new tag is pushed to the repo.
name: Release
on:
# Can be triggered from the tag.yaml workflow
workflow_call:
inputs:
tag_name:
required: true
type: string
secrets:
publish_token:
required: true
# Or, developers can manually push a tag from their clone
push:
tags:
- "v*.*.*"
permissions:
id-token: write
attestations: write
contents: write
jobs:
release:
uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7.2.3
with:
prerelease: false
release_files: protobuf-javascript-*.tar.gz
tag_name: ${{ inputs.tag_name || github.ref_name }}
secrets: inherit
publish:
needs: release
uses: ./.github/workflows/publish.yaml
with:
tag_name: ${{ inputs.tag_name || github.ref_name }}
secrets:
publish_token: ${{ secrets.publish_token || secrets.BCR_PUBLISH_TOKEN }}
28 changes: 28 additions & 0 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

# Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
readonly TAG=$1
# The prefix is chosen to match what GitHub generates for source archives.
# This guarantees that users can easily switch from a released artifact to a source archive
# with minimal differences in their code (e.g. strip_prefix remains the same)
readonly PREFIX="protobuf_javascript-${TAG}"
readonly ARCHIVE="${PREFIX}.tar.gz"

# NB: configuration for 'git archive' is in /.gitattributes
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')

# The stdout of this program will be used as the top of the release notes for this release.
cat << EOF
## Using bzlmod with Bazel 7 or later:

Add to your \`MODULE.bazel\` file:

\`\`\`starlark
bazel_dep(name = "protobuf_javascript", version = "${TAG}")
\`\`\`
EOF
38 changes: 38 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,41 @@ filegroup(
":dist_zip",
],
)

filegroup(
name = "javascript",
srcs = [
"asserts.js",
"binary/any_field_type.js",
"binary/arith.js",
"binary/binary_constants.js",
"binary/bytesource.js",
"binary/bytesource_alias.js",
"binary/decoder.js",
"binary/decoder_alias.js",
"binary/encoder.js",
"binary/encoder_alias.js",
"binary/errors.js",
"binary/internal_buffer.js",
"binary/reader.js",
"binary/reader_alias.js",
"binary/repeated_field_type.js",
"binary/scalar_field_type.js",
"binary/test_utils.js",
"binary/utf8.js",
"binary/utils.js",
"binary/writer.js",
"binary/writer_alias.js",
"bytestring.js",
"debug.js",
"extension_field_binary_info.js",
"extension_field_info.js",
"internal_bytes.js",
"internal_options.js",
"internal_public.js",
"map.js",
"message.js",
"unsafe_bytestring.js",
],
visibility = ["//visibility:public"],
)
6 changes: 4 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module(name = "protobuf_javascript", version = "4.0.1")
"Bazel module that provides protoc-gen-js."

module(name = "protobuf_javascript", version = "0.0.0") # updated by release action

bazel_dep(name = "abseil-cpp", version = "20250512.1")
bazel_dep(name = "protobuf", version = "33.0", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_cc", version = "0.2.15")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "rules_pkg", version = "1.0.1", dev_dependency = True)
Loading
Loading