blob: 88caca535c054f02d6da256072113cd69acb2de9 [file] [log] [blame]
Adam Snaider0967b812023-11-02 15:29:43 -07001load(
2 "@rules_rust//rust:defs.bzl",
3 _rust_binary = "rust_binary",
4 _rust_doc = "rust_doc",
5 _rust_doc_test = "rust_doc_test",
6 _rust_library = "rust_library",
7 _rust_test = "rust_test",
8)
9load("@com_github_google_flatbuffers//:build_defs.bzl", _flatbuffer_rust_library = "flatbuffer_rust_library")
10
Adam Snaider0967b812023-11-02 15:29:43 -070011def rust_doc_test(target_compatible_with = ["//tools/platforms/rust:has_support"], tags = [], **kwargs):
12 # TODO(james): Attempting to execute this remotely results
13 # in complaints about overly large files.
14 _rust_doc_test(
15 tags = tags + ["no-remote-exec"],
16 target_compatible_with = target_compatible_with,
17 **kwargs
18 )
19
Adam Snaiderb40b72f2023-11-02 19:40:55 -070020def rust_doc(target_compatible_with = ["//tools/platforms/rust:has_support"], rustdoc_flags = ["-Dwarnings"], **kwargs):
Adam Snaider0967b812023-11-02 15:29:43 -070021 _rust_doc(
22 target_compatible_with = target_compatible_with,
Adam Snaiderb40b72f2023-11-02 19:40:55 -070023 rustdoc_flags = rustdoc_flags,
Adam Snaider0967b812023-11-02 15:29:43 -070024 **kwargs
25 )
26
Adam Snaider5f000672023-11-02 16:04:30 -070027def rust_binary(target_compatible_with = ["//tools/platforms/rust:has_support"], rustc_flags = [], **kwargs):
28 _rust_binary(
29 target_compatible_with = select({
30 Label("//conditions:default"): target_compatible_with,
31 Label("//tools:has_msan"): ["@platforms//:incompatible"],
32 }),
33 # TODO: Make Rust play happy with pic vs nopic. Details at:
34 # https://github.com/bazelbuild/rules_rust/issues/118
35 rustc_flags = rustc_flags + ["-Crelocation-model=static"],
36 **kwargs
37 )
38
Adam Snaider5f000672023-11-02 16:04:30 -070039def rust_test(target_compatible_with = ["//tools/platforms/rust:has_support"], rustc_flags = [], **kwargs):
40 _rust_test(
41 target_compatible_with = select({
42 Label("//conditions:default"): target_compatible_with,
43 Label("//tools:has_msan"): ["@platforms//:incompatible"],
44 }),
45 rustc_flags = rustc_flags + ["-Crelocation-model=static"],
46 **kwargs
47 )
48
Adam Snaiderf560ae92023-11-07 17:06:21 -080049def rust_library(
50 name,
51 target_compatible_with = ["//tools/platforms/rust:has_support"],
52 gen_docs = True,
53 gen_tests = True,
54 gen_doctests = True,
55 **kwargs):
56 test_params = {}
57 doctest_params = {}
58 params = {}
59
60 for (param, value) in kwargs.items():
61 if param.startswith("test_"):
62 test_params[param[5:]] = value
63 elif param.startswith("doctest_"):
64 doctest_params[param[8:]] = value
65 else:
66 params[param] = value
67
68 _rust_library(
69 name = name,
70 target_compatible_with = select({
71 Label("//conditions:default"): target_compatible_with,
72 Label("//tools:has_msan"): ["@platforms//:incompatible"],
73 }),
74 **params
75 )
76
77 if gen_tests:
78 rust_test(
79 name = name + "_test",
80 crate = name,
81 **test_params
82 )
83
84 if gen_docs:
85 rust_doc(
86 name = name + "_doc",
87 crate = name,
88 target_compatible_with = ["//tools/platforms/rust:has_support"],
89 rustdoc_flags = ["--document-private-items", "-Dwarnings"],
90 )
91
92 if gen_doctests:
93 rust_doc_test(
94 name = name + "_doctest",
95 crate = name,
96 **doctest_params
97 )
98
Adam Snaider0967b812023-11-02 15:29:43 -070099def flatbuffer_rust_library(target_compatible_with = ["//tools/platforms/rust:has_support"], **kwargs):
100 _flatbuffer_rust_library(
101 target_compatible_with = select({
102 Label("//conditions:default"): target_compatible_with,
103 Label("//tools:has_msan"): ["@platforms//:incompatible"],
104 }),
105 **kwargs
106 )