[meta-tensorflow,03/13] create classes/bazel.bbclass

Submitted by Hongxu Jia on Feb. 21, 2019, 11:37 a.m. | Patch ID: 158951

Details

Message ID 1550749039-67320-4-git-send-email-hongxu.jia@windriver.com
State New
Headers show

Commit Message

Hongxu Jia Feb. 21, 2019, 11:37 a.m.
Inherit the bbclass to use bazel to build tensorflow-native,
tensorflow, tensorboard and tensorflow-estimator.

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 classes/bazel.bbclass | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
 create mode 100644 classes/bazel.bbclass

Patch hide | download patch | download mbox

diff --git a/classes/bazel.bbclass b/classes/bazel.bbclass
new file mode 100644
index 0000000..3bda2c8
--- /dev/null
+++ b/classes/bazel.bbclass
@@ -0,0 +1,80 @@ 
+DEPENDS += "bazel-native \
+           openjdk-8-native \
+          "
+
+BAZEL_OUTPUTBASE_DIR ?= "${WORKDIR}/bazel/output_base"
+export BAZEL_ARGS="--output_user_root=${WORKDIR}/bazel/user_root \
+                   --output_base=${BAZEL_OUTPUTBASE_DIR} \
+                   --bazelrc=${S}/bazelrc \
+                  "
+
+export JAVA_HOME="${RECIPE_SYSROOT_NATIVE}/usr/lib/jvm/openjdk-8-native"
+
+def bazel_get_flags(d):
+    flags = ""
+    for i in d.getVar("CC").split()[1:]:
+        flags += "--conlyopt=%s --cxxopt=%s " % (i, i)
+
+    for i in d.getVar("CFLAGS").split():
+        if i == "-g":
+            continue
+        flags += "--conlyopt=%s " % i
+
+    for i in d.getVar("BUILD_CFLAGS").split():
+        flags += "--host_conlyopt=%s " % i
+
+    for i in d.getVar("CXXFLAGS").split():
+        if i == "-g":
+            continue
+        flags += "--cxxopt=%s " % i
+
+    for i in d.getVar("BUILD_CXXFLAGS").split():
+        flags += "--host_cxxopt=%s " % i
+
+    for i in d.getVar("CPPFLAGS").split():
+        if i == "-g":
+            continue
+        flags += "--conlyopt=%s --cxxopt=%s " % (i, i)
+
+    for i in d.getVar("BUILD_CPPFLAGS").split():
+        flags += "--host_conlyopt=%s --host_cxxopt=%s " % (i, i)
+
+    for i in d.getVar("LDFLAGS").split():
+        flags += "--linkopt=%s " % i
+
+    for i in d.getVar("BUILD_LDFLAGS").split():
+        flags += "--host_linkopt=%s " % i
+
+    for i in d.getVar("TOOLCHAIN_OPTIONS").split():
+        flags += "--linkopt=%s " % i
+
+    return flags
+
+bazel_do_configure () {
+    cat > "${S}/bazelrc" <<-EOF
+build --verbose_failures
+build --spawn_strategy=standalone --genrule_strategy=standalone
+build --jobs=${@oe.utils.cpu_count()}
+test --verbose_failures --verbose_test_summary
+test --spawn_strategy=standalone --genrule_strategy=standalone
+
+build --linkopt=-Wl,-latomic
+build --strip=never
+
+fetch --distdir=${DL_DIR}
+build --distdir=${DL_DIR}
+
+EOF
+
+}
+
+bazel_do_configure_append_class-target () {
+    cat >> "${S}/bazelrc" <<-EOF
+# FLAGS
+build ${@bazel_get_flags(d)}
+EOF
+
+    sed -i "s:${WORKDIR}:${BAZEL_OUTPUTBASE_DIR}/external/yocto_compiler:g" ${S}/bazelrc
+}
+
+EXPORT_FUNCTIONS do_configure