db-console: bazel build for protobufjs clients#64065
db-console: bazel build for protobufjs clients#64065koorosh wants to merge 3 commits intocockroachdb:masterfrom
Conversation
f1d60ae to
2da0367
Compare
|
@rickystewart , @jlinder , I just started working on bazel build process for Lines 1324 to 1334 in afaea24 These changes don't affect current build process with Makefile and aren't included into main bazel build for entire project. |
| @@ -0,0 +1,108 @@ | |||
| "implementation is borrowed from https://github.com/bazelbuild/rules_nodejs/blob/stable/examples/protobufjs/defs.bzl" | |||
There was a problem hiding this comment.
I think this docstring pattern isn't really used anywhere else in tree? You can just replace this with a comment.
| name = "db-console_oss_js_proto", | ||
| out_name = "protos", | ||
| protos = [ | ||
| "//pkg/server/serverpb:admin_proto", |
There was a problem hiding this comment.
I understand you probably separated these protos out into individual targets so we could compile only the protos that HAVE to be in this JS library. Does it make a huge difference to just compile //pkg/server/serverpb:serverpb_proto, though? What's the impact? Code size in the generated file? Can/does that get squashed later in minification?
There was a problem hiding this comment.
Good point! The size of generated file was the primary concern for doing this but you're right, it could be reduced with minification and tree shaking of required code in generated file!
|
|
||
| # Define proto_library per each .proto file according to recommended code organization: | ||
| # https://docs.bazel.build/versions/master/be/protocol-buffer.html#proto_library | ||
| proto_library( |
There was a problem hiding this comment.
So, this stuff is all auto-generated (if you check out the failing lint job, you'll see that it's yelling at you to run make bazel-generate -- but if you do, that'll trample all the changes you've made here).
Gazelle auto-generates the structure of the proto rules so that we don't have to manually update these dependencies ourselves. Any solution we arrive at for this will have to honor all the existing Gazelle-based machinery here. A couple high-level options (sorry, these are all hand-wavy, it's a complicated problem):
- Exclude the
.protofiles inpkg/server/serverpbfrom being managed by Gazelle. This would mean that any change to the dependencies of any of the.protofiles in here would have to be manually implemented in theBUILDfiles. As far as I'm concerned, this is a worst-case scenario -- I think we would have lots of angry engineers if we forced that on them. - Maybe you can adjust the
gazelle:proto_groupdirective in this directory to achieve the same thing, where we have oneproto_libraryper.protofile? Worth playing with and seeing what that gets you. - Gazelle is supposed to support extensions to accomplish this sort of thing. I am not sure how much work it would be to hack something together that accomplishes the same thing as this PR, but it is worth at least considering because it would be really nice to have one tool that's responsible for all our
BUILDfiles in every language. (Edit: To be clear, I suspect this is probably more work than it's worth, but nothing's stopping us from looking.)
There was a problem hiding this comment.
@rickystewart , thanks for detailed suggestions! I would prefer to avoid manual changes in .proto files as well.
Taking into account that generated JS protobuf client can be minified to reduce file size, it might be okay just rely on generated serverpb_proto proto.
| attrs = {"protos": attr.label_list(providers = [ProtoInfo])}, | ||
| ) | ||
|
|
||
| def protobufjs_library(name, out_name, protos, **kwargs): |
There was a problem hiding this comment.
I didn't thoroughly review this, but it looks as I would expect.
2da0367 to
1e0112f
Compare
Previously, protobufjs cli build relied on dependencies from `pkg/ui` package and required additional installation steps to "fix" known installation issue for "protobufjs" package. Now, these dependencies are defined in `pkg/ui/src/js` directory with additional dependencies required for "protobufjs" package. It resolves the problem with additional installation steps and makes build process straightforward. Release note: None
This change introduces new bazel build targets: - pkg/ui/src/js - pkg/ui/ccl/ui/src/js These targets are intended to build protobufjs clint libs for farther usage by db-console (`pkg/ui`) and as source for `crdb-protobuf-client` package which is published to NPM registry. In addition to new targets, `pkg/server/serverpb` BUILD targets are refactored as well - single `serverpb_proto` target is removed in favor of separate `protobuf_library` targets per each .proto file. It allows to reuse them in different targets. Release note: None
1e0112f to
df1d089
Compare
|
Not actual anymore |
This PR includes two parts (bazel definitions and changes in JS packages) which are better to review per commit.
Related to #59329
You can build these packages with following commands:
Note: this change doesn't integrate new build targets into the main bazel build for entire project.
pkg/uipackageand required additional installation steps to "fix" known installation issue
for "protobufjs" package (see
pkg/ui/bin/gen-protobuf-cli-deps.js).Now, these dependencies are defined in
pkg/ui/src/jsdirectory with additionaldependencies required for "protobufjs" package. It resolves the problem with
additional installation steps and makes build process straightforward.
pkg/ui/src/jspkg/ui/ccl/ui/src/jsThese targets are intended to build protobufjs client libs for
farther usage by db-console (
pkg/ui) and as source forcrdb-protobuf-clientpackage which is published to NPM registry.In addition to new targets,
pkg/server/serverpbBUILD targetsare refactored as well - single
serverpb_prototarget is removedin favor of separate
protobuf_librarytargets per each .proto file.It allows to reuse them in different targets.
Release note: None