1# Copyright 2024 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 15module( 16 name = "pigweed", 17 version = "0.0.1", 18) 19 20register_execution_platforms("@local_config_platform//:host", "//pw_build/platforms:all") 21 22bazel_dep(name = "bazel_skylib", version = "1.7.1") 23bazel_dep(name = "boringssl", version = "0.20240913.0") 24bazel_dep(name = "freertos", version = "10.5.1.bcr.2") 25bazel_dep(name = "gazelle", version = "0.36.0", repo_name = "bazel_gazelle") 26bazel_dep(name = "nanopb", repo_name = "com_github_nanopb_nanopb") 27bazel_dep(name = "pico-sdk", version = "2.0.0") 28bazel_dep(name = "picotool", version = "2.0.0") 29bazel_dep(name = "platforms", version = "0.0.10") 30bazel_dep(name = "protobuf", version = "24.4", repo_name = "com_google_protobuf") 31bazel_dep(name = "rules_cc", version = "0.0.10") 32bazel_dep(name = "rules_fuzzing", version = "0.5.2") 33bazel_dep(name = "rules_go", version = "0.49.0", repo_name = "io_bazel_rules_go") 34bazel_dep(name = "rules_jvm_external", version = "6.2") 35bazel_dep(name = "rules_libusb", version = "0.1.0-rc1") 36bazel_dep(name = "rules_license", version = "1.0.0") 37bazel_dep(name = "rules_platform", version = "0.1.0") 38bazel_dep(name = "rules_probe_rs", version = "0.0.2") 39bazel_dep(name = "rules_proto", version = "6.0.2") 40bazel_dep(name = "rules_python", version = "0.36.0") 41bazel_dep(name = "rules_rust", version = "0.52.2") 42 43# LINT.IfChange(emboss) 44bazel_dep(name = "emboss", version = "2024.1017.203246", repo_name = "com_google_emboss") 45# LINT.ThenChange(/pw_package/py/pw_package/packages/emboss.py:emboss) 46 47bazel_dep(name = "hedron_compile_commands", dev_dependency = True) 48 49# Repository overrides 50# ==================== 51 52# TODO: https://pwbug.dev/349880767 - Point this back to the upstream repo once 53# this PR is merged. 54archive_override( 55 module_name = "hedron_compile_commands", 56 strip_prefix = "bazel-compile-commands-extractor-163521345aa6366fd1ed801b989b668b5c806f69", 57 urls = ["https://github.com/chadnorvell/bazel-compile-commands-extractor/archive/163521345aa6366fd1ed801b989b668b5c806f69.tar.gz"], 58) 59 60# TODO: https://pwbug.dev/354274498 - nanopb is not yet in the BCR. 61git_override( 62 module_name = "nanopb", 63 commit = "f9191cd0be4177abd0d04546d61d59a9b6c32de3", 64 remote = "https://github.com/nanopb/nanopb.git", 65) 66 67single_version_override( 68 module_name = "rules_rust", 69 patch_strip = 1, 70 patches = [ 71 # Adds prototype functionality for documenting multiple crates in one 72 # HTML output directory. While the approach in this patch may have 73 # issues scaling to giant mono-repos, it is appropriate for embedded 74 # projects and minimally invasive and should be easy to maintain. Once 75 # the `rules_rust` community decides on a way to propperly support this, 76 # we will migrate to that solution. 77 # https://github.com/konkers/rules_rust/tree/wip/rustdoc 78 "//pw_rust/bazel_patches:0002-PROTOTYPE-Add-ability-to-document-multiple-crates-at.patch", 79 ], 80) 81 82# Transitive deps not in BCR 83# ========================== 84http_archive = use_repo_rule( 85 "@bazel_tools//tools/build_defs/repo:http.bzl", 86 "http_archive", 87) 88 89# TODO(b/370523804): Remove this once the following issues are addressed in a 90# released version of rules_fuzzing 91# https://github.com/bazel-contrib/rules_fuzzing/issues/257 92non_module_dependencies = use_extension("@rules_fuzzing//fuzzing/private:extensions.bzl", "non_module_dependencies") 93use_repo( 94 non_module_dependencies, 95 "rules_fuzzing_oss_fuzz", 96) 97 98# Configure libusb 99# ================ 100# 101# The rules_libusb lets you configure which actual libusb version to use. 102libusb = use_extension("@rules_libusb//:extensions.bzl", "libusb") 103libusb.source_release(min_version = "1.0.27") 104use_repo(libusb, "libusb") 105 106# Configure C++ toolchains 107# ======================== 108# 109# TODO: https://pwbug.dev/346388161 - Migrate to the rules_cc toolchain API. 110bazel_dep(name = "pw_toolchain") 111local_path_override( 112 module_name = "pw_toolchain", 113 path = "pw_toolchain_bazel", 114) 115 116xcode_sdk_repository = use_repo_rule("//pw_toolchain:xcode.bzl", "xcode_sdk_repository") 117 118xcode_sdk_repository( 119 name = "macos_sysroot", 120 build_file = "//pw_toolchain/host_clang:macos_sysroot.BUILD", 121) 122 123cipd_client_repository = use_repo_rule("//pw_env_setup/bazel/cipd_setup:cipd_rules.bzl", "_cipd_client_repository") 124 125cipd_client_repository(name = "cipd_client") 126 127cipd_repository = use_repo_rule("//pw_env_setup/bazel/cipd_setup:cipd_rules.bzl", "cipd_repository") 128 129# Fetch llvm toolchain. 130cipd_repository( 131 name = "llvm_toolchain", 132 build_file = "//pw_toolchain/build_external:llvm_clang.BUILD", 133 path = "fuchsia/third_party/clang/${os}-${arch}", 134 tag = "git_revision:8280651ad57cb9fb24a404cec2401040c28dec98", 135) 136 137# TODO: b/366374135 - This is behind, most recent version 138# is in pw_env_setup/py/pw_env_setup/cipd_setup/pigweed.json 139cipd_repository( 140 name = "llvm_toolchain_device", 141 build_file = "//pw_toolchain/build_external:llvm_clang.BUILD", 142 path = "fuchsia/third_party/clang/${os}-${arch}", 143 tag = "git_revision:0dcada94bb1ae79f0edd91013038098c62a96b3b", 144) 145 146# Fetch linux sysroot for host builds. 147cipd_repository( 148 name = "linux_sysroot", 149 build_file = "//pw_toolchain/host_clang:linux_sysroot.BUILD", 150 path = "fuchsia/third_party/sysroot/bionic", 151 tag = "git_revision:702eb9654703a7cec1cadf93a7e3aa269d053943", 152) 153 154# Fetch gcc-arm-none-eabi toolchain. 155cipd_repository( 156 name = "gcc_arm_none_eabi_toolchain", 157 build_file = "//pw_toolchain/build_external:arm_none_eabi_gcc.BUILD", 158 path = "fuchsia/third_party/armgcc/${os}-${arch}", 159 tag = "version:[email protected]", 160) 161 162register_toolchains( 163 "//pw_toolchain:cc_toolchain_cortex-m0", 164 "//pw_toolchain:cc_toolchain_cortex-m0plus", 165 "//pw_toolchain:cc_toolchain_cortex-m33", 166 "//pw_toolchain/arm_gcc:arm_gcc_cc_toolchain_cortex-m3", 167 "//pw_toolchain/arm_gcc:arm_gcc_cc_toolchain_cortex-m4", 168 "//pw_toolchain/arm_gcc:arm_gcc_cc_toolchain_cortex-m4+nofp", 169 "//pw_toolchain/arm_gcc:arm_gcc_cc_toolchain_cortex-m33+nofp", 170 "//pw_toolchain/host_clang:host_cc_toolchain_linux", 171 "//pw_toolchain/host_clang:host_cc_toolchain_macos", 172 dev_dependency = True, 173) 174 175register_toolchains( 176 "//pw_toolchain/fuchsia:all", 177 dev_dependency = True, 178) 179 180# Rust toolchains 181pw_rust = use_extension("//pw_toolchain/rust:extensions.bzl", "pw_rust") 182pw_rust.toolchain(cipd_tag = "rust_revision:bf9c7a64ad222b85397573668b39e6d1ab9f4a72") 183use_repo(pw_rust, "pw_rust_toolchains") 184 185register_toolchains( 186 "@pw_rust_toolchains//:all", 187 dev_dependency = True, 188) 189 190git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") 191 192# Vendored third party rust crates. 193git_repository( 194 name = "rust_crates", 195 commit = "ed1ec1bd240b9446b30af5331b960871a0503a6c", 196 remote = "https://pigweed.googlesource.com/third_party/rust_crates", 197) 198 199# Get probe-rs 200# ============ 201 202# TODO: https://pwbug.dev/346388161 - Re enable use of rules_probe_rs once rp2350 203# support is upstreamed. 204# 205# probe_rs = use_extension("@rules_probe_rs//probe_rs:extensions.bzl", "probe_rs") 206# probe_rs.tools( 207# name = "probe_rs", 208# version = "0.24.0", 209# ) 210# use_repo(probe_rs, "probe_rs") 211 212# Use pre-release prebuilts for RP2350 support. 213cipd_repository( 214 name = "probe_rs", 215 build_file = "@pigweed//third_party/probe-rs:probe-rs.BUILD.bazel", 216 path = "pigweed/third_party/probe-rs/${os}-${arch}", 217 tag = "git_revision:37660106aba307cbab5cf6c2b0da57b72b6dc4e9", 218) 219 220# Configure Python toolchains and pip dependencies. 221# ================================================= 222python = use_extension("@rules_python//python/extensions:python.bzl", "python") 223python.toolchain( 224 # Allows building as root in a docker container. Required by oss-fuzz. 225 ignore_root_user_error = True, 226 is_default = True, 227 python_version = "3.11", 228) 229use_repo(python, "pythons_hub") 230 231pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") 232pip.parse( 233 hub_name = "python_packages", 234 python_version = "3.11", 235 requirements_darwin = "//pw_env_setup/py:pw_env_setup/virtualenv_setup/upstream_requirements_darwin_lock.txt", 236 requirements_linux = "//pw_env_setup/py:pw_env_setup/virtualenv_setup/upstream_requirements_linux_lock.txt", 237 requirements_windows = "//pw_env_setup/py:pw_env_setup/virtualenv_setup/upstream_requirements_windows_lock.txt", 238) 239use_repo(pip, "python_packages") 240 241# TODO: b/354241571 - The next two lines are only required because the Fuchsia 242# SDK doesn't correctly restrict the target platform compatibility of all its 243# targets. We should remove them once the bug is fixed. 244register_toolchains("@pythons_hub//:all") 245 246register_toolchains("@rules_python//python/runtime_env_toolchains:all") 247 248# Configure Go dependencies 249# ========================= 250go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps") 251go_deps.from_file(go_mod = "//:go.mod") 252use_repo(go_deps, "org_golang_google_grpc", "org_golang_google_grpc_examples", "org_golang_google_protobuf") 253 254# Configure Java dependencies 255# =========================== 256maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") 257maven.install( 258 artifacts = [ 259 "com.google.auto.value:auto-value-annotations:1.8.2", 260 "com.google.auto.value:auto-value:1.8.2", 261 "com.google.code.findbugs:jsr305:3.0.2", 262 "com.google.flogger:flogger-system-backend:0.7.1", 263 "com.google.flogger:flogger:0.7.1", 264 "com.google.guava:failureaccess:1.0.2", 265 "com.google.guava:guava:31.0.1-jre", 266 "com.google.truth:truth:1.1.3", 267 "org.mockito:mockito-core:4.1.0", 268 ], 269 repositories = [ 270 "https://maven.google.com/", 271 "https://jcenter.bintray.com/", 272 "https://repo1.maven.org/maven2", 273 ], 274) 275use_repo( 276 maven, 277 "maven", 278) 279 280# Vendored libraries 281# ================== 282 283# TODO: https://pwbug.dev/378531541 - These are one-off external libraries that 284# are NOT in the BCR that downstream users may need to override/unify to their 285# expected version. 286 287new_git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") 288 289# TODO: https://pwbug.dev/378531541 - Get micro_ecc from the BCR. 290new_git_repository( 291 name = "micro_ecc", 292 build_file = "//:third_party/micro_ecc/BUILD.micro_ecc", 293 commit = "b335ee812bfcca4cd3fb0e2a436aab39553a555a", 294 remote = "https://github.com/kmackay/micro-ecc.git", 295) 296 297# TODO: https://pwbug.dev/354749299 - Use the BCR version of mbedtls. 298http_archive( 299 name = "mbedtls", 300 build_file = "//:third_party/mbedtls/mbedtls.BUILD.bazel", 301 sha256 = "241c68402cef653e586be3ce28d57da24598eb0df13fcdea9d99bfce58717132", 302 strip_prefix = "mbedtls-2.28.8", 303 url = "https://github.com/Mbed-TLS/mbedtls/releases/download/v2.28.8/mbedtls-2.28.8.tar.bz2", 304) 305 306# TODO: https://github.com/bazelbuild/bazel/issues/23077 - Make these 307# bazel_deps dev_dependencies once archive_override has a build_file argument. 308http_archive( 309 name = "stm32f4xx_hal_driver", 310 build_file = "//third_party/stm32cube:stm32_hal_driver.BUILD.bazel", 311 sha256 = "d0427a3830f0c23dd4810952321b8209be7b3c50897d1fc2d79587435cc3a379", 312 strip_prefix = "stm32f4xx-hal-driver-1.8.0", 313 urls = ["https://github.com/STMicroelectronics/stm32f4xx-hal-driver/archive/refs/tags/v1.8.0.tar.gz"], 314) 315 316http_archive( 317 name = "cmsis_device_f4", 318 build_file = "//third_party/stm32cube:cmsis_device.BUILD.bazel", 319 sha256 = "1d9612ecaaab8708c88be2c9573927f2e5e9a911aa2c1427182b545ed5ed0fd6", 320 strip_prefix = "cmsis-device-f4-2.6.8", 321 urls = ["https://github.com/STMicroelectronics/cmsis-device-f4/archive/refs/tags/v2.6.8.tar.gz"], 322) 323 324http_archive( 325 name = "cmsis_core", 326 build_file = "//third_party/stm32cube:cmsis_core.BUILD.bazel", 327 sha256 = "32f226c31d7d1ff4a504404400603e047b99f405cd0c9a8f417f1f250251b829", 328 strip_prefix = "cmsis-core-5.4.0_cm4", 329 urls = ["https://github.com/STMicroelectronics/cmsis-core/archive/refs/tags/v5.4.0_cm4.tar.gz"], 330) 331 332# Other Pigweed-specific dependencies 333# =================================== 334cipd_repository( 335 name = "bloaty", 336 path = "fuchsia/third_party/bloaty/${os}-amd64", 337 tag = "git_revision:c057ba4f43db0506d4ba8c096925b054b02a8bd3", 338) 339 340# Set up legacy pw_transfer test binaries. 341# Required by: pigweed. 342# Used in modules: //pw_transfer. 343cipd_repository( 344 name = "pw_transfer_test_binaries", 345 # Only ever needed if you run the pw_transfer unit tests. 346 dev_dependency = True, 347 path = "pigweed/pw_transfer_test_binaries/${os=linux}-${arch=amd64}", 348 tag = "version:pw_transfer_test_binaries_528098d588f307881af83f769207b8e6e1b57520-linux-amd64-cipd.cipd", 349) 350