| # Copyright 2019 The Pigweed Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| # use this file except in compliance with the License. You may obtain a copy of |
| # the License at |
| # |
| # https://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| # License for the specific language governing permissions and limitations under |
| # the License. |
| |
| load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library") |
| load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library") |
| load("@com_google_protobuf//bazel/toolchains:proto_lang_toolchain.bzl", "proto_lang_toolchain") |
| load("@rules_cc//cc:cc_library.bzl", "cc_library") |
| load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary") |
| load("@sphinxdocs//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library") |
| load("//pw_build:compatibility.bzl", "incompatible_with_mcu") |
| load("//pw_build:glob_dirs.bzl", "glob_dirs", "match_dir", "match_dir_internal") |
| load("//pw_build:load_phase_test.bzl", "pw_bool_comparison_test", "pw_string_comparison_test", "pw_string_list_comparison_test", "return_error") |
| load("//pw_build:pigweed_is_root.bzl", "pigweed_is_root") |
| load("//pw_build:pw_cc_binary.bzl", "pw_cc_binary_with_map") |
| load("//pw_build:pw_cc_blob_library.bzl", "pw_cc_blob_info", "pw_cc_blob_library") |
| load("//pw_build:pw_copy_and_patch_file_test.bzl", "pw_copy_and_patch_file_test") |
| load("//pw_build:pw_py_importable_runfile.bzl", "pw_py_importable_runfile") |
| load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test") |
| load(":pw_pylint.bzl", "pylint_repo_allowlist") |
| load(":pw_pylint_test.bzl", "pw_pylint_test_suite") |
| |
| package(default_visibility = ["//visibility:public"]) |
| |
| licenses(["notice"]) |
| |
| label_flag( |
| name = "pylint", |
| build_setting_default = ":pigweed_pip_pylint", |
| ) |
| |
| py_console_script_binary( |
| name = "pigweed_pip_pylint", |
| pkg = "@pigweed_python_packages//pylint", |
| script = "pylint", |
| # TODO: https://github.com/bazel-contrib/rules_python/issues/3126 - Remove |
| # this tag once the bug in rules_python is fixed. |
| tags = ["nomypy"], |
| ) |
| |
| label_flag( |
| name = "pylintrc", |
| build_setting_default = "//pw_build/bazel_internal:empty_file_target", |
| ) |
| |
| pylint_repo_allowlist( |
| name = "default_allowed_repos", |
| allowed_canonical_names = [], |
| ) |
| |
| label_flag( |
| name = "pylint_allowed_repositories_target", |
| build_setting_default = ":default_allowed_repos", |
| ) |
| |
| config_setting( |
| name = "kythe", |
| values = { |
| "define": "kythe_corpus=pigweed.googlesource.com/pigweed/pigweed", |
| }, |
| ) |
| |
| alias( |
| name = "python_protobuf_runtime", |
| actual = select({ |
| "@platforms//os:linux": "@pigweed_python_packages//protobuf", |
| "@platforms//os:macos": "@pigweed_python_packages//protobuf", |
| "@platforms//os:windows": "@pigweed_python_packages//protobuf", |
| "//conditions:default": "@com_google_protobuf//:protobuf_python", |
| }), |
| ) |
| |
| # This toolchain targets python proto libraries using the python_protobuf_runtime. |
| # It is used by py_proto_library to generate python proto code. |
| proto_lang_toolchain( |
| name = "pw_python_proto_toolchain", |
| command_line = "--python_out=%s", |
| progress_message = "Generating Python proto_library %{label}", |
| runtime = ":python_protobuf_runtime", |
| toolchain_type = "@com_google_protobuf//bazel/private:python_toolchain_type", |
| ) |
| |
| proto_library( |
| name = "workflows_proto", |
| srcs = [ |
| "proto/workflows.proto", |
| ], |
| # Make private until the proto stabilizes. |
| visibility = ["//:__subpackages__"], |
| deps = [ |
| "@com_google_protobuf//:any_proto", |
| ], |
| ) |
| |
| py_proto_library( |
| name = "workflows_proto_py_pb2", |
| deps = [":workflows_proto"], |
| ) |
| |
| proto_library( |
| name = "build_driver_proto", |
| srcs = [ |
| "proto/build_driver.proto", |
| ], |
| # Restrict API to Pigweed until the api stabilizes. |
| visibility = ["//:__subpackages__"], |
| deps = [ |
| ":workflows_proto", |
| ], |
| ) |
| |
| py_proto_library( |
| name = "build_driver_proto_py_pb2", |
| # Restrict API to Pigweed until the api stabilizes. |
| visibility = ["//:__subpackages__"], |
| deps = [":build_driver_proto"], |
| ) |
| |
| proto_library( |
| name = "pigweed_build_driver", |
| srcs = [ |
| "proto/pigweed_build_driver.proto", |
| ], |
| # Restrict API to Pigweed until the api stabilizes. |
| visibility = ["//:__subpackages__"], |
| deps = [ |
| ":workflows_proto", |
| ], |
| ) |
| |
| py_proto_library( |
| name = "pigweed_build_driver_py_pb2", |
| # Restrict API to Pigweed until the api stabilizes. |
| visibility = ["//:__subpackages__"], |
| deps = [":pigweed_build_driver"], |
| ) |
| |
| pw_cc_blob_info( |
| name = "test_blob_aligned", |
| alignas = "512", |
| file_path = "test_blob_0123.bin", |
| symbol_name = "kFirstBlob0123", |
| ) |
| |
| pw_cc_blob_info( |
| name = "test_blob_unaligned", |
| file_path = "test_blob_0123.bin", |
| symbol_name = "kSecondBlob0123", |
| ) |
| |
| pw_cc_blob_info( |
| name = "test_blob_checksum", |
| file_path = "test_blob_0123.bin", |
| symbol_name = "kBlobWithChecksum", |
| ) |
| |
| pw_cc_blob_library( |
| name = "test_blob", |
| blobs = [ |
| ":test_blob_aligned", |
| ":test_blob_unaligned", |
| ], |
| namespace = "test::ns", |
| out_header = "pw_build/test_blob.h", |
| ) |
| |
| pw_cc_blob_library( |
| name = "test_blob_with_checksum", |
| blobs = [ |
| ":test_blob_checksum", |
| ], |
| checksum = "CRC32", |
| namespace = "test::checksum_ns", |
| out_header = "pw_build/test_blob_with_checksum.h", |
| ) |
| |
| pw_cc_test( |
| name = "cc_blob_library_test", |
| srcs = ["cc_blob_library_test.cc"], |
| deps = [":test_blob"], |
| ) |
| |
| pw_cc_test( |
| name = "cc_blob_library_checksum_test", |
| srcs = ["cc_blob_library_checksum_test.cc"], |
| deps = [":test_blob_with_checksum"], |
| ) |
| |
| pw_cc_binary_with_map( |
| name = "cc_binary_with_map", |
| srcs = ["empty_main.cc"], |
| # Only enable on platforms that support -Map linker flag |
| target_compatible_with = ["@platforms//os:linux"], |
| ) |
| |
| # Bazel produces root-relative file paths without the -ffile-prefix-map option. |
| pw_cc_test( |
| name = "file_prefix_map_test", |
| srcs = [ |
| "file_prefix_map_test.cc", |
| "pw_build_private/file_prefix_map_test.h", |
| ], |
| defines = [ |
| "PW_BUILD_EXPECTED_HEADER_PATH=\\\"pw_build/pw_build_private/file_prefix_map_test.h\\\"", |
| "PW_BUILD_EXPECTED_SOURCE_PATH=\\\"pw_build/file_prefix_map_test.cc\\\"", |
| ], |
| tags = ["noclangtidy"], |
| ) |
| |
| label_flag( |
| name = "default_module_config", |
| # The default module config is empty. |
| build_setting_default = "@rules_cc//:empty_lib", |
| ) |
| |
| cc_library( |
| name = "test_module_config", |
| defines = [ |
| "PW_THREAD_FREERTOS_CONFIG_JOINING_ENABLED=1", |
| ], |
| ) |
| |
| pw_cc_test( |
| name = "module_config_test", |
| srcs = ["module_config_test.cc"], |
| # This test requires a special configuration. It's run in CI, and can be |
| # run manually via, |
| # |
| # bazel build \ |
| # --config=stm32f429i_freertos \ |
| # --//pw_thread_freertos:config_override=//pw_build:test_module_config \ |
| # //pw_build:module_config_test |
| tags = ["manual"], |
| deps = ["//pw_thread:thread"], |
| ) |
| |
| # This empty library is used as a placeholder for label flags that need to |
| # point to a library of some kind, but don't actually need the dependency to |
| # amount to anything. |
| alias( |
| name = "empty_cc_library", |
| actual = "@rules_cc//:empty_lib", |
| ) |
| |
| # A special target used instead of a cc_library as the default condition in |
| # backend multiplexer select statements to signal that a facade is in an |
| # unconfigured state. This produces better error messages than e.g. using an |
| # invalid label. |
| # |
| # If you're a user whose build errored out because a library transitively |
| # depended on this target: the platform you're targeting did not specify which |
| # backend to use for some facade. Look at the previous step in the dependency |
| # chain (printed with the error) to figure out which one. |
| cc_library( |
| name = "unspecified_backend", |
| target_compatible_with = ["@platforms//:incompatible"], |
| ) |
| |
| # Additional libraries that all binaries using Pigweed should be linked against. |
| # |
| # This is analogous to GN's pw_build_LINK_DEPS. See |
| # https://pigweed.dev/build_system.html#docs-build-system-bazel-link-extra-lib |
| # for more details. |
| cc_library( |
| name = "default_link_extra_lib", |
| deps = [ |
| "//pw_assert:assert_backend_impl", |
| "//pw_assert:check_backend_impl", |
| "//pw_log:backend_impl", |
| ], |
| ) |
| |
| # Linker script utility PW_MUST_PLACE |
| cc_library( |
| name = "must_place", |
| hdrs = ["public/pw_build/must_place.ld.h"], |
| strip_include_prefix = "public", |
| ) |
| |
| cc_library( |
| name = "linker_symbol", |
| hdrs = ["public/pw_build/linker_symbol.h"], |
| strip_include_prefix = "public", |
| deps = [ |
| "//third_party/fuchsia:stdcompat", |
| ], |
| ) |
| |
| pw_cc_test( |
| name = "linker_symbol_test", |
| srcs = ["linker_symbol_test.cc"], |
| features = ["-ctad_warnings"], |
| linkopts = [ |
| "-T$(execpath linker_symbol_test.ld)", |
| ], |
| target_compatible_with = [ |
| "@platforms//os:linux", |
| ], |
| deps = [ |
| ":linker_symbol", |
| ":linker_symbol_test.ld", |
| ], |
| ) |
| |
| cc_library( |
| name = "sandbox_test_visible_header", |
| hdrs = ["public/pw_build/internal/test_header_with_dep.h"], |
| strip_include_prefix = "public", |
| ) |
| |
| cc_library( |
| name = "sandbox_test_invisible_header", |
| hdrs = ["public/pw_build/internal/test_header_without_dep.h"], |
| strip_include_prefix = "public", |
| ) |
| |
| pw_cc_test( |
| name = "sandbox_test", |
| srcs = [ |
| "absolute_path_source_file.cc", |
| "sandbox_absolute_source_test.cc", |
| "sandbox_test.cc", |
| ], |
| defines = ["SANDBOX_ENABLED=1"], |
| deps = [":sandbox_test_visible_header"], |
| ) |
| |
| pw_string_list_comparison_test( |
| name = "simple_glob", |
| actual = glob_dirs( |
| ["test_data/**"], |
| exclude = [ |
| "test_data/pw_copy_and_patch_file/**", |
| "test_data/pw_rust_crates_extension/**", |
| ], |
| ), |
| expected = [ |
| "test_data", |
| "test_data/glob_dirs", |
| "test_data/glob_dirs/nested_1", |
| "test_data/glob_dirs/nested_1/foo", |
| "test_data/glob_dirs/nested_2", |
| ], |
| ) |
| |
| pw_string_comparison_test( |
| name = "single_match", |
| actual = match_dir(["test_data/glob_dirs/nested_1"]), |
| expected = "test_data/glob_dirs/nested_1", |
| ) |
| |
| pw_string_comparison_test( |
| name = "no_match_single", |
| actual = match_dir(["test_data/glob_dirs/nested_1/nope"]), |
| expected = None, |
| ) |
| |
| pw_string_comparison_test( |
| name = "no_match_single_fail", |
| actual = match_dir_internal( |
| ["test_data/glob_dirs/**/*.txt"], |
| _fail_callback = return_error, |
| allow_empty = False, |
| ), |
| expected = "glob pattern [\"test_data/glob_dirs/**/*.txt\"] didn't match anything, but allow_empty is set to False", |
| ) |
| |
| pw_string_comparison_test( |
| name = "bad_match_multiple", |
| actual = match_dir_internal( |
| ["test_data/glob_dirs/**"], |
| _fail_callback = return_error, |
| allow_empty = False, |
| ), |
| 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\"]", |
| ) |
| |
| pw_string_comparison_test( |
| name = "match_exclusions", |
| actual = match_dir( |
| ["test_data/glob_dirs/**"], |
| allow_empty = False, |
| exclude = ["test_data/glob_dirs/*/**"], |
| ), |
| expected = "test_data/glob_dirs", |
| ) |
| |
| pw_string_list_comparison_test( |
| name = "single_match_glob", |
| actual = glob_dirs(["test_data/glob_dirs/nested_1"]), |
| expected = [ |
| "test_data/glob_dirs/nested_1", |
| ], |
| ) |
| |
| pw_string_list_comparison_test( |
| name = "partial_match_glob", |
| actual = glob_dirs(["test_data/glob_dirs/nested_*"]), |
| expected = [ |
| "test_data/glob_dirs/nested_1", |
| "test_data/glob_dirs/nested_2", |
| ], |
| ) |
| |
| pw_string_list_comparison_test( |
| name = "nested_match_glob", |
| actual = glob_dirs(["test_data/glob_dirs/*/foo"]), |
| expected = [ |
| "test_data/glob_dirs/nested_1/foo", |
| ], |
| ) |
| |
| pw_string_list_comparison_test( |
| name = "no_match_glob", |
| actual = glob_dirs(["test_data/glob_dirs/others/**"]), |
| expected = [ |
| ], |
| ) |
| |
| pw_string_list_comparison_test( |
| name = "no_match_subpackage", |
| actual = glob_dirs( |
| ["test_data/glob_dirs/subpackage"], |
| allow_empty = True, |
| ), |
| expected = [], |
| ) |
| |
| pw_bool_comparison_test( |
| name = "pigweed_is_root_test", |
| actual = pigweed_is_root(), |
| expected = True, |
| ) |
| |
| pw_copy_and_patch_file_test( |
| name = "patch_file_basic", |
| src = "test_data/pw_copy_and_patch_file/basic.txt", |
| out = "test_data/pw_copy_and_patch_file/patched_basic.txt", |
| expected = "test_data/pw_copy_and_patch_file/basic.expected", |
| patch_file = "test_data/pw_copy_and_patch_file/basic.patch", |
| ) |
| |
| pw_py_importable_runfile( |
| name = "test_runfile", |
| testonly = True, |
| src = "test_data/test_runfile.txt", |
| visibility = ["//pw_build:__subpackages__"], |
| ) |
| |
| pw_py_importable_runfile( |
| name = "test_runfile_remapped", |
| testonly = True, |
| src = "test_data/test_runfile.txt", |
| import_location = "pw_build.another_test_runfile", |
| visibility = ["//pw_build:__subpackages__"], |
| ) |
| |
| filegroup( |
| name = "doxygen", |
| srcs = [ |
| "public/pw_build/linker_symbol.h", |
| "public/pw_build/must_place.ld.h", |
| ], |
| ) |
| |
| sphinx_docs_library( |
| name = "docs", |
| srcs = [ |
| "CMakeLists.txt", |
| "bazel.rst", |
| "bazel_constraints.rst", |
| "bazel_helpers.rst", |
| "bazel_rules.rst", |
| "docs.rst", |
| "gn.rst", |
| "linker_scripts.rst", |
| "pigweed.bazelrc", |
| "pigweed.cmake", |
| "pigweed_recommended.bazelrc", |
| "project_builder.rst", |
| "proto/pigweed_build_driver.proto", |
| "proto/workflows.proto", |
| "python.gni", |
| "python.rst", |
| "python_api.rst", |
| "python_gn_args.gni", |
| "security.rst", |
| "workflows_build_drivers.rst", |
| "workflows_launcher.rst", |
| "//pw_build/py:docs", |
| ], |
| prefix = "pw_build/", |
| target_compatible_with = incompatible_with_mcu(), |
| ) |
| |
| # This target is used by the analysis tests in pw_pylint_test to confirm that |
| # pw_pylint.bzl is working. |
| py_console_script_binary( |
| name = "pw_pylint_test_test_target", |
| pkg = "@pigweed_python_packages//pylint", |
| script = "pylint", |
| tags = ["manual"], |
| visibility = ["//visibility:private"], |
| ) |
| |
| pw_pylint_test_suite(name = "pw_pylint_test") |