• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 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#
15
16# Standard flags required for all Pigweed projects.
17import %workspace%/pw_build/pigweed.bazelrc
18import %workspace%/pw_build/pigweed_recommended.bazelrc
19
20# TODO: https://pwbug.dev/258836641 - Only until bzlmod migration is done.
21common --enable_workspace
22
23# Default build_tag_filters and test_tag_filters
24# ==============================================
25# Skip building any targets tagged do_not_build.
26build --build_tag_filters=-do_not_build,-kernel
27
28# Exclude integration tests from the default build. The test_tag_filters flag
29# doesn't accumulate (https://github.com/bazelbuild/bazel/issues/7322): we have
30# to specify it only once, setting all the exclusions in a comma-separated
31# list.
32test --test_tag_filters=-integration,-do_not_build,-do_not_run_test,-kernel
33
34# C++ related flags
35# =================
36# Picotool needs to build with exceptions and RTTI enabled.
37common --per_file_copt=external.*picotool.*@-fexceptions,-frtti
38common --host_per_file_copt=external.*picotool.*@-fexceptions,-frtti
39
40# RP2xxx PIO assembler also needs exceptions.
41common --host_per_file_copt=external.*pioasm.*@-fexceptions,-frtti
42
43# Default to C++17 to ensure compatibility.
44common --//pw_toolchain/cc:cxx_standard=17
45common:cxx20 --//pw_toolchain/cc:cxx_standard=20
46
47# Silence compiler warnings from external repositories.
48#
49# TODO: https://pwbug.dev/347317581 - This is supported by Bazel's default C++
50# toolchain, but not yet by Pigweed's own toolchains.
51build --features=external_include_paths
52
53# Turn on internal warnings for upstream Pigweed. DO NOT enable in downstream
54# projects to allow for warnings to be added in the future without breaking
55# downstream.
56#
57build --features=internal_strict_warnings
58
59# This feature can't be enabled until __unordtf2 and __letf2 are implemented by
60# compiler-rt. See https://reviews.llvm.org/D53608.
61# build --features=fully_static_link
62
63# Required for combined code coverage reports.
64coverage --experimental_generate_llvm_lcov
65coverage --combined_report=lcov
66
67
68# Enable layering check support.
69#
70# NOTE: this _does not_ by itself enable the layering check; that's done in
71# REPO.bazel. This flag only ensures the module maps for sysroot and toolchain
72# headers (needed for the layering check to not produce false positives) are
73# constructed. Module map construction is gated behind a flag because the
74# approach we take does not work in Bazel versions older than 8.0.0, so some
75# downstream projects using Pigweed's toolchains would be broken if this flag
76# was removed and always set to true in the toolchain definition.
77common --//pw_toolchain/host_clang:layering_check
78
79# Rust related flags
80# ==================
81# Ensure that rust channel gets propagated to the exec config under which
82# proc-macros and build.rs files are built.
83common --experimental_propagate_custom_flag=@@rules_rust+//rust/toolchain/channel:channel
84
85# Java related flags
86# ==================
87# Workaround for https://github.com/bazelbuild/rules_jvm_external/issues/445.
88build --java_language_version=11
89build --tool_java_language_version=11
90build --java_runtime_version=remotejdk_11
91build --repo_env=JAVA_HOME=../bazel_tools/jdk
92
93# JavaScript related flags
94# ========================
95# Allow the Bazel server to check directory sources for changes. Ensures that the Bazel server
96# notices when a directory changes, if you have a directory listed in the srcs of some target.
97# Recommended when using
98# [copy_directory](https://github.com/aspect-build/bazel-lib/blob/main/docs/copy_directory.md) and
99# [rules_js](https://github.com/aspect-build/rules_js) since npm package are source directories
100# inputs to copy_directory actions.
101# Docs: https://bazel.build/reference/command-line-reference#flag--host_jvm_args
102#
103# Ultimately, this is a workaround for
104# https://github.com/aspect-build/rules_js/issues/1408. See also
105# https://github.com/bazelbuild/bazel/commit/c64421bc35214f0414e4f4226cc953e8c55fa0d2.
106startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1
107
108# Default label flags values
109# ==========================
110build --@freertos//:freertos_config=//third_party/freertos:freertos_config
111build --@mbedtls//:mbedtls_config=//third_party/mbedtls:default_config
112
113# We use non-default labels for the STM32Cube repositories upstream (to reserve
114# the option of building for more than one MCU family down the road), so need to
115# override the three labels below.
116common --//third_party/stm32cube:hal_driver=@stm32f4xx_hal_driver//:hal_driver
117common --@stm32f4xx_hal_driver//:cmsis_device=@cmsis_device_f4//:cmsis_device
118common --@stm32f4xx_hal_driver//:cmsis_init=@cmsis_device_f4//:default_cmsis_init
119common --@cmsis_device_f4//:cmsis_core=@cmsis_core
120
121common --//pw_env_setup/py:pigweed_json=//:pigweed_json
122common --experimental_propagate_custom_flag=//pw_env_setup/py:pigweed_json
123
124build --//pw_function:config_override=//pw_function:upstream_default_config
125
126# These flags may be read by tooling running in the exec configuration.
127common --experimental_propagate_custom_flag=//pw_build/luci:is_ci
128common --experimental_propagate_custom_flag=//pw_build/luci:is_shadow
129
130
131# Sanitizer config definitions
132# ============================
133common:asan --//pw_toolchain/host_clang:asan
134# TODO: https://github.com/bazelbuild/bazel/issues/7322 - We need to repeat the
135# -integration because the test_tag_filters flag does not
136# accumulate.
137test:asan --test_tag_filters=-integration,-noasan,-do_not_build,-do_not_run_test,-kernel
138
139common:ubsan --//pw_toolchain/host_clang:ubsan
140# TODO: https://github.com/bazelbuild/bazel/issues/7322 - We need to repeat the
141# -integration because the test_tag_filters flag does not accumulate.
142test:ubsan --test_tag_filters=-integration,-noubsan,-do_not_build,-do_not_run_test,-kernel
143
144common:tsan --//pw_toolchain/host_clang:tsan
145# TODO: https://github.com/bazelbuild/bazel/issues/7322 - We need to repeat the
146# -integration because the test_tag_filters flag does not accumulate.
147test:tsan --test_tag_filters=-integration,-notsan,-do_not_build,-do_not_run_test,-kernel
148
149# Include libFuzzer build configurations.
150import %workspace%/pw_fuzzer/libfuzzer.bazelrc
151
152# Include FuzzTest build configurations.
153import %workspace%/pw_fuzzer/fuzztest.bazelrc
154
155# clang-tidy configuration
156build:clang-tidy --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect
157build:clang-tidy --output_groups=report
158build:clang-tidy --@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config
159build:clang-tidy --@bazel_clang_tidy//:clang_tidy_executable=//pw_toolchain/host_clang:copy_clang_tidy
160build:clang-tidy --@bazel_clang_tidy//:clang_tidy_additional_deps=//pw_toolchain/host_clang:sysroot_root
161build:clang-tidy --build_tag_filters=-noclangtidy
162# We need to disable this warning to avoid spurious "#pragma once in main file"
163# warnings for header-only libraries. For another approach, see
164# https://github.com/mongodb-forks/bazel_clang_tidy/pull/2
165#
166# TODO: https://pwbug.dev/341723612 - What do we do in GN?
167build:clang-tidy --copt=-Wno-pragma-once-outside-header
168
169# For some platforms i.e. google/oss-fuzz we need to use the system provided
170# rather than the hermetic toolchains. This allows oss-fuzz to override the
171# build with specialised compilers that are tightly coupled to the fuzzing
172# runtimes.
173# Detect toolchains
174common:non_hermetic --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=0
175common:non_hermetic --extra_toolchains=@local_config_cc_toolchains//...
176
177# Configure workspace status command to test pw_build_info git_build_info
178# https://bazel.build/docs/user-manual#workspace-status-command
179# TODO: b/348046338 - Add a Windows version of this command
180build --workspace_status_command=pw_build_info/git_workspace_status_command.sh
181
182# Target platform config definitions
183# ==================================
184# Exclude //pw_bluetooth_sapphire/fuchsia when the host platform is not
185# linux-amd64. This is the only platform that the Fuchsia SDK supports.
186common --enable_platform_specific_config
187
188# Import `--config=fuchsia` scoped pigweed backends.
189import %workspace%/pw_bluetooth_sapphire/fuchsia/backends.bazelrc
190
191# TODO: https://pwbug.dev/382533028 - The Fuchsia SDK doesn't work with these
192# flags yet. Unfortunately, this needs to be switched for all build types since
193# it's required for things to load properly in pw_bluetooth_sapphire.
194common --noincompatible_disallow_empty_glob
195
196# Configs for RP2xxx platforms.
197build:rp2040 --platforms=@pigweed//targets/rp2040
198test:rp2040 --run_under=//targets/rp2040/py:unit_test_client
199
200build:rp2350 --platforms=@pigweed//targets/rp2040:rp2350
201test:rp2350 --run_under=//targets/rp2040/py:unit_test_client
202
203# Config for the stm32f429i_disc1 baremetal platform.
204build:stm32f429i_baremetal --platforms=//targets/stm32f429i_disc1:platform
205
206# Config for the stm32f429i_disc1_stm32cube freertos platform.
207build:stm32f429i_freertos --platforms=//targets/stm32f429i_disc1_stm32cube:platform
208
209# Config for the lm3s6965evb platform, used to build pw_rust/examples.
210build:lm3s6965evb --platforms=//targets/lm3s6965evb
211
212# Config for the microbit platform, used to build pw_rust/examples.
213build:microbit --platforms=//targets/microbit
214
215# GoogleTest config
216# =================
217# This config can be used to build and run host tests using GoogleTest instead
218# of the default //pw_unit_test:light framework.
219common:googletest --//pw_unit_test:backend=//pw_unit_test:googletest
220common:googletest --//pw_unit_test:main=@com_google_googletest//:gtest_main
221
222# Remote execution config definitions
223# ===================================
224# Use the remote cache. This will only work for users who have permission to access it.
225common:remote_cache --bes_backend="buildeventservice.googleapis.com"
226common:remote_cache --bes_instance_name=pigweed-rbe-open
227common:remote_cache --bes_results_url="https://source.cloud.google.com/results/invocations/"
228common:remote_cache --bes_timeout=600s
229common:remote_cache --experimental_remote_cache_eviction_retries=5
230common:remote_cache --google_default_credentials=true
231# Required to use buildeventservice on Bazel 8+.
232# TODO: b/345556899 -- Remove this flag when no longer required.
233common:remote_cache --legacy_important_outputs
234common:remote_cache --remote_cache=grpcs://remotebuildexecution.googleapis.com
235common:remote_cache --remote_instance_name=projects/pigweed-rbe-open/instances/default-instance
236common:remote_cache --remote_upload_local_results=false
237# TODO: https://github.com/bazelbuild/bazel/issues/24867 - This flag breaks
238# runfiles handling with remote caching, and causes a bunch of
239# java.io.FileNotFoundException when creating runfiles trees.
240common:remote_cache --experimental_inprocess_symlink_creation=false
241
242# cache-silo-key: this is essentially a "salt" added to the remote cache key.
243# Change it to a new value when we want to create a new cache from scratch
244# (e.g. to recover from cache poisoning). We've used the current date in
245# YYYYMMDD format in the past.
246common --remote_default_exec_properties=cache-silo-key=20240918
247
248# Configs for experimental //pw_kernel
249import %workspace%/pw_kernel/kernel.bazelrc
250
251# User bazelrc file
252# =================
253# See https://bazel.build/configure/best-practices#bazelrc-file
254#
255# Note: this should be at the bottom of the file, so that user-specified
256# options override anything in this file
257# (https://bazel.build/run/bazelrc#imports)
258try-import %workspace%/user.bazelrc
259