Take a look in the .bazelrc file. It defines for instance build:android_arm --config=android
. This means you can build in bazel with bazel build --config=android
- I guess that a compiler with target android provides in the system header an ANDROID
and __ANDROID__
define - so you have not to explicitly modify a cc_binary
target.
You can also add defines explicitly to a cc_binary
:
The cc_binary
target provides a define
and copts
attribute:
cc_binary(name, deps, srcs, data, args, compatible_with, copts, defines, deprecation, distribs, exec_compatible_with, features, includes, licenses, linkopts, linkshared, linkstatic, malloc, nocopts, output_licenses, restricted_to, stamp, tags, testonly, toolchains, visibility, win_def_file)
From the documentation:
defines: List of strings; optional
List of defines to add to the compile line. Subject to "Make" variable
substitution and Bourne shell tokenization. Each string, which must
consist of a single Bourne shell token, is prepended with -D
(or /D
on
Windows) and added to COPTS
. Unlike copts
, these flags are added for
the target and every rule that depends on it! Be very careful, since
this may have far-reaching effects. When in doubt, add "-D" (or /D on
Windows) flags to copts
instead.
I would recommend you to add your define to the copts
attribute, e.g.:
cc_binary(
srcs = ["main.cpp"],
copts = ["-DMY_DEFINE"],
)