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

[FR]: Add example for cc_proto_library #21

Open
malt3 opened this issue Jul 24, 2024 · 2 comments
Open

[FR]: Add example for cc_proto_library #21

malt3 opened this issue Jul 24, 2024 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@malt3
Copy link

malt3 commented Jul 24, 2024

What is the current behavior?

I can't quite get cc_proto_library to work and there is no end-to-end example for C++.

Describe the feature

I'd like to enable --incompatible_enable_proto_toolchain_resolution and use a precompiled protoc.
I got this mostly working:

MODULE.bazel:

bazel_dep(name = "rules_proto", version = "6.0.2")
bazel_dep(name = "toolchains_protoc", version = "0.3.1")

protoc = use_extension("@toolchains_protoc//protoc:extensions.bzl", "protoc")
protoc.toolchain(
    # Creates a repository to satisfy well-known-types dependencies such as
    # deps=["@com_google_protobuf//:any_proto"]
    google_protobuf = "com_google_protobuf",
    version = "LATEST",
)

use_repo(protoc, "com_google_protobuf", "toolchains_protoc_hub", "toolchains_protoc_hub.linux_x86_64")

register_toolchains("@toolchains_protoc_hub//:all")
register_toolchains("//toolchain:protoc_cc_toolchain")

toolchain/BUILD:

load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain")

proto_lang_toolchain(
    name = "protoc_cc",
    runtime = "@toolchains_protoc_hub.linux_x86_64//:prebuilt_protoc_toolchain",
    command_line = "--cpp_out=$(OUT)",
    progress_message = "Generating C++ proto_library %{label}",
    toolchain_type = "@rules_cc//cc/proto:toolchain_type",
)

BUILD:

load("@rules_proto//proto:defs.bzl", "proto_library")

cc_proto_library(
    name = "foo_cc_proto",
    deps = [":foo_proto"],
)

proto_library(
    name = "foo_proto",
    srcs = ["foo.proto"],
    features = ["-asan"],
)

foo.proto:

syntax = "proto3";

package foo;

message Bar {
    uint64 baz = 1;
}

Output:

fatal error: google/protobuf/runtime_version.h: No such file or directory

edit

I think the runtime attribute of proto_lang_toolchain should be something like @com_google_protobuf//:protoc_lib.
I’ll experiment some more.

@malt3 malt3 added the enhancement New feature or request label Jul 24, 2024
@alexeagle
Copy link
Member

In theory, C++ doesn't have to be covered here because the official Protobuf documentation says that C++ developers ought to build it from source:
https://github.com/protocolbuffers/protobuf#protobuf-compiler-installation

If you author C++ code then it's reasonable to require every engineer on your team has a functioning local toolchain, or you've configured Bazel with a hermetic toolchain.

In practice of course it's ALWAYS annoying to compile protoc and watch its gcc warnings scrolling by, and I'd love to have C++ here too!

@alexeagle alexeagle added the help wanted Extra attention is needed label Aug 23, 2024
@alexeagle
Copy link
Member

Tagging @thesayyn who might recall whether any work happened with cc_proto_library to make this possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants