bazelbuild / bazelbuild/rules_closure
Issues building protos, and using them
- Dominant language
- Java
- Stars
- 159
- Forks
- 111
- PR merge metrics
- No merged PRs in 30d
Description
Hey there `rules_closure` folks,
I was wondering if someone could help me out with compilation and use of protos from Soy (in JS and Java). First things first, I'm aware there is not yet support in `rules_closure` for proto use from Java, although I was not able to answer that question fully for JS.
`SomeModel.proto`:
```protobuf
syntax = "proto3";
package sample;
message Sample {
string example = 1;
}
```
`WORKSPACE`:
```
workspace(name = "some_workspace")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
## Closure
http_archive(
name = "io_bazel_rules_closure",
strip_prefix = "rules_closure-9e82c789d83ddc57e98e11ecb6c0f0479ebbbb5b",
url = "https://github.com/bazelbuild/rules_closure/archive/9e82c789d83ddc57e98e11ecb6c0f0479ebbbb5b.zip")
```
`BUILD`:
```
package(default_visibility = ["//visibility:public"])
load("@io_bazel_rules_closure//closure:defs.bzl",
"closure_js_proto_library",
"closure_proto_library")
# Protos
proto_library(
name = "SomeModel",
srcs = ["SomeModel.proto"])
closure_js_proto_library(
name = "SomeModel_js_proto",
srcs = ["SomeModel.proto"])
closure_proto_library(
name = "SomeModel_closure_proto",
deps = [":SomeModel"])
```
I can't get Soy to recognize the proto types, whether I'm using `closure_js_proto_library` or `closure_proto_library`. The behavior seems rather strange:
### When using `closure_js_proto_library`:
- I depend on it from a `closure_js_template_library` rule, like so:
```
closure_js_template_library(
name = "labtesting-tpl",
srcs = ["labtesting.soy"],
deps = ["@schema//:SomeModel_js_proto"])
```
- But I get the following output (with `verbose_failures` on):
```bash
INFO: Analysed 18 targets (159 packages loaded, 2483 targets configured).
INFO: Found 18 targets...
ERROR: /private/var/tmp/_bazel_sam/.../external/.../BUILD.bazel:25:1: Generating JavaScript Protocol Buffer file @schema//:SomeModel_closure_proto_gen failed (Exit 1): bash failed: error executing command
(cd /private/var/tmp/_bazel_sam/.../execroot/SomeWorkspace && \
exec env - \
PATH='(really-long-path-variable)' \
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/external/com_google_protobuf/protoc -I. --js_out=library=SomeModel_closure_proto,error_on_name_conflict,binary:bazel-out/darwin-fastbuild/genfiles/external/schema/SomeModel --descriptor_set_out=bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel_closure_proto.descriptor bazel-out/darwin-fastbuild/genfiles/external/schema/SomeModel-descriptor-set.proto.bin')
Execution platform: @bazel_tools//platforms:host_platform
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:2:1: Interpreting non ascii codepoint 179.
[libprotobuf WARNING external/com_google_protobuf/src/google/protobuf/compiler/parser.cc:562] No syntax specified for the proto file: bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:2:1: Expected top-level statement (e.g. "message").
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:2:2: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:3:39: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:3:73: Interpreting non ascii codepoint 145.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:3:74: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:4:13: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:5:5: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:6:7: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:7:7: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:8:5: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:10:7: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:11:7: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:13:8: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:14:5: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:15:5: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:16:7: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:17:5: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:17:7: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:18:5: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:18:7: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:19:7: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:20:1: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:20:18: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:21:27: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:22:10: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:23:14: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:24:7: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:25:14: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:26:10: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:27:48: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:27:70: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:27:72: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:27:73: Interpreting non ascii codepoint 162.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:27:74: Invalid control characters encountered in text.
bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin:27:80: Invalid control characters encountered in text.
INFO: Elapsed time: 52.657s, Critical Path: 24.80s
INFO: 581 processes: 553 local, 28 worker.
FAILED: Build did NOT complete successfully
```
- When I examine the file `bazel-out/darwin-fastbuild/genfiles/external/schema/.../SomeModel-descriptor-set.proto.bin`, it contains a binary representation of the proto. So, it *does* compile the proto.
- I can also accurately find a JS representation of the proto, in `bazel-out`. It's in Closure format (`goog.require`/`goog.provide`), which is how I want it, but I don't see how I can reference that file.
It seems to me, that one of `closure_js_template_library` or `closure_js_proto_library` is expecting the protos to be in source form (hence the message `No syntax specified for the proto file`)? What am I doing wrong?
Contributor guide
Research direction
Start with the WORKSPACE and BUILD examples, then inspect the closure_js_proto_library, closure_proto_library, and closure_js_template_library entry points involved in the failing command. Reproduce the sample build and trace how SomeModel-descriptor-set.proto.bin is consumed; done means the proto builds without treating its binary descriptor as source and can be used from Soy in the requested targets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, javascript
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100