Document usage with nix provided protobuf
Is your feature request related to a problem? Please describe.
protobuf is used under the hood in a number of rules_X and in some of the builtin packages. It should be possible to use a nix provided protobuf. I played with this a little bit, but things got a little hairy at some point, and figured it would be better to incorporate this directly into rules_nixpkgs
Describe the solution you'd like If it is already possible, and easy- it'd be nice to have documentation for it. If it is not super easy as is, it might be worth looking into how to properly setup protobuf.
Describe alternatives you've considered
I just use com_google_protobuf, but it doesn't have nix level caching
Additional context Happy to spend sometime on this myself, just want to post. I understand if it's a wontfix or non-starter on you end- just let me know if you would welcome the contribution (either documentation, or a rule or something).
Here was my initial attempt:
# TODO: Resolve Compilation with nix provided package.
# Thinks everything is c...
nixpkgs_package(
name = "com_google_protobuf",
attribute_path = "protobuf",
build_file_content = """
sh_binary(
name = "protoc",
srcs = ["bin/protoc"],
data = [":protoc_lib"] + glob(["include/**/*.hpp", "include/**/*.inc", "include/**/*.h"], allow_empty = True),
visibility = ["//visibility:public"],
)
cc_library(
name="protoc_lib",
# copts = ["-x c++", "-std=c++14", "-std=c++17", "-D_GLIBCXX_USE_CXX11_ABI=1",],
srcs = glob(["lib/**/*.so*", "lib/**/*.dylib", "lib/**/*.a"], allow_empty = True),
hdrs = glob(["include/**/*.hpp", "include/**/*.inc", "include/**/*.h"], allow_empty = True),
includes = ["include", "include/google", "include/google/protobuf"],
visibility = ["//visibility:public"],
linkopts = ["-lpthread", "-lm"],
copts = [
"-DHAVE_ZLIB",
"-Wmissing-field-initializers",
"-Woverloaded-virtual",
"-Wno-sign-compare",
],
)
cc_library(
name = "protobuf_headers",
# copts = ["-x c++", "-std=c++14", "-std=c++17", "-D_GLIBCXX_USE_CXX11_ABI=1",],
hdrs = glob(["include/**/*.h", "include/**/*.inc"]),
includes = ["include", "include/google", "include/google/protobuf"],
visibility = ["//visibility:public"],
)
""",
repositories = {"nixpkgs": "@nixpkgs//:default.nix"},
)
replacing
# Protobuf: Used for data exchange and storage.
http_archive(
name = "com_google_protobuf",
#sha256 = "0a1dbc272f932056200d819147116fd38e0a02889b80fa8b82ce4b8c8857488f",
strip_prefix = "protobuf-3.19.3",
urls = ["https://github.com/google/protobuf/archive/v3.19.3.tar.gz"],
)
But this causes all other cc deps to fail.
Pinging @googleson78 who IIRC looked into a solution to this a while ago.
The now open sourced Nix+Bazel Codelab contains some instructions on forcing a source built protoc on NixOS. This is not the same that this issue is asking about, but part of the approach may be relevant in this case.