# By default, the host platform is targeted with the default c toolchain,
# likely using gcc/libstdc++ on Linux.
#
# To select the android ARM64 platform, build with `--config=android_arm64`
#
# The Android platform and the clang toolchain requires an external
# toolchain (NDK with clang/libc++) that
# needs setup by the user.  See README.md for instructions.
#
# If clang/libc++ is installed to /usr/local/ it can be used with linux builds
# instead of the default (gcc) by building with `--config=clang_toolchain`.
# Since this will provide no specific advantages for most users, and the process
# of installing a specific clang toolchain is a bit involved, the documentation
# for clang toolchain setup is in toolchain/

build --cxxopt=-std=gnu++17
build --linkopt=-lm
# Use the default C++ toolchain to build the tools used during the
# build.
build --host_crosstool_top=@bazel_tools//tools/cpp:toolchain

build:clang_toolchain --crosstool_top=//toolchain:clang_suite
build:clang_toolchain --cpu=k8

# Android
build:android_arm64 --cpu=arm64-v8a
build:android_arm64 --fat_apk_cpu=arm64-v8a
build:android_arm64 --crosstool_top=//external:android/crosstool
build:android_arm64 --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
build:android_arm64 --linkopt=-lm
build:android_arm64 --linkopt=-ldl
build:android_arm64 --linkopt=-llog
build:android_arm64 --linkopt=-landroid
build:android_arm64 --cxxopt=-std=gnu++17
# This is required for using command line flags on android.
# It could be removed for the APK targets, but making it default since
# it doesn't seem to affect the size.
build:android_arm64 --cxxopt=-DABSL_FLAGS_STRIP_NAMES=0
# The android toolchain seems to add debug symbols (-g) even in copt mode.
# This seems like a bazel bug.
# (see https://github.com/bazelbuild/bazel/issues/13264). Until this is
# resolved, make optimized arguments default.
# If debugging c++ code, you may want to remove this.
build:android_arm64 --copt=-g0
build:android_arm64 --copt=-Os
# When building the demo apk Android has transitive deps that need to be pulled
# in.  The correct fix is probably to stop using gmaven_artifact() rules and
# use rules_jvm_external.  After that, this might be removeable, and we can use
# androidx and more recent deps instead of deprecated ones.
build:android_arm64 --strict_java_deps=OFF


# Start Tensorflow
# The below 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 --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

# End Tensorflow

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

# These settings below allow for compilation using MSVC
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__
