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 | 8215ac8 | 2024-03-04 13:53:31 -0500 | [diff] [blame] | 11 | def rust_doc_test(tags = [], **kwargs): |
Adam Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 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"], |
Adam Snaider | 8215ac8 | 2024-03-04 13:53:31 -0500 | [diff] [blame] | 16 | # TODO(adam.snaider): Investigate why doctests only work on x86_64. |
| 17 | target_compatible_with = ["@platforms//cpu:x86_64"], |
Adam Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 18 | **kwargs |
| 19 | ) |
| 20 | |
Adam Snaider | b40b72f | 2023-11-02 19:40:55 -0700 | [diff] [blame] | 21 | 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] | 22 | _rust_doc( |
| 23 | target_compatible_with = target_compatible_with, |
Adam Snaider | b40b72f | 2023-11-02 19:40:55 -0700 | [diff] [blame] | 24 | rustdoc_flags = rustdoc_flags, |
Adam Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 25 | **kwargs |
| 26 | ) |
| 27 | |
Adam Snaider | 5f00067 | 2023-11-02 16:04:30 -0700 | [diff] [blame] | 28 | def rust_binary(target_compatible_with = ["//tools/platforms/rust:has_support"], rustc_flags = [], **kwargs): |
| 29 | _rust_binary( |
| 30 | target_compatible_with = select({ |
| 31 | Label("//conditions:default"): target_compatible_with, |
| 32 | Label("//tools:has_msan"): ["@platforms//:incompatible"], |
| 33 | }), |
| 34 | # TODO: Make Rust play happy with pic vs nopic. Details at: |
| 35 | # https://github.com/bazelbuild/rules_rust/issues/118 |
| 36 | rustc_flags = rustc_flags + ["-Crelocation-model=static"], |
| 37 | **kwargs |
| 38 | ) |
| 39 | |
Adam Snaider | 5f00067 | 2023-11-02 16:04:30 -0700 | [diff] [blame] | 40 | def rust_test(target_compatible_with = ["//tools/platforms/rust:has_support"], rustc_flags = [], **kwargs): |
| 41 | _rust_test( |
| 42 | target_compatible_with = select({ |
| 43 | Label("//conditions:default"): target_compatible_with, |
| 44 | Label("//tools:has_msan"): ["@platforms//:incompatible"], |
| 45 | }), |
| 46 | rustc_flags = rustc_flags + ["-Crelocation-model=static"], |
| 47 | **kwargs |
| 48 | ) |
| 49 | |
Adam Snaider | f560ae9 | 2023-11-07 17:06:21 -0800 | [diff] [blame] | 50 | def rust_library( |
| 51 | name, |
| 52 | target_compatible_with = ["//tools/platforms/rust:has_support"], |
| 53 | gen_docs = True, |
| 54 | gen_tests = True, |
| 55 | gen_doctests = True, |
| 56 | **kwargs): |
| 57 | test_params = {} |
| 58 | doctest_params = {} |
| 59 | params = {} |
| 60 | |
| 61 | for (param, value) in kwargs.items(): |
| 62 | if param.startswith("test_"): |
| 63 | test_params[param[5:]] = value |
| 64 | elif param.startswith("doctest_"): |
| 65 | doctest_params[param[8:]] = value |
| 66 | else: |
| 67 | params[param] = value |
| 68 | |
| 69 | _rust_library( |
| 70 | name = name, |
| 71 | target_compatible_with = select({ |
| 72 | Label("//conditions:default"): target_compatible_with, |
| 73 | Label("//tools:has_msan"): ["@platforms//:incompatible"], |
| 74 | }), |
| 75 | **params |
| 76 | ) |
| 77 | |
| 78 | if gen_tests: |
| 79 | rust_test( |
| 80 | name = name + "_test", |
| 81 | crate = name, |
| 82 | **test_params |
| 83 | ) |
| 84 | |
| 85 | if gen_docs: |
| 86 | rust_doc( |
| 87 | name = name + "_doc", |
| 88 | crate = name, |
| 89 | target_compatible_with = ["//tools/platforms/rust:has_support"], |
| 90 | rustdoc_flags = ["--document-private-items", "-Dwarnings"], |
| 91 | ) |
| 92 | |
| 93 | if gen_doctests: |
| 94 | rust_doc_test( |
| 95 | name = name + "_doctest", |
| 96 | crate = name, |
| 97 | **doctest_params |
| 98 | ) |
| 99 | |
Adam Snaider | 0967b81 | 2023-11-02 15:29:43 -0700 | [diff] [blame] | 100 | def flatbuffer_rust_library(target_compatible_with = ["//tools/platforms/rust:has_support"], **kwargs): |
| 101 | _flatbuffer_rust_library( |
| 102 | target_compatible_with = select({ |
| 103 | Label("//conditions:default"): target_compatible_with, |
| 104 | Label("//tools:has_msan"): ["@platforms//:incompatible"], |
| 105 | }), |
| 106 | **kwargs |
| 107 | ) |