Last active
February 11, 2019 10:02
-
-
Save gilbertfrancois/aac59035d1dba42b555f96516dc86ff0 to your computer and use it in GitHub Desktop.
Creates a library distribution with necessary headers and library files that can be used to create Tensorflow C++ programs with your favourite build system, without bazel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Creates a dist archive that can be used to create C++ applications with Tensorflow, without bazel | |
# IMPORTANT: Before running this script, compile tensorflow_cc.so with --config=monolithic, then run this script. | |
# | |
# The script is written for Tensorflow v1.11. Update all dependencies in this script when running for a higher version. | |
# You can find the 3rd party dependency library versions in ${TENSORFLOW_DIR}/tensorflow/workspace.bzl. | |
# | |
# Original script: https://github.com/memo/ofxMSATensorFlow/blob/master/scripts/ubuntu/copy_headers.sh | |
# | |
mkdir -p ./libs/tensorflow/lib/linux64 | |
mkdir -p ./libs/tensorflow/lib/osx | |
mkdir -p ./libs/tensorflow/include | |
mkdir -p ./libs/google/include | |
DST='./libs/tensorflow/include' | |
if [[ $# -eq 0 ]] ; then | |
echo 'Usage: make_tensorflow_cpp_lib_dist.sh path/to/tensorflow' | |
exit 1 | |
fi | |
SRC=$1 | |
DO_CLEANUP=true | |
echo 'Copying files from '$SRC' to '$DST | |
# remove existing headers for a clean start | |
rm -rf $DST | |
mkdir -p $DST/tensorflow | |
cp -RL $SRC/tensorflow/core $DST/tensorflow | |
cp -RL $SRC/tensorflow/cc $DST/tensorflow | |
mkdir -p $DST/third_party | |
cp -RL $SRC/third_party/eigen3 $DST/third_party | |
#rm -rf $DST/third_party/eigen3/unsupported | |
cp -RLf $SRC/bazel-tensorflow//eigen_archive/unsuexternalpported $DST | |
cp -RL $SRC/bazel-genfiles/tensorflow/cc $DST/tensorflow | |
cp -RL $SRC/bazel-genfiles/tensorflow/core $DST/tensorflow | |
cp -RL $SRC/bazel-tensorflow/external/eigen_archive/Eigen $DST/Eigen | |
# Additional part: | |
# The script downloads and installs the additional headers needed by Tensorflow. It is written for Tensorflow version 1.11. | |
# To adapt it for other versions, please change the download links and versions in this | |
# script. You can find the correct versions in the ${TENSORFLOW_SRC_DIR}/tensorflow/workspace.bzl file. | |
# Download and unpack additional packages in a temporary directory | |
mkdir -p ./tmp | |
cd ./tmp | |
# com_google_abseil | |
wget https://github.com/abseil/abseil-cpp/archive/f0f15c2778b0e4959244dd25e63f445a455870f5.tar.gz | |
tar zxf f0f15c2778b0e4959244dd25e63f445a455870f5.tar.gz | |
cp -r abseil-cpp-f0f15c2778b0e4959244dd25e63f445a455870f5/absl ../libs/google/include | |
# protobuf | |
wget https://github.com/google/protobuf/archive/v3.6.0.tar.gz | |
tar zxf v3.6.0.tar.gz | |
cp -r protobuf-3.6.0/src/google ../libs/google/include/ | |
# nsync | |
wget https://github.com/google/nsync/archive/1.20.1.tar.gz | |
tar zxf 1.20.1.tar.gz | |
mkdir -p ../libs/tensorflow/include/external/nsync | |
cp -r nsync-1.20.1/public ../libs/tensorflow/include/external/nsync | |
# cleanup | |
cd .. | |
rm -Rf ./tmp | |
LIBS_DIR=./libs | |
if $DO_CLEANUP ; then | |
echo "Cleaning up. Deleting src files from "$DST | |
find $LIBS_DIR -name '*.cpp' -type f -delete | |
find $LIBS_DIR -name '*.c' -type f -delete | |
find $LIBS_DIR -name '*.cc' -type f -delete | |
find $LIBS_DIR -name '*.cxx' -type f -delete | |
find $LIBS_DIR -name '*.cmake' -type f -delete | |
find $LIBS_DIR -name '*.py' -type f -delete | |
find $LIBS_DIR -name '*.txt' -type f -delete | |
find $LIBS_DIR -name '*.dat' -type f -delete | |
find $LIBS_DIR -name '*.sh' -type f -delete | |
find $LIBS_DIR -name '*.proto' -type f -delete | |
fi | |
# Install so libraries for macOS | |
if [[ "$OSTYPE" == "darwin"* ]] ; then | |
cp tensorflow/bazel-bin/tensorflow/libtensorflow_cc.so ./libs/tensorflow/lib/osx/ | |
chmod 755 ./libs/tensorflow/lib/osx/libtensorflow_cc.so | |
install_name_tool -id libtensorflow_cc.so ./libs/tensorflow/lib/osx/libtensorflow_cc.so | |
fi | |
# Install so libraries for Linux | |
if [[ "$OSTYPE" == "linux"* ]] ; then | |
cp tensorflow/bazel-bin/tensorflow/libtensorflow_cc.so ./libs/tensorflow/lib/linux64 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment