1# Copyright 2023 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15load("@rules_rust//rust:defs.bzl", "rust_doc", "rust_doc_test", "rust_library", "rust_proc_macro", "rust_test") 16load("//pw_build:compatibility.bzl", "incompatible_with_mcu") 17 18rust_proc_macro( 19 name = "pw_tokenizer_macro", 20 srcs = [ 21 "pw_tokenizer_macro.rs", 22 ], 23 visibility = ["//visibility:public"], 24 deps = [ 25 ":pw_tokenizer_core", 26 "//pw_format/rust:pw_format", 27 "//pw_status/rust:pw_status", 28 "@rust_crates//:proc-macro2", 29 "@rust_crates//:quote", 30 "@rust_crates//:syn", 31 ], 32) 33 34rust_test( 35 name = "pw_tokenizer_macro_test", 36 crate = ":pw_tokenizer_macro", 37 # TODO: b/343726867 - support on-device rust tests 38 target_compatible_with = incompatible_with_mcu(), 39) 40 41rust_library( 42 name = "pw_tokenizer_core", 43 srcs = [ 44 "pw_tokenizer_core.rs", 45 "pw_tokenizer_core_test_cases.rs", 46 ], 47 crate_features = select({ 48 "@rust_crates//:std": ["std"], 49 "//conditions:default": [""], 50 }), 51 visibility = ["//visibility:public"], 52) 53 54rust_test( 55 name = "pw_tokenizer_core_test", 56 crate = ":pw_tokenizer_core", 57 crate_features = select({ 58 "@rust_crates//:std": ["std"], 59 "//conditions:default": [], 60 }), 61 # TODO: b/343726867 - support on-device rust tests 62 target_compatible_with = incompatible_with_mcu(), 63) 64 65rust_doc_test( 66 name = "pw_tokenizer_core_doc_test", 67 crate = ":pw_tokenizer_core", 68 target_compatible_with = select({ 69 "@platforms//os:none": ["@platforms//:incompatible"], 70 # TODO: https://github.com/bazelbuild/rules_rust/issues/1431 - enable once rules_rust can set features on doc tests 71 "@rules_rust//rust/toolchain/channel:nightly": ["@platforms//:incompatible"], 72 "//conditions:default": [], 73 }), 74) 75 76rust_doc( 77 name = "pw_tokenizer_core_doc", 78 crate = ":pw_tokenizer_core", 79 target_compatible_with = incompatible_with_mcu(), 80) 81 82rust_library( 83 name = "pw_tokenizer", 84 srcs = [ 85 "pw_tokenizer/internal.rs", 86 "pw_tokenizer/lib.rs", 87 ], 88 crate_features = select({ 89 "@rust_crates//:std": ["std"], 90 "//conditions:default": [""], 91 }), 92 proc_macro_deps = [":pw_tokenizer_macro"], 93 visibility = ["//visibility:public"], 94 deps = [ 95 ":pw_tokenizer_core", 96 "//pw_bytes/rust:pw_bytes", 97 "//pw_format/rust:pw_format_core", 98 "//pw_status/rust:pw_status", 99 "//pw_stream/rust:pw_stream", 100 "//pw_varint/rust:pw_varint", 101 ] + select({ 102 "@rust_crates//:std": [ 103 "//pw_format/rust:pw_format", # Added for rustdoc linking support. 104 ], 105 "//conditions:default": [], 106 }), 107) 108 109rust_test( 110 name = "pw_tokenizer_test", 111 crate = ":pw_tokenizer", 112 crate_features = select({ 113 "@rust_crates//:std": ["std"], 114 "//conditions:default": [""], 115 }) + select({ 116 "@rules_rust//rust/toolchain/channel:nightly": ["nightly"], 117 "//conditions:default": [], 118 }), 119 # TODO: b/343726867 - support on-device rust tests 120 target_compatible_with = incompatible_with_mcu(), 121) 122 123rust_doc_test( 124 name = "pw_tokenizer_doc_test", 125 crate = ":pw_tokenizer", 126 target_compatible_with = select({ 127 "@platforms//os:none": ["@platforms//:incompatible"], 128 # TODO: https://github.com/bazelbuild/rules_rust/issues/1431 - enable once rules_rust can set features on doc tests 129 "@rules_rust//rust/toolchain/channel:nightly": ["@platforms//:incompatible"], 130 "//conditions:default": [], 131 }), 132) 133 134rust_doc( 135 name = "pw_tokenizer_doc", 136 crate = ":pw_tokenizer", 137 target_compatible_with = incompatible_with_mcu(), 138) 139