Austin Schuh | 8f99c82 | 2024-05-05 22:43:40 -0700 | [diff] [blame^] | 1 | load("@com_github_google_flatbuffers//:build_defs.bzl", _flatbuffer_rust_library = "flatbuffer_rust_library") |
Adam Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 2 | load( |
| 3 | "@rules_rust//rust:defs.bzl", |
| 4 | _rust_binary = "rust_binary", |
| 5 | _rust_doc = "rust_doc", |
| 6 | _rust_doc_test = "rust_doc_test", |
| 7 | _rust_library = "rust_library", |
| 8 | _rust_test = "rust_test", |
| 9 | ) |
Adam Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 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 | |
Adam Snaider | b40b72f | 2023-11-02 19:40:55 -0700 | [diff] [blame] | 20 | def rust_doc(target_compatible_with = ["//tools/platforms/rust:has_support"], rustdoc_flags = ["-Dwarnings"], **kwargs): |
Adam Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 21 | _rust_doc( |
| 22 | target_compatible_with = target_compatible_with, |
Adam Snaider | b40b72f | 2023-11-02 19:40:55 -0700 | [diff] [blame] | 23 | rustdoc_flags = rustdoc_flags, |
Adam Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 24 | **kwargs |
| 25 | ) |
| 26 | |
Adam Snaider | 5f00067 | 2023-11-02 16:04:30 -0700 | [diff] [blame] | 27 | def 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 Snaider | 5f00067 | 2023-11-02 16:04:30 -0700 | [diff] [blame] | 39 | def 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 Snaider | f560ae9 | 2023-11-07 17:06:21 -0800 | [diff] [blame] | 49 | def 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 Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 99 | def 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 | ) |