# Copyright 2019 Google LLC
#
# 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
#
#     http://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.

# To workaround a bug in Bazel [1], gRPC requires this flag on macOS builds,
# and there is (AFAIK) no way to "inherit" their definitions.
#   [1]: https://github.com/bazelbuild/bazel/issues/4341
build --copt=-DGRPC_BAZEL_BUILD

# Do not create the convenience links, they are incovenient when the build runs
# inside a docker image.
build --experimental_convenience_symlinks=ignore

# Clang Sanitizers, use with (for example):
#
# --client_env=CXX=clang++ --client_env=CC=clang --config asan
#

# --config asan: Address Sanitizer
build:asan --strip=never
build:asan --copt=-Og
build:asan --copt=-g
build:asan --copt=-fsanitize=address
build:asan --copt=-fno-omit-frame-pointer
build:asan --linkopt=-fsanitize=address
build:asan --action_env=ASAN_OPTIONS=detect_leaks=1:color=always
build:asan --action_env=LSAN_OPTIONS=report_objects=1

# --config tsan: Thread Sanitizer
build:tsan --strip=never
build:tsan --copt=-Og
build:tsan --copt=-g
build:tsan --copt=-fsanitize=thread
build:tsan --copt=-fno-omit-frame-pointer
build:tsan --linkopt=-fsanitize=thread
build:tsan --action_env=TSAN_OPTIONS=halt_on_error=1:second_deadlock_stack=1

# --config ubsan: Undefined Behavior Sanitizer
build:ubsan --strip=never
build:ubsan --copt=-Og
build:ubsan --copt=-g
build:ubsan --copt=-fsanitize=undefined
build:ubsan --copt=-fno-omit-frame-pointer
build:ubsan --linkopt=-fsanitize=undefined
build:ubsan --linkopt=-fsanitize-link-c++-runtime
build:ubsan --action_env=UBSAN_OPTIONS=halt_on_error=1:print_stacktrace=1
build:ubsan --cxxopt=-stdlib=libc++
build:ubsan --linkopt=-stdlib=libc++
build:ubsan --linkopt=-lc++
build:ubsan --linkopt=-lc++abi

# --config msan: Memory Sanitizer
build:msan --strip=never
build:msan --copt=-Og
build:msan --copt=-g
build:msan --copt=-fsanitize=memory
build:msan --copt=-fno-omit-frame-pointer
build:msan --copt=-fsanitize-memory-track-origins
build:msan --copt=-fsanitize-memory-use-after-dtor
build:msan --linkopt=-fsanitize=memory
build:msan --action_env=MSAN_OPTIONS=poison_in_dtor=1
build:msan --cxxopt=-stdlib=libc++
build:msan --linkopt=-stdlib=libc++
build:msan --linkopt=-lc++
build:msan --linkopt=-lc++abi

# --config libcxx: Compile and link using libc++.
build:libcxx --cxxopt=-stdlib=libc++
build:libcxx --linkopt=-stdlib=libc++
build:libcxx --linkopt=-lc++
build:libcxx --linkopt=-lc++abi
