blob: d62f3f058834a82182d0b852cebb6380a812a222 [file] [log] [blame]
Drew Macrae78a58872021-09-07 20:52:19 +00001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4
Drew Macrae7ac1efb2021-09-22 16:08:28 +00005# https://docs.opentitan.org/doc/rm/c_cpp_coding_style/#cxx-version specifies
Chris Frantz50931152022-09-01 00:52:57 +00006build --action_env=BAZEL_CXXOPTS="-std=gnu++14"
Chris Frantzdb5ae4d2022-06-21 18:32:47 -07007build --cxxopt='-std=gnu++14'
8build --conlyopt='-std=gnu11'
Drew Macrae7ac1efb2021-09-22 16:08:28 +00009
Alphan Ulusoy883d3a92022-06-09 16:42:08 -040010# Never strip debugging information so that we can produce annotated
11# disassemblies when compilation mode is fastbuild.
12build --strip='never'
13
Drew Macrae3f2e2312021-12-02 21:56:00 +000014# Bazel embedded enables the following feature which along with -std=c11 and
15# our codebase generates a lot of warnings by setting the -Wpedantic flag
16build --features=-all_warnings
17
Drew Macrae7ac1efb2021-09-22 16:08:28 +000018# Enable toolchain resolution with cc
19build --incompatible_enable_cc_toolchain_resolution
Drew Macrae399af402021-11-01 18:15:09 +000020
Drew Macrae3f2e2312021-12-02 21:56:00 +000021# This lets us generate key/value pairs for the workspace which can be
Drew Macrae399af402021-11-01 18:15:09 +000022# accessed like we do in util/BUILD
23build --workspace_status_command=util/get_workspace_status.sh
Chris Frantzb231f112021-12-02 15:42:10 -080024
Drew Macrae7e867022022-07-14 13:09:22 -040025# This enables convenient building for opentitan targets with the argument
26# --config=riscv32
Timothy Trippelaaf5e532022-08-29 20:19:28 -070027build:riscv32 --platforms=@crt//platforms/riscv32:opentitan
Drew Macrae7e867022022-07-14 13:09:22 -040028
Alphan Ulusoy221eeab2022-12-28 13:45:40 -050029# Shared configuration for clang's source-based coverage instrumentation.
30# Bazel seems to support this only partially, thus we have to perform some
31# additional processing. See
Alphan Ulusoy5377dba2022-12-14 08:33:21 -050032# https://github.com/bazelbuild/bazel/commit/21b5eb627d78c09d47c4de957e9e6b56a9ae6fad
33# and `util/coverage/coverage_off_target.py`.
Alphan Ulusoy221eeab2022-12-28 13:45:40 -050034build:ot_coverage --repo_env='CC=clang'
35build:ot_coverage --repo_env='BAZEL_USE_LLVM_NATIVE_COVERAGE=1'
36build:ot_coverage --java_runtime_version='remotejdk_11'
37# Docs state that bazel will fail to create coverage information if tests have
38# been cached previously. See
39# https://bazel.build/configure/coverage?hl=en#remote-execution
40coverage:ot_coverage --nocache_test_results
41
42# Configuration for measuring off-target coverage. Enable with
43# `--config=ot_coverage_off_target`.
44build:ot_coverage_off_target --config='ot_coverage'
45build:ot_coverage_off_target --collect_code_coverage
46coverage:ot_coverage_off_target --repo_env='GCOV=/usr/bin/llvm-profdata'
47coverage:ot_coverage_off_target --repo_env='BAZEL_LLVM_COV=/usr/bin/llvm-cov'
Drew Macraed5536ef2021-12-12 19:33:59 -080048
Alphan Ulusoy56a5dce2022-12-28 13:46:01 -050049# Configuration for measuring on-target coverage. Enable with
50# `--config=ot_coverage_on_target`.
51build:ot_coverage_on_target --config='ot_coverage'
52build:ot_coverage_on_target --platforms="@crt//platforms/riscv32:opentitan"
53build:ot_coverage_on_target --define='measure_coverage_on_target=true'
54# Instrument selectively to limit size overhead when measuring on-target coverage.
55# Note: We have to disable optimizations until the corresponding item in #16761 is
56# resolved.
57build:ot_coverage_on_target --per_file_copt='//sw/device/silicon_creator[/:].*,//sw/device/lib/base:.*@-fprofile-instr-generate,-fcoverage-mapping,-O0'
58# Needed to be able to build host binaries while collecting coverage.
59coverage:ot_coverage_on_target --platforms=""
60
Drew Macrae56036292022-12-21 12:51:40 -050061# Configuration to override resource constrained test
62# scheduling. Enable with `--config=local_test_jobs_per_cpus`
63test:local_test_jobs_per_cpus --local_test_jobs=HOST_CPUS*0.22
64# Verilator is built for 4 cores, but requires a harness and additional overhead.
65# Empirically 72 cores can support 16 simultaneous tests, but not 17. Setting
66# this will ignore tags like "cpu:5"
Dan McArdle0d212ce2022-07-20 13:12:16 -040067
Drew Macrae5d721012022-12-10 21:55:00 -050068# We have verilator tests that take more than an hour to complete
69test --test_timeout=60,300,1500,7200
70
Dan McArdle0d212ce2022-07-20 13:12:16 -040071# AddressSanitizer (ASan) catches runtime out-of-bounds accesses to globals, the
72# stack, and (less importantly for OpenTitan) the heap. ASan instruments
73# programs at compile time and also requires a runtime library.
74#
75# ASan documentation: https://clang.llvm.org/docs/AddressSanitizer.html
76#
77# Enable ASan with --config=asan.
78build:asan --copt -fsanitize=address
79build:asan --copt -g
80build:asan --strip=never
81build:asan --copt -fno-omit-frame-pointer
82build:asan --linkopt -fsanitize=address
83
84# UndefinedBehaviorSanitizer (UBSan) catches C/C++ undefined behavior at
85# runtime, e.g. signed integer overflow. UBSan instruments programs at compile
86# time and also requires a runtime library.
87#
88# UBSan documentation:
89# https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
90#
91# Enable UBSan with --config=ubsan.
92build:ubsan --copt -fsanitize=undefined
93build:ubsan --copt -g
94build:ubsan --strip=never
95build:ubsan --copt -fno-omit-frame-pointer
96build:ubsan --linkopt -fsanitize=undefined
Martin Lueker-Boden7e3bb0a2022-09-05 14:38:50 -070097
Chris Frantz10450612022-10-12 10:03:48 -070098# Enable the rust 'clippy' linter.
99build --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
100build --output_groups=+clippy_checks
101
Martin Lueker-Boden7e3bb0a2022-09-05 14:38:50 -0700102# Import site-specific configuration.
103try-import .bazelrc-site