Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: macos build #357

Merged
merged 3 commits into from
Jul 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 31 additions & 20 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@
# Options:
# --quiet Give less output.


# Writes variables to bazelrc file
function write_to_bazelrc() {
echo "$1" >> .bazelrc
}

function write_action_env_to_bazelrc() {
write_to_bazelrc "build --action_env $1=\"$2\""
}

# Converts the linkflag namespec to the full shared library name
function generate_shared_lib_name() {
if [[ $(uname) == "Darwin" ]]; then
local namespec="$1"
echo "lib"${namespec:2}".dylib"
else
local namespec="$1"
echo ${namespec:3}
fi
}

QUIET_FLAG=""
if [[ $1 == "--quiet" ]]; then
QUIET_FLAG="--quiet"
Expand All @@ -43,42 +64,32 @@ fi

${PYTHON_VERSION:=python} -m pip install $QUIET_FLAG -r $REQUIREMENTS_TXT

# Bazel configure
function write_to_bazelrc() {
echo "$1" >> .bazelrc
}

function write_action_env_to_bazelrc() {
write_to_bazelrc "build --action_env $1=\"$2\""
}

[[ -f .bazelrc ]] && rm .bazelrc

TF_CFLAGS=( $(${PYTHON_VERSION} -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') )
TF_LFLAGS="$(${PYTHON_VERSION} -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))')"
TF_LFLAGS=( $(${PYTHON_VERSION} -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))') )
TF_CXX11_ABI_FLAG=( $(${PYTHON_VERSION} -c 'import tensorflow as tf; print(tf.sysconfig.CXX11_ABI_FLAG)') )

SHARED_LIBRARY_DIR=${TF_LFLAGS:2}
SHARED_LIBRARY_NAME=$(echo $TF_LFLAGS | rev | cut -d":" -f1 | rev)
SHARED_LIBRARY_DIR=${TF_LFLAGS[0]:2}
SHARED_LIBRARY_NAME=$(generate_shared_lib_name ${TF_LFLAGS[1]})

write_action_env_to_bazelrc "TF_HEADER_DIR" ${TF_CFLAGS:2}
write_action_env_to_bazelrc "TF_SHARED_LIBRARY_DIR" ${SHARED_LIBRARY_DIR}
write_action_env_to_bazelrc "TF_SHARED_LIBRARY_NAME" ${SHARED_LIBRARY_NAME}
write_action_env_to_bazelrc "TF_CXX11_ABI_FLAG" ${TF_CXX11_ABI_FLAG}

write_to_bazelrc "build:cuda --define=using_cuda=true --define=using_cuda_nvcc=true"
write_to_bazelrc "build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain"
write_to_bazelrc "build --spawn_strategy=standalone"
write_to_bazelrc "build --strategy=Genrule=standalone"
write_action_env_to_bazelrc "TF_NEED_CUDA" ${TF_NEED_CUDA}

# TODO(yifeif): do not hardcode path
if [[ "$TF_NEED_CUDA" == "1" ]]; then
# TODO: use CUDA_HOME here?
write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "/usr/lib/x86_64-linux-gnu"
write_action_env_to_bazelrc "TF_CUDA_VERSION" "10.0"
write_action_env_to_bazelrc "TF_CUDNN_VERSION" "7"
write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "${CUDA_HOME:=/usr/local/cuda}"
write_to_bazelrc "build --config=cuda"
write_to_bazelrc "test --config=cuda"

write_to_bazelrc "build:cuda --define=using_cuda=true --define=using_cuda_nvcc=true"
write_to_bazelrc "build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain"
write_to_bazelrc "build --spawn_strategy=standalone"
write_to_bazelrc "build --strategy=Genrule=standalone"
write_action_env_to_bazelrc "TF_NEED_CUDA" ${TF_NEED_CUDA}

fi