# Import any user defined rules.
try-import %workspace%/user.bazelrc

# Add C++14 compiler flags.
build --cxxopt=-std=c++14
build --host_cxxopt=-std=c++14

# Default to an optimized build.
build -c opt

# lexyacc
build --extra_toolchains=@dreal//third_party/com_github_google_kythe/tools/build_rules:lexyacc_remote_toolchain

# Default build options.
build --force_pic
build --strip=never
build --strict_system_includes

# Default test options.
test --test_output=errors

### Cpplint. ###
# By default, cpplint tests are run as part of `bazel test` alongside all of
# the other compilation and test targets.  This is a convenience shortcut to
# only do the cpplint testing and nothing else.
test:cpplint --build_tests_only
test:cpplint --test_tag_filters=cpplint

### ASan build. ###
build:asan --copt=-g
build:asan --copt=-fno-common
build:asan --copt=-fsanitize=address
build:asan --copt=-O0
build:asan --copt=-fno-omit-frame-pointer
build:asan --copt=-fno-optimize-sibling-calls
build:asan --copt=-DCDS_ADDRESS_SANITIZER_ENABLED
build:asan --copt -Wno-macro-redefined
build:asan --copt -D_FORTIFY_SOURCE=0
build:asan --linkopt=-fsanitize=address
build:asan --test_env=ASAN_OPTIONS
build:asan --test_env=LSAN_OPTIONS
build:asan --test_tag_filters=-no_asan,-no_lsan
build:asan --test_timeout=120,600,1800,7200

### LSan build. ###
build:lsan --copt=-g
build:lsan --copt=-fno-common
build:lsan --copt=-fsanitize=leak
build:lsan --copt=-O0
build:lsan --copt=-fno-omit-frame-pointer
build:lsan --copt -Wno-macro-redefined
build:lsan --copt -D_FORTIFY_SOURCE=0
build:lsan --linkopt=-fsanitize=leak
build:lsan --test_env=LSAN_OPTIONS
build:lsan --test_env=LSAN_SYMBOLIZER_PATH
build:lsan --test_tag_filters=-no_asan,-no_lsan
build:lsan --test_timeout=120,600,1800,7200

### TSan build. ###
build:tsan --build_tests_only
build:tsan --copt -g
build:tsan --copt -fsanitize=thread
build:tsan --copt -O1
build:tsan --copt -fno-omit-frame-pointer
build:tsan --copt -DCDS_THREAD_SANITIZER_ENABLED
build:tsan --copt -Wno-macro-redefined
build:tsan --copt -D_FORTIFY_SOURCE=0

# From Tsan documentation for Clang-3.9:
# fsanitize=thread flag will cause Clang to act as though the -fPIE flag
# had been supplied if compiling without -fPIC, and as though the
# -pie flag had been supplied if linking an executable
# Bug in GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67308
build:tsan --noforce_pic
build:tsan --linkopt -fsanitize=thread
build:tsan --test_env=TSAN_OPTIONS
build:tsan --test_tag_filters=-no_tsan
build:tsan --test_timeout=180,900,2700,10800

### UBSan build. ###
build:ubsan --build_tests_only
build:ubsan --copt -g
build:ubsan --copt -fsanitize=undefined
# Since Bazel uses clang instead of clang++, enabling -fsanitize=vptr would
# require extra linkopts that cause segmentation faults on pure C code.
build:ubsan --copt -fno-sanitize=float-divide-by-zero,vptr
build:ubsan --copt -O1
build:ubsan --copt -fno-omit-frame-pointer
build:ubsan --copt -Wno-macro-redefined
build:ubsan --copt -D_FORTIFY_SOURCE=0
build:ubsan --linkopt -fsanitize=undefined
build:ubsan --test_env=UBSAN_OPTIONS
build:ubsan --test_tag_filters=-no_ubsan
build:ubsan --test_timeout=120,600,1800,7200

### Kcov coverage build. ###
build:kcov --copt -g
build:kcov --copt -O0
test:kcov --spawn_strategy=local
test:kcov --run_under //tools:kcov
test:kcov --local_test_jobs=1
test:kcov --test_tag_filters=-cpplint,-pycodestyle,-no_kcov
test:kcov --nocache_test_results
test:kcov --test_timeout=120,600,1800,7200

# When compiling with dReal as the main WORKSPACE (i.e., if and only if this
# rcfile is loaded), we enable -Werror by default for dReal's *own* targets,
# but not for our externals.
#
# Developers may still disable errors locally by passing --copt=-w on the
# command line, or promote *any* warnings even from externals to errors via
# --copt=-Werror.
#
# When compiilng dReal as an external package, this rcfile is not loaded and we
# won't promote warnings to errors by default.
build --copt=-Werror