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

Generate ES6-style code (classes, exports, imports) #156

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
71e76b3
WIP on ES6-style code generation (imports and implementation).
gonzojive Dec 4, 2022
611d03d
Further WIP towards ES6-style code generation.
gonzojive Dec 5, 2022
e7e3a45
Maybe 70% complete ES6 implementation generation
gonzojive Dec 5, 2022
a90de85
Start to attempt to rework how references to imported types work.
gonzojive Dec 5, 2022
b2c7b46
Define TypeNames class for referencing message and enum types in gene…
gonzojive Dec 5, 2022
6eff0cb
Use "Compile Commands Extractor for Bazel" to get C++ autocomplete.
gonzojive Jan 4, 2023
5108a8e
fixup! Use "Compile Commands Extractor for Bazel" to get C++ autocomp…
gonzojive Jan 4, 2023
68ab15f
Output // proto_import: "path/to/dep.proto" comments to assist post-p…
gonzojive Jan 10, 2023
e16db87
Fix generator so it outpus message constructor.
gonzojive Jan 14, 2023
ed259b3
add .map file to .gitignore
gonzojive Jan 18, 2023
8d27122
Fix toObject codegen.
gonzojive Jan 18, 2023
1167b4e
Fix GenerateBytesWrapper and well-known type ES6 codegen.
gonzojive Feb 5, 2023
2df217e
Rename imports in ES6 mode if there are possible identifier conflicts.
gonzojive Feb 5, 2023
5802a07
Delete unused ExportedNamesOfDeps.
gonzojive Feb 5, 2023
d31e215
Fix generation of top-level enums.
gonzojive Mar 9, 2023
36960c2
Fix serialization and deserialization generated code.
gonzojive Mar 9, 2023
ea63156
Fix repeated field wrapper class name generation
egormodin Mar 10, 2023
2a80405
Fix repeated field wrapper class name generation - Red.
gonzojive Mar 10, 2023
e5011de
Fix generated code for repeated field 'addFoo' helper methods.
gonzojive Mar 10, 2023
dfa5a70
Fix TypeNames so that fields with types defined in same file work.
gonzojive Mar 10, 2023
03e6f43
Add 'static' keyword for enums defined inside the class
egormodin Mar 10, 2023
7193703
Add 'static' keyword for enums generatef from oneof fields
egormodin Mar 10, 2023
d3ce92c
Fix treatment of nested messages by TypeNames::JsExpression.
reddaly Mar 13, 2023
dc42c5a
Delete leftover debug comment in generated code.
reddaly Mar 13, 2023
885b9cd
Fix has and clear methods (#6)
egormodin Mar 17, 2023
978cfa4
Add github action to run bazel build //generator/... (#7)
gonzojive Mar 19, 2023
7f11c3e
Support protobuf `extend` keyword when in `kImportEs6` mode (#8)
davemasselink Jul 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file contains Bazel settings to apply on CI only.
# It is referenced with a --bazelrc option in the call to bazel in ci.yaml

# Debug where options came from
build --announce_rc
# This directory is configured in GitHub actions to be persisted between runs.
build --disk_cache=~/.cache/bazel
build --repository_cache=~/.cache/bazel-repo
# Don't rely on test logs being easily accessible from the test runner,
# though it makes the log noisier.
test --test_output=errors
# Allows tests to run bazelisk-in-bazel, since this is the cache folder used
test --test_env=XDG_CACHE_HOME
88 changes: 88 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: CI

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main, es6]
pull_request:
branches: [main, es6]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

concurrency:
# Cancel previous actions from the same PR: https://stackoverflow.com/a/72408109
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
# matrix-prep-* steps generate JSON used to create a dynamic actions matrix.
# Insanely complex for how simple this requirement is inspired from
# https://stackoverflow.com/questions/65384420/how-to-make-a-github-action-matrix-element-conditional

matrix-prep-bazelversion:
# Prepares the 'bazelversion' axis of the test matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: bazel_from_bazelversion
run: echo "bazelversion=$(head -n 1 .bazelversion)" >> $GITHUB_OUTPUT
# bazel 5 testing disabled for now due to
# https://github.com/aspect-build/bazel-lib/issues/392
# - id: bazel_5
# run: echo "bazelversion=5.3.2" >> $GITHUB_OUTPUT
outputs:
# Will look like ["<version from .bazelversion>"]
bazelversions: ${{ toJSON(steps.*.outputs.bazelversion) }}

bazel-build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

needs:
- matrix-prep-bazelversion

# Run bazel test in each workspace with each version of Bazel supported
strategy:
fail-fast: false
matrix:
bazelversion: ${{ fromJSON(needs.matrix-prep-bazelversion.outputs.bazelversions) }}
folder:
- "."

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

# Cache build and external artifacts so that the next ci build is incremental.
# Because github action caches cannot be updated after a build, we need to
# store the contents of each build in a unique cache key, then fall back to loading
# it on the next ci run. We use hashFiles(...) in the key and restore-keys- with
# the prefix to load the most recent cache for the branch on a cache miss. You
# should customize the contents of hashFiles to capture any bazel input sources,
# although this doesn't need to be perfect. If none of the input sources change
# then a cache hit will load an existing cache and bazel won't have to do any work.
# In the case of a cache miss, you want the fallback cache to contain most of the
# previously built artifacts to minimize build time. The more precise you are with
# hashFiles sources the less work bazel will have to do.
- name: Mount bazel caches
uses: actions/cache@v3
with:
path: |
~/.cache/bazel
~/.cache/bazel-repo
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
restore-keys: bazel-cache-

- name: Configure Bazel version
working-directory: ${{ matrix.folder }}
run: echo "${{ matrix.bazelversion }}" > .bazelversion

- name: bazel build //generator/...
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
XDG_CACHE_HOME: ~/.cache/bazel-repo
working-directory: ${{ matrix.folder }}
run: bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc --bazelrc=.github/workflows/ci.bazelrc build //generator/...
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ bazel-*
/testproto_libs1.js
/testproto_libs2.js
/google-protobuf.js
/google-protobuf.js.map

### Automatically added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor
# Ignore the `external` link (that is added by `bazel-compile-commands-extractor`). The link differs between macOS/Linux and Windows, so it shouldn't be checked in. The pattern must not end with a trailing `/` because it's a symlink on macOS/Linux.
/external
# Ignore links to Bazel's output. The pattern needs the `*` because people can change the name of the directory into which your repository is cloned (changing the `bazel-<workspace_name>` symlink), and must not end with a trailing `/` because it's a symlink on macOS/Linux.
/bazel-*
# Ignore generated output. Although valuable (after all, the primary purpose of `bazel-compile-commands-extractor` is to produce `compile_commands.json`!), it should not be checked in.
/compile_commands.json
# Ignore the directory in which `clangd` stores its local index.
/.cache/
17 changes: 17 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@ protobuf_deps()

load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()

# Hedron's Compile Commands Extractor for Bazel
# https://github.com/hedronvision/bazel-compile-commands-extractor
#
# Run bazel run @hedron_compile_commands//:refresh_all to get autocomplete
# working in VS Code and other editors.
http_archive(
name = "hedron_compile_commands",

# Replace the commit hash in both places (below) with the latest, rather than using the stale one here.
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/ed994039a951b736091776d677f324b3903ef939.tar.gz",
strip_prefix = "bazel-compile-commands-extractor-ed994039a951b736091776d677f324b3903ef939",
# When you first run this tool, it'll recommend a sha256 hash to put here with a message like: "DEBUG: Rule 'hedron_compile_commands' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = ..."
)
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
hedron_compile_commands_setup()