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

New protobuf workflow won't output generated files #836

Closed
trystanj opened this issue Sep 16, 2017 · 6 comments
Closed

New protobuf workflow won't output generated files #836

trystanj opened this issue Sep 16, 2017 · 6 comments

Comments

@trystanj
Copy link

trystanj commented Sep 16, 2017

I thought I would give the new protobuf rules a try, so perhaps they are not ready for primetime - forgive me if I'm jumping the gun or misunderstanding something! I'm still a bit new to Bazel.

When trying to build, I'm getting an error about outputting the generated files:

➜  bazel-proto git:(master) ✗ bazel build //...
INFO: Found 5 targets...
ERROR: /Users/trystanjohnson/Documents/go/src/github.com/trystanj/bazel-proto/proto/BUILD.bazel:10:1: output 'proto/github.com/trystanj/bazel-proto/proto/demo.pb.go' was not created.
ERROR: /Users/trystanjohnson/Documents/go/src/github.com/trystanj/bazel-proto/proto/BUILD.bazel:10:1: not all outputs were created or valid.

If I generate the file myself it works:

➜  proto git:(master) ✗ protoc --go_out=. demo.proto
➜  proto git:(master) ✗ cd ..
➜  bazel-proto git:(master) ✗ go run main.go
2017/09/16 11:24:20 OH HAI
2017/09/16 11:24:20 demo.Very, hi
2017/09/16 11:24:20 Helper: hi

Am I missing a step or configuration in my Bazel setup?

Here's the minimal example I'm trying to get working: https://github.com/trystanj/bazel-proto

Bazel version

➜  bazel-proto git:(master) ✗ bazel version
Build label: 0.5.4-homebrew
Build target: bazel-out/darwin_x86_64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Aug 25 16:55:29 2017 (1503680129)
Build timestamp: 1503680129
Build timestamp as int: 1503680129
@ianthehat
Copy link
Contributor

It's because you are not telling the proto compiler what package the proto should generate.
You need

option go_package = "github.com/trystanj/bazel-proto/proto";

in the proto file.
The generated files change with that option, and the rules assume that it was set correctly so they complain that the files they were expecting did not get generated by protoc.
There might be a way to make the message a little clearer, and when the changes to gazelle land it will also warn you if you have not done this.

@trystanj
Copy link
Author

Amazing! I had that option off since IIRC it caused trouble with the previous proto mechanism.

This is great - let me know if/how I can help with documentation! I put this together by poking around back and forth in the examples dir, but it's little things like this that I missed. Time to apply this to my real project!

@ianthehat
Copy link
Contributor

Glad it works for you.
If you find anything you don't like or can't do, please let me know, right now I am still happy to make radical changes if needed, but that won't last for long!
I am currently trying to do the final touches to make the go rules work properly on windows, and then after that I will be writing lots of documentation for the new state of all the rules, not just the proto parts. I am fairly hopeful that the new structure of rules, providers and toolchains is reasonable stable now and worth putting the effort into proper documentation.

@trystanj
Copy link
Author

trystanj commented Sep 16, 2017

Will gazelle be able to generate the BUILD files on its own? They're somewhat finnicky and tedious.

One thing that wasn't clear to me - and may still not be - is the interaction between proto_library and go_proto_library. I take it there's a sort of pipeline happening, and if I had to guess I'd say that proto_library compiles the protobuf, while go_proto_library is the (for lack of a better word) "implementation" / dependency declaration of using that compiled proto?

@ianthehat
Copy link
Contributor

Yes, gazelle will generate both the proto_library rules and the go_proto_library rules correctly for you, probably by sometime next week. That was the design trade off we decided to accept, the rules are slightly verbose and you have to make sure some things match, but they are automatically generated so you should not need to care, and it gives the increased flexibility to cover all the use cases.

The proto_library rule is language neutral, and used by all langauges. It compiles proto to a proto descriptor. The go_proto_library takes the proto descriptor and uses it to generate both go sources and a go library. If you don't need any other sources in the package, you can just use that library as it is, but if you need to add more sources and deps to it, then you embed it into a normal go_library instead.

@trystanj
Copy link
Author

Sounds good to me! I've just finished converting our project to use this new structure, and it's much cleaner. Definitely a step forward! Looking forward to gazelle generation and the next big release!

I'll close this issue - thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants