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