Adam Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 1 | load( |
| 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 | ) |
| 9 | load("@com_github_google_flatbuffers//:build_defs.bzl", _flatbuffer_rust_library = "flatbuffer_rust_library") |
| 10 | |
Adam Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 11 | def 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 | |
| 20 | def rust_doc(target_compatible_with = ["//tools/platforms/rust:has_support"], **kwargs): |
| 21 | _rust_doc( |
| 22 | target_compatible_with = target_compatible_with, |
| 23 | **kwargs |
| 24 | ) |
| 25 | |
Adam Snaider | 5f00067 | 2023-11-02 16:04:30 -0700 | [diff] [blame^] | 26 | def rust_binary(target_compatible_with = ["//tools/platforms/rust:has_support"], rustc_flags = [], **kwargs): |
| 27 | _rust_binary( |
| 28 | target_compatible_with = select({ |
| 29 | Label("//conditions:default"): target_compatible_with, |
| 30 | Label("//tools:has_msan"): ["@platforms//:incompatible"], |
| 31 | }), |
| 32 | # TODO: Make Rust play happy with pic vs nopic. Details at: |
| 33 | # https://github.com/bazelbuild/rules_rust/issues/118 |
| 34 | rustc_flags = rustc_flags + ["-Crelocation-model=static"], |
| 35 | **kwargs |
| 36 | ) |
| 37 | |
| 38 | def rust_library(target_compatible_with = ["//tools/platforms/rust:has_support"], docs = True, **kwargs): |
| 39 | _rust_library( |
| 40 | target_compatible_with = select({ |
| 41 | Label("//conditions:default"): target_compatible_with, |
| 42 | Label("//tools:has_msan"): ["@platforms//:incompatible"], |
| 43 | }), |
| 44 | **kwargs |
| 45 | ) |
| 46 | |
| 47 | if docs: |
| 48 | rust_doc( |
| 49 | name = kwargs["name"] + "_doc", |
| 50 | crate = kwargs["name"], |
| 51 | rustdoc_flags = ["--document-private-items"], |
| 52 | target_compatible_with = ["//tools/platforms/rust:has_support"], |
| 53 | ) |
| 54 | |
| 55 | def rust_test(target_compatible_with = ["//tools/platforms/rust:has_support"], rustc_flags = [], **kwargs): |
| 56 | _rust_test( |
| 57 | target_compatible_with = select({ |
| 58 | Label("//conditions:default"): target_compatible_with, |
| 59 | Label("//tools:has_msan"): ["@platforms//:incompatible"], |
| 60 | }), |
| 61 | rustc_flags = rustc_flags + ["-Crelocation-model=static"], |
| 62 | **kwargs |
| 63 | ) |
| 64 | |
Adam Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 65 | def flatbuffer_rust_library(target_compatible_with = ["//tools/platforms/rust:has_support"], **kwargs): |
| 66 | _flatbuffer_rust_library( |
| 67 | target_compatible_with = select({ |
| 68 | Label("//conditions:default"): target_compatible_with, |
| 69 | Label("//tools:has_msan"): ["@platforms//:incompatible"], |
| 70 | }), |
| 71 | **kwargs |
| 72 | ) |