using protobufs with bazel?

1,345 views
Skip to first unread message

JI Ioannidis

unread,
Jul 14, 2016, 5:05:04 PM7/14/16
to bazel-discuss
Environment:

Environment: 
bazel built from source (and output/bazel moved to ~/bin/):
 ~/workspace/bazel$ git rev-parse HEAD 
e3dc62f2b520d6698776754ef70e916300895330

repo has protobuf (and others) as submodules under third_party:

~/workspace/foo$ git submodule status  
546819b1d91d666c9e98a061fe2ff19f63cac9a7 third_party/gflags (v2.1.0-149-g546819b)
d406cb18c3d73995cec51fc6b39a2aea821b68c1 third_party/googletest (remotes/origin/BillyDonahue-patch-2-1-gd406cb1)
3fb819fd2a51991a54c946ae8c8005f7c25dd2eb third_party/grpc (release-0_15_1-559-g3fb819f)
042993b3dd8c52f979870c91ea7fcbcf0dcf94a0 third_party/protobuf (v3.0.0-beta-2-627-g042993b)


There is an empty WORKSPACE file at the top of the foo repo.  Now:
 
 
$ cat WORKSPACE
$ cat src/ttt/BUILD  
load("//third_party/protobuf:protobuf.bzl", "cc_proto_library")

cc_proto_library(
 name = "foo",
 srcs = ["foo.proto"],
)
$ cat src/ttt/foo.proto  
syntax = "proto3";

message Bar {
 string description = 1;
}
$ bazel build //src/ttt:foo
.
ERROR: /home/ji/workspace/rp/src/ttt/BUILD:3:1: no such package '': BUILD file not found on package path and referenced by '//src/ttt:foo'.
ERROR: Analysis of target '//src/ttt:foo' failed; build aborted.
INFO: Elapsed time: 2.127s

Line 3 is the invocation of cc_proto_library. I searched this group and I can see that others have had a similar problem in the past, but as far as I can tell, I'm doing the right thing. I can successfully build  a simple C++ program in another directory of the same repo, so I know bazel is properly installed. 

Any hints?

Thanks,

/ji
 
 

Brian Edmonds

unread,
Jul 19, 2016, 6:34:25 PM7/19/16
to JI Ioannidis, bazel-discuss
> ERROR: /home/ji/workspace/rp/src/ttt/BUILD:3:1: no such package '': BUILD
> file not found on package path and referenced by '//src/ttt:foo'.

When using cc_proto_library() I find I always have to explicitly specify
its protoc and default_runtime arguments to point to the targets inside
the iexternal protobuf workspace. Something like:

cc_proto_library(
name = "foo",
srcs = ["foo.proto"],
protoc = "//third_party/protobuf:protoc",
default_runtime = "//third_party/protobuf:protobuf_lite",
)

But I'm using git_repository() in my WORKSPACE rather than importing the
source into third_party, so it's possible you're hitting a different
problem, but hopefully this helps you.

Brian.

JI Ioannidis

unread,
Jul 28, 2016, 2:26:14 AM7/28/16
to bazel-discuss, jay...@gmail.com
It did:

In WORKSPACE:

git_repository(
  name = "protobuf",
  remote = "https://github.com/google/protobuf",
  commit = "e7982e409deab9cb4390dd574441604e846caf7f", # master on 20160727
)

in the BUILD file further down the directory tree:

load("@protobuf//:protobuf.bzl", "cc_proto_library")   

cc_proto_library(   
  name = "protolib",   
  srcs = glob(["*.proto"]),   
  protoc = "@protobuf//:protoc",   
  default_runtime = "@protobuf//:protobuf",   
)

Now building a cc_binary works

However, I still can't get grpc working (specifying use_grpc_plugin = True complains about the protocol compiler missing. I traced the target to the grpc repo, but it's only defined for objc, and even then it says "not supported" :(

Any idea when it will be?

Thanks again,


/ji

Brian.
Reply all
Reply to author
Forward
0 new messages