# Most of this file is to allow tensorflow to build.
# Inspired by TensorFlow serving's .bazelrc to build from the source.
# It also may be useful to refer to TensorFlow .bazelrc for more details:
# https://github.com/tensorflow/tensorflow/blob/master/.bazelrc

# Optimizations used for TF Serving release builds.
build:release --copt=-mavx
build:release --copt=-msse4.2

# Options used to build with CUDA.
build:cuda --repo_env TF_NEED_CUDA=1
build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain
build:cuda --@local_config_cuda//:enable_cuda
build:cuda --define=using_cuda=true --define=using_cuda_nvcc=true
build:cuda --action_env=TF_CUDA_COMPUTE_CAPABILITIES="sm_35,sm_50,sm_60,sm_70,sm_75,compute_80"

# Options used to build with TPU support.
build:tpu --distinct_host_configuration=false
build:tpu --define=with_tpu_support=true --define=framework_shared_object=false

# Please note that MKL on MacOS or windows is still not supported.
# If you would like to use a local MKL instead of downloading, please set the
# environment variable "TF_MKL_ROOT" every time before build.
build:mkl --define=build_with_mkl=true --define=enable_mkl=true --define=build_with_openmp=true
build:mkl --define=tensorflow_mkldnn_contraction_kernel=0

# This config option is used to enable MKL-DNN open source library only,
# without depending on MKL binary version.
build:mkl_open_source_only --define=build_with_mkl_dnn_only=true
build:mkl_open_source_only --define=build_with_mkl=true --define=enable_mkl=true
build:mkl_open_source_only --define=tensorflow_mkldnn_contraction_kernel=0

# Processor native optimizations (depends on build host capabilities).
build:nativeopt --copt=-march=native
build:nativeopt --host_copt=-march=native
build:nativeopt --copt=-O3

build --keep_going
build --verbose_failures=true
build --spawn_strategy=standalone
build --genrule_strategy=standalone

build --define=grpc_no_ares=true

# Sets the default Apple platform to macOS.
build --apple_platform_type=macos

build -c opt

# ViSQOL is overridding the default c++14 settings in tensorflow.
# TF's .bazelrc claims it c++14 required, but it is likely required
# in the sense that it is backwards compatible with c++17.
build --cxxopt=-std=c++17
build --linkopt=-ldl
build --host_cxxopt=-std=c++17

build --experimental_repo_remote_exec

# Enable platform specific config (e.g. by default use --config=windows when on windows, and --config=linux when on linux)
build --enable_platform_specific_config


## Windows config
startup --windows_enable_symlinks
build:windows --enable_runfiles

# These settings below allow for compilation using MSVC
# It would be nice to use clang to compile for Windows as well,
# but the bazel instructions did not work.
build:windows --copt=/D_USE_MATH_DEFINES
build:windows --host_copt=/D_USE_MATH_DEFINES
build:windows --cxxopt=-D_HAS_DEPRECATED_RESULT_OF=1

build:windows --cxxopt=/Zc:__cplusplus
# c++20 needed in MSVC for designated initializers (llvm libc++
# and gnu stc++ provides them in c++17).
build:windows  --cxxopt=/std:c++20
build:windows  --linkopt=-ldl
build:windows  --host_cxxopt=/std:c++20

# Make sure to include as little of windows.h as possible
build:windows --copt=-DWIN32_LEAN_AND_MEAN
build:windows --host_copt=-DWIN32_LEAN_AND_MEAN
build:windows --copt=-DNOGDI
build:windows --host_copt=-DNOGDI

# MSVC (Windows): Standards-conformant preprocessor mode
# See https://docs.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview
build:windows --copt=/Zc:preprocessor
build:windows --host_copt=/Zc:preprocessor

# Misc build options we need for windows according to tensorflow
build:windows --linkopt=/DEBUG
build:windows --host_linkopt=/DEBUG
build:windows --linkopt=/OPT:REF
build:windows --host_linkopt=/OPT:REF
build:windows --linkopt=/OPT:ICF
build:windows --host_linkopt=/OPT:ICF
# This is a workaround for this magic preprocessor constant/macro not existing
# in MSVC
build:windows --host_copt=-D__PRETTY_FUNCTION__=__FUNCSIG__
build:windows --copt=-D__PRETTY_FUNCTION__=__FUNCSIG__

# [visqol packaging patch 0001] GCC 13 dropped transitive <cstdint> includes;
# TF 2.11's tensorflow/lite/kernels/internal/spectrogram.cc uses uint32_t
# without including it. Force-include <cstdint> in every C++ TU.
build --cxxopt=-include --cxxopt=cstdint
