bazelbuild / bazelbuild/rules_closure

Protobuf support for closure_java_template_library

Open
#225 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
159
Forks
111
PR merge metrics
No merged PRs in 30d

Description

`closure_java_template_library()` does not support protobuf yet. The following attempt was made before I learned that, should not work at the moment, may be of wrong syntax, and becomes a feature request.

Related announcement and discussion:
* https://groups.google.com/forum/#!msg/closure-rules-announce/GocpXwXE8FI/T3Ixl3ZMAgAJ
* https://github.com/google/closure-templates/issues/99


Bazel version: 0.10.0
rules_closure: git repo HEAD

`WORKSPACE`:
```python
git_repository(
name = "io_bazel_rules_closure",
commit = "08039ba8ca59f64248bb3b6ae016460fe9c9914f",
remote = "https://github.com/bazelbuild/rules_closure",
)

load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")

closure_repositories()
```

`BUILD`:
```python
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_java_template_library")

closure_java_template_library(
name = "test_soy_java",
srcs = ["test.soy"],
java_package = "hello.test",
deps = [
":user_java_proto",
],
)

java_proto_library(
name = "user_java_proto",
deps = [
":user_proto",
],
)

proto_library(
name = "user_proto",
srcs = ["user.proto"],
)
```

`user.proto`:
```protobuf
syntax = "proto3";

option java_package = "hello";

package hello;

message User {
string name = 1;
}
```

`test.soy`:
```soy
{namespace hello}

{template .test}
{@param user: hello.User}
{$user.name}
{/template}
```

`bazel build :test_soy_java` fails with:
```
ERROR: /tmp/hello/BUILD:3:1: Generating SOY v2 Java files //:test_soy_java_files failed (Exit 1): bash failed: error executing command
(...
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/external/com_google_template_soy/SoyParseInfoGenerator --outputDirectory=bazel-out/k8-dbg/genfiles --javaPackage=hello.test --javaClassNameSource=filename --allowExternalCalls=1 $(cat bazel-out/k8-dbg/genfiles/test_soy_java_files__srcs) $(cat bazel-out/k8-dbg/genfiles/test_soy_java_files__deps)')
errors during Soy compilation
bazel-out/k8-dbg/bin/libuser_proto-speed.jar:1: error: parse error at 'P': expected {namespace or {delpackage
PK
^

bazel-out/k8-dbg/genfiles/user_proto-speed-src.jar:1: error: parse error at 'P': expected {namespace or {delpackage
PK
^

test.soy:4: error: Unknown type 'hello.User'.
{@param user: hello.User}
^
3 errors
```

`SoyParseInfoGenerator` needs `--protoFileDescriptors` generated by `protoc user.proto --descriptor_set_out` to complete the task.

Do you have plan to support Protocol buffer for `closure_java_template_library`?

Thanks.

Contributor guide

Open the contributing guide

Research direction

Start with closure_java_template_library in closure/defs.bzl and trace how its SoyParseInfoGenerator invocation assembles dependencies. Compare the failing BUILD example with the generator's --protoFileDescriptors requirement and inspect existing protobuf or descriptor-generation rules. Done means the shown hello.User parameter compiles through bazel build :test_soy_java.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.