Allocate enough memory for the InputOver2G test.
[google-protobuf.git] / rust / BUILD
blob99c1c95b5dc534c4e8e3f56ad140c2049fd14a3b
1 # Protobuf Rust runtime packages.
3 load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
4 load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files", "strip_prefix")
5 load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
6 load("//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain")
7 load("//rust:dist.bzl", "pkg_cross_compiled_binaries")
9 licenses(["notice"])
11 package_group(
12     name = "protobuf_internal",
13     packages = [
14         "//rust/...",
15         "//src/google/protobuf/...",
16     ],
19 # The current Rust Protobuf runtime for the build. Depending on the value of
20 # `:rust_proto_library_kernel` build setting it forwards to the cpp or upb kernels. This is the
21 # target that users are expected to depend on.
23 # Rust gencode (via `rust_upb_proto_library` and `rust_cc_proto_library`) doesn't depend on this
24 # target, instead, it depends on the kernel-specific libraries directly. The reason is that we need
25 # to be able to use both kernels in the same build. That allows us to have one TAP config for both
26 # kernels, and to run tests using a single Blaze invocation.
28 # WARNING: It's critical that users do not end up using Rust Protobufs with multiple kernels in
29 # their binaries. Currently this is achieved by using bzl visibility on kernel-specific rules.
30 # TODO: Hide the kernel-specific targets once we can restrict a target visibility to a
31 # rule.
32 rust_library(
33     name = "protobuf",
34     srcs = ["protobuf.rs"],
35     rustc_flags = select({
36         ":use_upb_kernel": ["--cfg=upb_kernel"],
37         "//conditions:default": ["--cfg=cpp_kernel"],
38     }),
39     visibility = ["//visibility:public"],
40     deps = select({
41         ":use_upb_kernel": [":protobuf_upb"],
42         "//conditions:default": [":protobuf_cpp"],
43     }),
46 # This list contains kernel-agnostic logic and simple kernel-specific logic controlled by
47 # `#[cfg(...)]` attributes. That forces us to compile these files twice, once for each kernel. As a
48 # result these files are included in both `:protobuf_upb` and `:protobuf_cpp`.
49 # This is in principle identical to how we compile regular Rust source files twice
50 # (once for production, and once for unit testing).
52 # shared.rs is the root of the crate and has public items re-exported in protobuf.rs for user use.
53 PROTOBUF_SHARED = [
54     # go/keep-sorted start
55     "codegen_traits.rs",
56     "cord.rs",
57     "enum.rs",
58     "internal.rs",
59     "map.rs",
60     "optional.rs",
61     "prelude.rs",
62     "primitive.rs",
63     "proto_macro.rs",
64     "proxied.rs",
65     "repeated.rs",
66     "shared.rs",
67     "string.rs",
68     # go/keep-sorted end
71 # All Rust source files; this is used for packaging up a crate.
72 ALL_RUST_SRCS = PROTOBUF_SHARED + [
73     # go/keep-sorted start
74     "cpp.rs",
75     "gtest_matchers.rs",
76     "gtest_matchers_impl.rs",
77     "protobuf.rs",
78     "upb.rs",
79     "utf8.rs",
80     # go/keep-sorted end
83 # The Rust Protobuf runtime using the upb kernel.
85 # `rust_upb_proto_library` implicitly depends on this target. This target cannot depend on
86 # `:rust_proto_library_kernel` build setting; it has to be fully functional under any value of that
87 # setting.
88 rust_library(
89     name = "protobuf_upb",
90     srcs = PROTOBUF_SHARED + ["upb.rs"],
91     crate_root = "shared.rs",
92     proc_macro_deps = [
93         "@crate_index//:paste",
94     ],
95     rustc_flags = [
96         "--cfg=upb_kernel",
97         "--cfg=bzl",
98     ],
99     visibility = [":protobuf_internal"],
100     deps = [
101         ":utf8",
102         "//rust/upb",
103     ],
106 rust_test(
107     name = "protobuf_upb_test",
108     crate = ":protobuf_upb",
109     rustc_flags = [
110         "--cfg=upb_kernel",
111         "--cfg=bzl",
112     ],
113     deps = [
114         "@crate_index//:googletest",
115     ],
118 # This provides an identical set of re-exports as `:protobuf` with `:use_upb_kernel` active.
119 # This is only used for tests shared between runtimes.
120 rust_library(
121     name = "protobuf_upb_export",
122     testonly = True,
123     srcs = ["protobuf.rs"],
124     rustc_flags = ["--cfg=upb_kernel"],
125     visibility = [":protobuf_internal"],
126     deps = [":protobuf_upb"],
129 # The Rust Protobuf runtime using the cpp kernel.
131 # `rust_cpp_proto_library` implicitly depends on this target. This target cannot depend on
132 # `:rust_proto_library_kernel` build setting; it has to be fully functional under any value of that
133 # setting.
134 rust_library(
135     name = "protobuf_cpp",
136     srcs = PROTOBUF_SHARED + ["cpp.rs"],
137     crate_root = "shared.rs",
138     proc_macro_deps = [
139         "@crate_index//:paste",
140     ],
141     rustc_flags = [
142         "--cfg=cpp_kernel",
143         "--cfg=bzl",
144     ],
145     visibility = [":protobuf_internal"],
146     deps = [
147         ":utf8",
148         "//rust/cpp_kernel:cpp_api",
149     ],
152 rust_test(
153     name = "protobuf_cpp_test",
154     crate = ":protobuf_cpp",
155     rustc_flags = [
156         "--cfg=cpp_kernel",
157         "--cfg=bzl",
158     ],
159     deps = [
160         "@crate_index//:googletest",
161     ],
164 # This provides an identical set of re-exports as `:protobuf` with `:use_upb_kernel` inactive.
165 # This is only used for tests shared between runtimes.
166 rust_library(
167     name = "protobuf_cpp_export",
168     testonly = True,
169     srcs = ["protobuf.rs"],
170     rustc_flags = ["--cfg=cpp_kernel"],
171     visibility = [":protobuf_internal"],
172     deps = [":protobuf_cpp"],
175 rust_library(
176     name = "protobuf_gtest_matchers",
177     testonly = True,
178     srcs = ["gtest_matchers.rs"],
179     aliases = select({
180         ":use_upb_kernel": {"//rust:protobuf_gtest_matchers_upb": "protobuf_gtest_matchers_impl"},
181         "//conditions:default": {"//rust:protobuf_gtest_matchers_cpp": "protobuf_gtest_matchers_impl"},
182     }),
183     visibility = ["//visibility:public"],
184     deps = select({
185         ":use_upb_kernel": [":protobuf_gtest_matchers_upb"],
186         "//conditions:default": [":protobuf_gtest_matchers_cpp"],
187     }),
190 rust_library(
191     name = "protobuf_gtest_matchers_cpp",
192     testonly = True,
193     srcs = ["gtest_matchers_impl.rs"],
194     aliases = {
195         "//rust:protobuf_cpp": "protobuf",
196     },
197     visibility = [":protobuf_internal"],
198     deps = [
199         ":protobuf_cpp",
200         "@crate_index//:googletest",
201     ],
204 rust_library(
205     name = "protobuf_gtest_matchers_upb",
206     testonly = True,
207     srcs = ["gtest_matchers_impl.rs"],
208     aliases = {
209         "//rust:protobuf_upb": "protobuf",
210     },
211     visibility = [":protobuf_internal"],
212     deps = [
213         ":protobuf_upb",
214         "@crate_index//:googletest",
215     ],
218 rust_library(
219     name = "utf8",
220     srcs = ["utf8.rs"],
223 proto_lang_toolchain(
224     name = "proto_rust_upb_toolchain",
225     command_line = "--rust_out=$(OUT)",
226     output_files = "multiple",
227     progress_message = "Generating Rust proto_library %{label}",
228     runtime = ":protobuf_upb",
229     visibility = ["//visibility:public"],
232 proto_lang_toolchain(
233     name = "proto_rust_cpp_toolchain",
234     command_line = "--rust_out=$(OUT)",
235     output_files = "multiple",
236     progress_message = "Generating Rust proto_library %{label}",
237     runtime = ":protobuf_cpp",
238     visibility = ["//visibility:public"],
241 package_group(
242     name = "rust_proto_library_allowed_in_different_package",
243     packages = ["//rust/test"],  # for unittest proto_libraries
246 # This flag controls what kernel all Rust Protobufs are using in the current build.
247 string_flag(
248     name = "rust_proto_library_kernel",
249     build_setting_default = "cpp",
250     values = [
251         "upb",
252         "cpp",
253     ],
256 config_setting(
257     name = "use_upb_kernel",
258     flag_values = {
259         ":rust_proto_library_kernel": "upb",
260     },
263 pkg_files(
264     name = "rust_protobuf_src",
265     srcs = ALL_RUST_SRCS,
266     strip_prefix = strip_prefix.from_root("rust"),
269 pkg_filegroup(
270     name = "rust_protobuf_src_dir",
271     srcs = [
272         ":rust_protobuf_src",
273         "//rust/upb:rust_protobuf_upb_src",
274     ],
275     prefix = "src",
276     visibility = ["//rust/release_crates:__subpackages__"],
279 pkg_files(
280     name = "amalgamated_upb",
281     srcs = ["//upb:gen_amalgamation"],
282     strip_prefix = strip_prefix.from_root(""),
285 pkg_filegroup(
286     name = "rust_protobuf_libupb_src",
287     srcs = [
288         ":amalgamated_upb",
289         "//upb/cmake:upb_cmake_dist",
290     ],
291     prefix = "libupb",
292     visibility = ["//rust/release_crates:__subpackages__"],