tensorflow: Couldn't build android C++ .so libs with bazel and tensorflow as a remote dependency.

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 18.04
  • TensorFlow installed from (source or binary): Source, current master branch (23.03.2021)
  • TensorFlow version: Current master branch(23.03.2021), latest tag v2.4.1
  • Python version: 3.8
  • Bazel version (if compiling from source): 4.0.0
  • GCC/Compiler version (if compiling from source): 7.5.0
  • CUDA/cuDNN version: Not Used
  • GPU model and memory: Not Used

Describe the problem I am trying to build on C++ .so on top of tensorflow with bazel. I am trying to add tensorflow as a remote repository just like tensorflow_serving ( https://github.com/tensorflow/serving ). I can build for native targets(linux x86_64) all fine, when I tried to build for –config android I got errors that android is not defined, so I copy/pasted the .bazelrc file from tensorflow, and updated .tf_configure.bazelrc. Than the build started but it is failing for this target:

ERROR: /home/flamur/.cache/bazel/_bazel_flamur/8aff49c09e177f51e03fa24b3bf8aaa8/external/org_tensorflow/tensorflow/lite/delegates/gpu/cl/BUILD:486:22: Generating flatbuffer files for serialization_cc_fbs_srcs: @org_tensorflow//tensorflow/lite/delegates/gpu/cl:serialization_cc_fbs_srcs failed: (Exit 1): bash failed: error executing command 
  (cd /home/flamur/.cache/bazel/_bazel_flamur/8aff49c09e177f51e03fa24b3bf8aaa8/execroot/this_repo && \
  exec env - \
    ANDROID_BUILD_TOOLS_VERSION=30.0.0-rc4 \
    ANDROID_NDK_API_LEVEL=24 \
    ANDROID_NDK_HOME=/home/flamur/Android/Sdk/ndk-bundle \
    ANDROID_SDK_API_LEVEL=30 \
    ANDROID_SDK_HOME=/home/flamur/Android/Sdk \
    PATH=/home/flamur/anaconda3/envs/flamxi/bin:/home/flamur/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/flamur/bin:/home/flamur/.cargo/bin:/snap/bin:/home/flamur/anaconda3/envs/flamxi/bin:/home/flamur/anaconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/flamur/bin:/snap/bin:/home/flamur/Documents/CLion-2020.2.4/clion-2020.2.4/bin:/home/flamur/Documents/CLion-2020.2.4/clion-2020.2.4/bin \
    PYTHON_BIN_PATH=/home/flamur/anaconda3/envs/flamxi/bin/python3 \
    PYTHON_LIB_PATH=/home/flamur/anaconda3/envs/flamxi/lib/python3.7/site-packages \
    TF2_BEHAVIOR=1 \
    TF_CONFIGURE_IOS=0 \
  /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; for f in external/org_tensorflow/tensorflow/lite/delegates/gpu/cl/serialization.fbs; do bazel-out/host/bin/external/flatbuffers/flatc --scoped-enums -I ./  -c -o bazel-out/armeabi-v7a-opt/bin/external/org_tensorflow/tensorflow/lite/delegates/gpu/cl $f; done')
Execution platform: @local_execution_config_platform//:platform
error: /home/flamur/.cache/bazel/_bazel_flamur/8aff49c09e177f51e03fa24b3bf8aaa8/external/org_tensorflow/tensorflow/lite/delegates/gpu/cl/serialization.fbs:15: 75: error: unable to load include file: tensorflow/lite/delegates/gpu/common/task/serialization_base.fbs
Target //skeleton:centernet failed to build
INFO: Elapsed time: 0.131s, Critical Path: 0.01s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

I checked that file serialization.fbs and it seems like having a relative path for this include:

include "tensorflow/lite/delegates/gpu/common/task/serialization_base.fbs";

I am guessing this could be the problem! As the error says that cannot find this file.

If you want more files like WORKSPACE or .bazelrc please mention that, I don’t know if they are required at this state!

For the target that I get this error I tested it with tensorflow as local dependency it works all fine, also with the remote dependency the non android targets are builded succesfully!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (7 by maintainers)

Most upvoted comments

It worth to provide absolute path to the serialization_base.fbs with “-I” option. (later we could find proper relative path) FYI, “//” path only works Bazel and flatc_args is directly used by flatbuffer compiler.

I guess the problem can be fixed by modifying the following file. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/delegates/gpu/cl/BUILD

flatbuffer_cc_library(
    name = "serialization_cc_fbs",
    srcs = ["serialization.fbs"],
    flatc_args = [
        "--scoped-enums",
        "-I ./",
    ],
    includes = [
        "//tensorflow/lite/delegates/gpu/common/task:serialization_base_cc_fbs_includes",
    ],
)

flatc_args need to have additional “-I” option to find serialization_base.fbs file. Could you try?