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_test", "rust_library", "rust_proc_macro", "rust_test") 16load("//pw_build:compatibility.bzl", "incompatible_with_mcu") 17 18rust_library( 19 name = "pw_log", 20 srcs = [ 21 "pw_log.rs", 22 ], 23 crate_features = select({ 24 "@rust_crates//:std": ["std"], 25 "//conditions:default": [""], 26 }), 27 visibility = ["//visibility:public"], 28 deps = [ 29 ":pw_log_backend", 30 ":pw_log_backend_api", 31 ], 32) 33 34rust_test( 35 name = "pw_log_test", 36 crate = ":pw_log", 37 crate_features = select({ 38 "@rust_crates//:std": ["std"], 39 "//conditions:default": [""], 40 }), 41 # TODO: b/343726867 - support on-device rust tests 42 target_compatible_with = incompatible_with_mcu(), 43) 44 45rust_doc_test( 46 name = "pw_log_doc_test", 47 crate = ":pw_log", 48 target_compatible_with = select({ 49 "@platforms//os:none": ["@platforms//:incompatible"], 50 # TODO: https://github.com/bazelbuild/rules_rust/issues/1431 - enable once rules_rust can set features on doc tests 51 "@rules_rust//rust/toolchain/channel:nightly": ["@platforms//:incompatible"], 52 "//conditions:default": [], 53 }), 54) 55 56rust_library( 57 name = "pw_log_backend_api", 58 srcs = [ 59 "pw_log_backend_api.rs", 60 ], 61 visibility = ["//visibility:public"], 62) 63 64rust_library( 65 name = "pw_log_backend_println", 66 srcs = [ 67 "pw_log_backend_println.rs", 68 ], 69 crate_name = "pw_log_backend", 70 proc_macro_deps = [":pw_log_backend_println_macro"], 71 # TODO: b/343467774 - provide no_std backend by default 72 tags = ["manual"], 73 visibility = ["//visibility:public"], 74 deps = [ 75 ":pw_log_backend_api", 76 ], 77) 78 79rust_proc_macro( 80 name = "pw_log_backend_println_macro", 81 srcs = [ 82 "pw_log_backend_println_macro.rs", 83 ], 84 visibility = ["//visibility:public"], 85 deps = [ 86 ":pw_log_backend_api", 87 "//pw_format/rust:pw_format", 88 "//pw_status/rust:pw_status", 89 "@rust_crates//:proc-macro2", 90 "@rust_crates//:quote", 91 "@rust_crates//:syn", 92 ], 93) 94 95# Declare two targets. One named `pw_log_backend_printf` which uses the 96# crate name `pw_log_backend` for use with `pw_log`'s facade pattern. The 97# second named `pw_log_backend_printf_docs` with the crate name 98# `pw_log_backend_printf` used for generating docs for the crate. 99rust_library( 100 name = "pw_log_backend_printf", 101 srcs = [ 102 "pw_log_backend_printf/lib.rs", 103 "pw_log_backend_printf/varargs.rs", 104 ], 105 crate_name = "pw_log_backend", 106 proc_macro_deps = [":pw_log_backend_printf_macro"], 107 # TODO: b/343467774 - provide no_std backend by default 108 target_compatible_with = incompatible_with_mcu(), 109 visibility = ["//visibility:public"], 110 deps = [ 111 ":pw_log_backend_api", 112 "//pw_bytes/rust:pw_bytes", 113 "//pw_format/rust:pw_format_core", 114 ], 115) 116 117rust_library( 118 name = "pw_log_backend_printf_docs", 119 srcs = [ 120 "pw_log_backend_printf/lib.rs", 121 "pw_log_backend_printf/varargs.rs", 122 ], 123 crate_name = "pw_log_backend_printf", 124 proc_macro_deps = [":pw_log_backend_printf_macro"], 125 # TODO: b/343467774 - provide no_std backend by default 126 target_compatible_with = incompatible_with_mcu(), 127 visibility = ["//visibility:public"], 128 deps = [ 129 ":pw_log_backend_api", 130 "//pw_bytes/rust:pw_bytes", 131 "//pw_format/rust:pw_format_core", 132 ], 133) 134 135# Use the _docs target for tests and doc tests so they get the unique crate 136# name. 137rust_test( 138 name = "pw_log_backend_printf_test", 139 crate = ":pw_log_backend_printf_docs", 140 # TODO: b/343726867 - support on-device rust tests 141 target_compatible_with = incompatible_with_mcu(), 142) 143 144rust_doc_test( 145 name = "pw_log_backend_printf_doc_test", 146 crate = ":pw_log_backend_printf_docs", 147 target_compatible_with = incompatible_with_mcu(), 148) 149 150rust_proc_macro( 151 name = "pw_log_backend_printf_macro", 152 srcs = [ 153 "pw_log_backend_printf_macro.rs", 154 ], 155 visibility = ["//visibility:public"], 156 deps = [ 157 ":pw_log_backend_api", 158 "//pw_format/rust:pw_format", 159 "//pw_status/rust:pw_status", 160 "@rust_crates//:proc-macro2", 161 "@rust_crates//:quote", 162 "@rust_crates//:syn", 163 ], 164) 165 166rust_library( 167 name = "printf_backend_test", 168 srcs = [ 169 "backend_tests.rs", 170 "printf_backend_test.rs", 171 ], 172 visibility = ["//visibility:public"], 173 deps = [ 174 ":pw_log_backend_api", 175 ":pw_log_backend_printf", 176 "@rust_crates//:libc", 177 "@rust_crates//:nix", 178 ], 179) 180 181rust_test( 182 name = "printf_backend_test_test", 183 crate = ":printf_backend_test", 184 crate_features = select({ 185 "@rules_rust//rust/toolchain/channel:nightly": ["nightly"], 186 "//conditions:default": [], 187 }), 188 # TODO: b/343726867 - support on-device rust tests 189 target_compatible_with = incompatible_with_mcu(), 190) 191 192rust_library( 193 name = "println_backend_test", 194 srcs = [ 195 "backend_tests.rs", 196 "println_backend_test.rs", 197 ], 198 target_compatible_with = select({ 199 # This test needs unstable features. 200 "@rules_rust//rust/toolchain/channel:nightly": [], 201 "//conditions:default": ["@platforms//:incompatible"], 202 }), 203 visibility = ["//visibility:public"], 204 deps = [ 205 ":pw_log_backend_api", 206 ":pw_log_backend_println", 207 ], 208) 209 210rust_test( 211 name = "println_backend_test_test", 212 crate = ":println_backend_test", 213 # TODO: b/343726867 - support on-device rust tests 214 target_compatible_with = incompatible_with_mcu(), 215) 216 217label_flag( 218 name = "pw_log_backend", 219 build_setting_default = ":pw_log_backend_printf", 220 visibility = ["//visibility:public"], 221) 222