1.Introduction
In order to build Tensorflow v2.0.0-beta natively on RaspberryPi3, first build Bazel natively on RaspberryPi3. Tensorflow v2.0.0-beta requires Bazel 0.24.1 or higher. Btw, The pre-built binary can be downloaded from the above Github repository.
2.Environment
- RaspberryPi3 model B+ (armv7l)
- Raspbian Stretch
- Bazel 0.24.1
- openjdk-8-jdk
3.Procedure
Build_procedure
$ sudo apt-get install build-essential openjdk-8-jdk python zip unzip
$ wget https://github.com/PINTO0309/Tensorflow-bin/raw/master/zram.sh
$ chmod 755 zram.sh
$ sudo mv zram.sh /etc/init.d/
$ sudo update-rc.d zram.sh defaults
$ sudo reboot
$ cd ~
$ mkdir bazel;cd bazel
$ wget https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel-0.24.1-dist.zip
$ unzip bazel-0.24.1-dist.zip
$ env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk"
#==== Only RaspberryPi ============================================================
$ nano compile.sh
#################################################################################
bazel_build "src:bazel_nojdk${EXE_EXT}" \
--action_env=PATH \
--host_platform=@bazel_tools//platforms:host_platform \
--platforms=@bazel_tools//platforms:target_platform \
|| fail "Could not build Bazel"
#################################################################################
↓
#################################################################################
bazel_build "src:bazel_nojdk${EXE_EXT}" \
--host_javabase=@local_jdk//:jdk \
--action_env=PATH \
--host_platform=@bazel_tools//platforms:host_platform \
--platforms=@bazel_tools//platforms:target_platform \
|| fail "Could not build Bazel"
#################################################################################
$ nano scripts/bootstrap/compile.sh
#################################################################################
run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
-d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \
-encoding UTF-8 ${BAZEL_JAVAC_OPTS} "@${paramfile}"
#################################################################################
↓
#################################################################################
run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
-d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \
-encoding UTF-8 ${BAZEL_JAVAC_OPTS} "@${paramfile}" -J-Xmx800M
#################################################################################
#==== Only RaspberryPi ============================================================
$ sudo bash ./compile.sh #<--- Execute it directly under the bazel folder
$ sudo cp output/bazel /usr/local/bin #<--- Always execute after completion of build
4.Reference article
[Stable] Install openjdk-8-jdk safely in Raspbian Buster (Debian 10) environment