From e6efe0c874b296338e4457fe52fe874a2b213a6c Mon Sep 17 00:00:00 2001 From: Taku Kudo Date: Tue, 14 Aug 2018 20:03:53 +0900 Subject: [PATCH] Added make_py_wheel_mac for Mac/TF --- .travis.yml | 13 ++++-- tensorflow/make_py_wheel_mac.sh | 80 +++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 4 deletions(-) create mode 100755 tensorflow/make_py_wheel_mac.sh diff --git a/.travis.yml b/.travis.yml index 463d76b..faba9cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,17 +20,17 @@ matrix: env: IMAGE=ubuntu:rolling COMMAND=build_linux_clang_ubuntu services: docker - os: linux - env: IMAGE=x86_64 COMMAND=make_py_wheel + env: IMAGE=x86_64 COMMAND=make_py_wheel_py script: - $TRAVIS_BUILD_DIR/python/make_py_wheel.sh ${IMAGE} services: docker - os: linux - env: IMAGE=i686 COMMAND=make_py_wheel + env: IMAGE=i686 COMMAND=make_py_wheel_py script: - $TRAVIS_BUILD_DIR/python/make_py_wheel.sh ${IMAGE} services: docker - os: linux - env: IMAGE=x86_64 COMMAND=make_py_wheel + env: IMAGE=x86_64 COMMAND=make_py_wheel_tf script: - $TRAVIS_BUILD_DIR/tensorflow/make_py_wheel.sh services: docker @@ -45,9 +45,14 @@ matrix: env: IMAGE=native COMMAND=build_osx - os: osx osx_image: xcode9.4 - env: IMAGE=native COMMAND=make_py_wheel_mac + env: IMAGE=native COMMAND=make_py_wheel_mac_py script: - $TRAVIS_BUILD_DIR/python/make_py_wheel_mac.sh + - os: osx + osx_image: xcode9.4 + env: IMAGE=native COMMAND=make_py_wheel_mac_tf + script: + - $TRAVIS_BUILD_DIR/tensorflow/make_py_wheel_mac.sh script: - $TRAVIS_BUILD_DIR/test.sh ${IMAGE} ${COMMAND} env: diff --git a/tensorflow/make_py_wheel_mac.sh b/tensorflow/make_py_wheel_mac.sh new file mode 100755 index 0000000..be0cdea --- /dev/null +++ b/tensorflow/make_py_wheel_mac.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +# Copyright 2018 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License.! + +set -e # exit immediately on error +set -x # display all commands + +PROTOBUF_VERSION=3.6.1 + +build() { + cd tensorflow + rm -fr build + mkdir -p build + cd build + + # Install protobuf + curl -L -O https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protobuf-cpp-${PROTOBUF_VERSION}.tar.gz + tar zxfv protobuf-cpp-${PROTOBUF_VERSION}.tar.gz + cd protobuf-${PROTOBUF_VERSION} + ./configure --disable-shared --with-pic + make CXXFLAGS+="-std=c++11 -O3 -DGOOGLE_PROTOBUF_NO_THREADLOCAL=1 -D_GLIBCXX_USE_CXX11_ABI=0" \ + CFLAGS+="-std=c++11 -O3 -DGOOGLE_PROTOBUF_NO_THREADLOCAL=1 -D_GLIBCXX_USE_CXX11_ABI=0" -j4 + make install || true + cd .. + + # Install sentencepiece + cmake ../.. -DSPM_ENABLE_SHARED=OFF -DSPM_ENABLE_TENSORFLOW_SHARED=ON -DSPM_NO_THREADLOCAL=ON + make -j4 VERBOSE=1 + make install + cd .. + + which python + which pip + python --version + + curl -L -O https://bootstrap.pypa.io/get-pip.py + sudo python get-pip.py --no-setuptools --no-wheel --ignore-installed + pip install --upgrade setuptools + pip install wheel + pip install delocate + pip install tensorflow + + TF_CFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') ) + TF_LFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))') ) + + g++ -std=c++11 -shared \ + -I../../src \ + -fPIC ${TF_CFLAGS[@]} -O2 \ + -D_GLIBCXX_USE_CXX11_ABI=0 \ + -Wl,-all_load \ + /usr/local/lib/libprotobuf.a \ + /usr/local/lib/libsentencepiece.a \ + -Wl,-noall_load \ + sentencepiece_processor_ops.cc \ + -o tf_sentencepiece/_sentencepiece_processor_ops.so \ + ${TF_LFLAGS[@]} + + strip -x tf_sentencepiece/_sentencepiece_processor_ops.so + + # Builds Python manylinux wheel package. + PLAT_NAME=$(python -c 'import distutils.util; print(distutils.util.get_platform())') + python setup.py bdist_wheel --universal --plat-name=${PLAT_NAME} + python setup.py sdist + + rm -fr build tf_sentencepiece.egg-info tmp +} + +build