1# Copyright 2019 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_cc//cc:cc_library.bzl", "cc_library") 16load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") 17load("//pw_build:compatibility.bzl", "incompatible_with_mcu") 18load("//pw_build:glob_dirs.bzl", "glob_dirs", "match_dir", "match_dir_internal") 19load("//pw_build:load_phase_test.bzl", "pw_string_comparison_test", "pw_string_list_comparison_test", "return_error") 20load("//pw_build:pw_cc_binary.bzl", "pw_cc_binary_with_map") 21load("//pw_build:pw_cc_blob_library.bzl", "pw_cc_blob_info", "pw_cc_blob_library") 22load("//pw_build:pw_copy_and_patch_file_test.bzl", "pw_copy_and_patch_file_test") 23load("//pw_build:pw_py_importable_runfile.bzl", "pw_py_importable_runfile") 24load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") 25 26package(default_visibility = ["//visibility:public"]) 27 28licenses(["notice"]) 29 30config_setting( 31 name = "kythe", 32 values = { 33 "define": "kythe_corpus=pigweed.googlesource.com/pigweed/pigweed", 34 }, 35) 36 37pw_cc_blob_info( 38 name = "test_blob_aligned", 39 alignas = "512", 40 file_path = "test_blob_0123.bin", 41 symbol_name = "kFirstBlob0123", 42) 43 44pw_cc_blob_info( 45 name = "test_blob_unaligned", 46 file_path = "test_blob_0123.bin", 47 symbol_name = "kSecondBlob0123", 48) 49 50pw_cc_blob_library( 51 name = "test_blob", 52 blobs = [ 53 ":test_blob_aligned", 54 ":test_blob_unaligned", 55 ], 56 namespace = "test::ns", 57 out_header = "pw_build/test_blob.h", 58) 59 60pw_cc_test( 61 name = "cc_blob_library_test", 62 srcs = ["cc_blob_library_test.cc"], 63 deps = [":test_blob"], 64) 65 66pw_cc_binary_with_map( 67 name = "cc_binary_with_map", 68 srcs = ["empty_main.cc"], 69 # Only enable on platforms that support -Map linker flag 70 target_compatible_with = ["@platforms//os:linux"], 71) 72 73# Bazel produces root-relative file paths without the -ffile-prefix-map option. 74pw_cc_test( 75 name = "file_prefix_map_test", 76 srcs = [ 77 "file_prefix_map_test.cc", 78 "pw_build_private/file_prefix_map_test.h", 79 ], 80 defines = [ 81 "PW_BUILD_EXPECTED_HEADER_PATH=\\\"pw_build/pw_build_private/file_prefix_map_test.h\\\"", 82 "PW_BUILD_EXPECTED_SOURCE_PATH=\\\"pw_build/file_prefix_map_test.cc\\\"", 83 ], 84 tags = ["noclangtidy"], 85) 86 87label_flag( 88 name = "default_module_config", 89 # The default module config is empty. 90 build_setting_default = ":empty_cc_library", 91) 92 93cc_library( 94 name = "test_module_config", 95 defines = [ 96 "PW_THREAD_FREERTOS_CONFIG_JOINING_ENABLED=1", 97 ], 98) 99 100pw_cc_test( 101 name = "module_config_test", 102 srcs = ["module_config_test.cc"], 103 # This test requires a special configuration. It's run in CI, and can be 104 # run manually via, 105 # 106 # bazel build \ 107 # --config=stm32f429i_freertos \ 108 # --//pw_thread_freertos:config_override=//pw_build:test_module_config \ 109 # //pw_build:module_config_test 110 tags = ["manual"], 111 deps = ["//pw_thread:thread"], 112) 113 114# This empty library is used as a placeholder for label flags that need to 115# point to a library of some kind, but don't actually need the dependency to 116# amount to anything. 117cc_library( 118 name = "empty_cc_library", 119) 120 121# A special target used instead of a cc_library as the default condition in 122# backend multiplexer select statements to signal that a facade is in an 123# unconfigured state. This produces better error messages than e.g. using an 124# invalid label. 125# 126# If you're a user whose build errored out because a library transitively 127# depended on this target: the platform you're targeting did not specify which 128# backend to use for some facade. Look at the previous step in the dependency 129# chain (printed with the error) to figure out which one. 130cc_library( 131 name = "unspecified_backend", 132 target_compatible_with = ["@platforms//:incompatible"], 133) 134 135# Additional libraries that all binaries using Pigweed should be linked against. 136# 137# This is analogous to GN's pw_build_LINK_DEPS. See 138# https://pigweed.dev/build_system.html#docs-build-system-bazel-link-extra-lib 139# for more details. 140cc_library( 141 name = "default_link_extra_lib", 142 deps = [ 143 "//pw_assert:assert_backend_impl", 144 "//pw_assert:check_backend_impl", 145 "//pw_log:backend_impl", 146 ], 147) 148 149# Linker script utility PW_MUST_PLACE 150cc_library( 151 name = "must_place", 152 hdrs = ["public/pw_build/must_place.ld.h"], 153 strip_include_prefix = "public", 154) 155 156cc_library( 157 name = "linker_symbol", 158 hdrs = ["public/pw_build/linker_symbol.h"], 159 strip_include_prefix = "public", 160 deps = [ 161 "//third_party/fuchsia:stdcompat", 162 ], 163) 164 165pw_cc_test( 166 name = "linker_symbol_test", 167 srcs = ["linker_symbol_test.cc"], 168 linkopts = [ 169 "-T$(execpath linker_symbol_test.ld)", 170 ], 171 target_compatible_with = [ 172 "@platforms//os:linux", 173 ], 174 deps = [ 175 ":linker_symbol", 176 ":linker_symbol_test.ld", 177 ], 178) 179 180pw_string_list_comparison_test( 181 name = "simple_glob", 182 actual = glob_dirs( 183 ["test_data/**"], 184 exclude = ["test_data/pw_copy_and_patch_file/**"], 185 ), 186 expected = [ 187 "test_data", 188 "test_data/glob_dirs", 189 "test_data/glob_dirs/nested_1", 190 "test_data/glob_dirs/nested_1/foo", 191 "test_data/glob_dirs/nested_2", 192 ], 193) 194 195pw_string_comparison_test( 196 name = "single_match", 197 actual = match_dir(["test_data/glob_dirs/nested_1"]), 198 expected = "test_data/glob_dirs/nested_1", 199) 200 201pw_string_comparison_test( 202 name = "no_match_single", 203 actual = match_dir(["test_data/glob_dirs/nested_1/nope"]), 204 expected = None, 205) 206 207pw_string_comparison_test( 208 name = "no_match_single_fail", 209 actual = match_dir_internal( 210 ["test_data/glob_dirs/**/*.txt"], 211 _fail_callback = return_error, 212 allow_empty = False, 213 ), 214 expected = "glob pattern [\"test_data/glob_dirs/**/*.txt\"] didn't match anything, but allow_empty is set to False", 215) 216 217pw_string_comparison_test( 218 name = "bad_match_multiple", 219 actual = match_dir_internal( 220 ["test_data/glob_dirs/**"], 221 _fail_callback = return_error, 222 allow_empty = False, 223 ), 224 expected = "glob pattern [\"test_data/glob_dirs/**\"] matches multiple directories when only one was requested: [\"test_data/glob_dirs\", \"test_data/glob_dirs/nested_1\", \"test_data/glob_dirs/nested_1/foo\", \"test_data/glob_dirs/nested_2\"]", 225) 226 227pw_string_comparison_test( 228 name = "match_exclusions", 229 actual = match_dir( 230 ["test_data/glob_dirs/**"], 231 allow_empty = False, 232 exclude = ["test_data/glob_dirs/*/**"], 233 ), 234 expected = "test_data/glob_dirs", 235) 236 237pw_string_list_comparison_test( 238 name = "single_match_glob", 239 actual = glob_dirs(["test_data/glob_dirs/nested_1"]), 240 expected = [ 241 "test_data/glob_dirs/nested_1", 242 ], 243) 244 245pw_string_list_comparison_test( 246 name = "partial_match_glob", 247 actual = glob_dirs(["test_data/glob_dirs/nested_*"]), 248 expected = [ 249 "test_data/glob_dirs/nested_1", 250 "test_data/glob_dirs/nested_2", 251 ], 252) 253 254pw_string_list_comparison_test( 255 name = "nested_match_glob", 256 actual = glob_dirs(["test_data/glob_dirs/*/foo"]), 257 expected = [ 258 "test_data/glob_dirs/nested_1/foo", 259 ], 260) 261 262pw_string_list_comparison_test( 263 name = "no_match_glob", 264 actual = glob_dirs(["test_data/glob_dirs/others/**"]), 265 expected = [ 266 ], 267) 268 269pw_copy_and_patch_file_test( 270 name = "patch_file_basic", 271 src = "test_data/pw_copy_and_patch_file/basic.txt", 272 out = "test_data/pw_copy_and_patch_file/patched_basic.txt", 273 expected = "test_data/pw_copy_and_patch_file/basic.expected", 274 patch_file = "test_data/pw_copy_and_patch_file/basic.patch", 275) 276 277pw_py_importable_runfile( 278 name = "test_runfile", 279 testonly = True, 280 src = "test_data/test_runfile.txt", 281 visibility = ["//pw_build:__subpackages__"], 282) 283 284pw_py_importable_runfile( 285 name = "test_runfile_remapped", 286 testonly = True, 287 src = "test_data/test_runfile.txt", 288 import_location = "pw_build.another_test_runfile", 289 visibility = ["//pw_build:__subpackages__"], 290) 291 292filegroup( 293 name = "doxygen", 294 srcs = [ 295 "public/pw_build/linker_symbol.h", 296 "public/pw_build/must_place.ld.h", 297 ], 298) 299 300sphinx_docs_library( 301 name = "docs", 302 srcs = [ 303 "bazel.rst", 304 "cmake.rst", 305 "docs.rst", 306 "gn.rst", 307 "linker_scripts.rst", 308 "pigweed.bazelrc", 309 "pigweed_recommended.bazelrc", 310 "project_builder.rst", 311 "python.gni", 312 "python.rst", 313 "python_api.rst", 314 "python_gn_args.gni", 315 "//pw_build/py:docs", 316 ], 317 prefix = "pw_build/", 318 target_compatible_with = incompatible_with_mcu(), 319) 320