• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Build definitions supporting platform-independent native build."""
2
3load("@org_tensorflow//tensorflow:tensorflow.bzl", "tf_copts", "tf_opts_nortti_if_android")
4load("@bazel_skylib//lib:selects.bzl", "selects")
5
6def micore_if(android, ios = [], default = []):
7    """Helper to create a select.
8
9    Args:
10      android: what to return if compiling for Android.
11      ios: what to return if compiling for iOS.
12      default: what to return otherwise.
13    Returns:
14      the `android` list for Android compilation and the
15      `default` list otherwise.
16    """
17    return select({
18        ":android": android,
19        ":apple": ios,
20        "//conditions:default": default,
21    })
22
23def micore_tf_copts():
24    """C options for Tensorflow builds.
25
26    Returns:
27      a list of copts which must be used by each cc_library which
28      refers to Tensorflow. Enables the library to compile both for
29      Android and for Linux.
30    """
31    return tf_copts(android_optimization_level_override = None) + tf_opts_nortti_if_android() + [
32        "-Wno-narrowing",
33        "-Wno-sign-compare",
34        "-Wno-overloaded-virtual",
35    ] + micore_if(
36        android = [
37            # Set a define so Tensorflow's register_types.h
38            # adopts to support a rich set of types, to be pruned by
39            # selective registration.
40            "-DSUPPORT_SELECTIVE_REGISTRATION",
41            # Selective registration uses constexprs with recursive
42            # string comparisons; that can lead to compiler errors, so
43            # we increase the constexpr recursion depth.
44            "-fconstexpr-depth=1024",
45        ],
46    ) + selects.with_or({
47        # If building for armeabi-v7a, and if compilation_mode is 'fastbuild'
48        # or 'dbg' then forcefully add -Oz to the list compiler options.
49        # Without it, some TF dependencies can't build (b/112286436). If
50        # compilation_mode is 'opt' then rely on the toolchain default.
51        (
52            ":armeabi_v7a_and_fastbuild",
53            ":armeabi_v7a_and_dbg",
54        ): ["-Oz"],
55        "//conditions:default": [],
56    })
57
58def micore_tf_deps():
59    """Dependencies for Tensorflow builds.
60
61    Returns:
62      list of dependencies which must be used by each cc_library
63      which refers to Tensorflow. Enables the library to compile both for
64      Android and for Linux. Use this macro instead of directly
65      declaring dependencies on Tensorflow.
66    """
67    return micore_if(
68        android = [
69            # Link to library which does not contain any ops.
70            "@org_tensorflow//tensorflow/core:portable_tensorflow_lib_lite",
71            "@gemmlowp//:eight_bit_int_gemm",
72            "@fft2d//:fft2d",
73        ],
74        ios = [
75            "@org_tensorflow//tensorflow/core:portable_tensorflow_lib",
76            "@gemmlowp//:eight_bit_int_gemm",
77            "@fft2d//:fft2d",
78        ],
79        default = [
80            # Standard references for Tensorflow when building for Linux. We use
81            # an indirection via the alias targets below, to facilitate whitelisting
82            # these deps in the mobile license presubmit checks.
83            "@local_config_tf//:libtensorflow_framework",
84            "@local_config_tf//:tf_header_lib",
85        ],
86    )
87