From 2b4a0f9a485d47ceb572c4ff4e1ad3100dc1c3e0 Mon Sep 17 00:00:00 2001 From: resec Date: Thu, 27 Jul 2017 01:51:17 +0800 Subject: [PATCH] Enable Android lib bazel build for mips and mips64 (#11773) --- WORKSPACE | 3 +++ tensorflow/BUILD | 18 ++++++++++++++++++ tensorflow/contrib/android/BUILD | 3 ++- tensorflow/core/BUILD | 5 ++--- tensorflow/tensorflow.bzl | 15 +++++++++++++++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 74ce13f4e88..6b5d24560ca 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -32,6 +32,9 @@ load("//tensorflow:workspace.bzl", "tf_workspace") # name="androidndk", # path="", # # This needs to be 14 or higher to compile TensorFlow. +# # Please specify API level to >= 21 to build for 64-bit +# # archtectures or the Android NDK will automatically select biggest +# # API level that it supports without notice. # # Note that the NDK version is not the API level. # api_level=14) diff --git a/tensorflow/BUILD b/tensorflow/BUILD index 0b5ba805a86..a162bcf4525 100644 --- a/tensorflow/BUILD +++ b/tensorflow/BUILD @@ -63,6 +63,24 @@ config_setting( visibility = ["//visibility:public"], ) +config_setting( + name = "android_mips", + values = { + "crosstool_top": "//external:android/crosstool", + "cpu": "mips", + }, + visibility = ["//visibility:public"], +) + +config_setting( + name = "android_mips64", + values = { + "crosstool_top": "//external:android/crosstool", + "cpu": "mips64", + }, + visibility = ["//visibility:public"], +) + config_setting( name = "darwin", values = {"cpu": "darwin"}, diff --git a/tensorflow/contrib/android/BUILD b/tensorflow/contrib/android/BUILD index 952f24f34b2..0833790e991 100644 --- a/tensorflow/contrib/android/BUILD +++ b/tensorflow/contrib/android/BUILD @@ -11,6 +11,7 @@ load( "//tensorflow:tensorflow.bzl", "tf_copts", "if_android", + "if_android_mips", ) exports_files([ @@ -85,7 +86,7 @@ cc_binary( "-Wl,--gc-sections", "-Wl,--version-script", # This line must be directly followed by LINKER_SCRIPT. LINKER_SCRIPT, - ]), + ]) + if_android_mips(["-latomic"]), linkshared = 1, linkstatic = 1, tags = [ diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD index 02355a7626b..deb2d99feb6 100644 --- a/tensorflow/core/BUILD +++ b/tensorflow/core/BUILD @@ -64,6 +64,7 @@ load( "//tensorflow:tensorflow.bzl", "full_path", "if_android", + "if_not_android_mips_and_mips64", "if_ios", "if_linux_x86_64", "if_not_mobile", @@ -933,9 +934,7 @@ filegroup( cc_library( name = "android_tensorflow_lib_lite", srcs = if_android(["//tensorflow/core:android_srcs"]), - copts = tf_copts() + [ - "-Os", - ], + copts = tf_copts() + if_not_android_mips_and_mips64(["-Os"]), linkopts = ["-lz"], tags = [ "manual", diff --git a/tensorflow/tensorflow.bzl b/tensorflow/tensorflow.bzl index cddf16f147a..5fd9fe597dd 100644 --- a/tensorflow/tensorflow.bzl +++ b/tensorflow/tensorflow.bzl @@ -72,6 +72,13 @@ def if_android_arm64(a): }) +def if_android_mips(a): + return select({ + clean_dep("//tensorflow:android_mips"): a, + "//conditions:default": [], + }) + + def if_not_android(a): return select({ clean_dep("//tensorflow:android"): [], @@ -79,6 +86,14 @@ def if_not_android(a): }) +def if_not_android_mips_and_mips64(a): + return select({ + clean_dep("//tensorflow:android_mips"): [], + clean_dep("//tensorflow:android_mips64"): [], + "//conditions:default": a, + }) + + def if_android(a): return select({ clean_dep("//tensorflow:android"): a,