forked from facebook/buck2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proto_defs.bzl
78 lines (71 loc) · 2.4 KB
/
proto_defs.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@fbcode//buck2:buck_rust_binary.bzl", "buck_rust_binary")
load("@fbcode_macros//build_defs:export_files.bzl", "export_file")
load("@fbcode_macros//build_defs:native_rules.bzl", "buck_genrule")
load("@fbcode_macros//build_defs:rust_library.bzl", "rust_library")
def rust_protobuf_library(
name,
srcs,
build_script,
protos,
build_env = None,
deps = None,
test_deps = None,
doctests = True):
build_name = name + "-build"
proto_name = name + "-proto"
buck_rust_binary(
name = build_name,
srcs = [build_script],
crate_root = build_script,
deps = [
"fbcode//buck2/app/buck2_protoc_dev:buck2_protoc_dev",
],
)
build_env = build_env or {}
build_env.update(
{
"PROTOC": "$(exe fbsource//third-party/protobuf:protoc)",
"PROTOC_INCLUDE": "$(location fbsource//third-party/protobuf:google.protobuf)",
},
)
buck_genrule(
name = proto_name,
srcs = protos,
# The binary doesn't look at the command line, but with Buck1, if we don't have $OUT
# on the command line, it doesn't set the environment variable, so put it on.
cmd = "$(exe :{}) --required-for-buck1=$OUT".format(build_name),
env = build_env,
out = ".",
)
rust_library(
name = name,
srcs = srcs,
doctests = doctests,
env = {
# This is where prost looks for generated .rs files
"OUT_DIR": "$(location :{})".format(proto_name),
},
named_deps = {
# "prost" is https://github.com/tokio-rs/prost, which is used
# to generate Rust code from protobuf definitions.
"generated_prost_target": ":{}".format(proto_name),
},
labels = [
"generated_protobuf_library_rust",
],
deps = [
"fbsource//third-party/rust:prost",
] + (deps or []),
test_deps = test_deps,
)
# For python tests only
for proto in protos:
export_file(
name = proto,
)