Skip to content

Commit

Permalink
Use .bazelrc to configure optional dependencies (tensorflow#8218)
Browse files Browse the repository at this point in the history
Rather than having ./configure mutate one of our .bzl files, which
dirties the git repository, this change has ./configure put the options
for jemalloc, GCS, HDFS, and XLA inside a .bazelrc at the root of the
TensorFlow repository. This file is listed in .gitignore.

Therefore, running ./configure will no longer cause the git repository
to be in a modified state.

Fixes tensorflow#8202
  • Loading branch information
jart authored and jhseu committed Mar 14, 2017
1 parent 9daae39 commit bce77b9
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 73 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.ipynb_checkpoints
node_modules
/.bazelrc
/bazel-*
/third_party/py/numpy/numpy_include
/tools/bazel.rc
Expand All @@ -13,4 +14,4 @@ node_modules
*.pyc
__pycache__
*.swp
.vscode/
.vscode/
51 changes: 18 additions & 33 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pushd `dirname $0` > /dev/null
SOURCE_BASE_DIR=`pwd -P`
popd > /dev/null

# This file contains customized config settings.
touch .bazelrc

PLATFORM="$(uname -s | tr 'A-Z' 'a-z')"

function is_linux() {
Expand Down Expand Up @@ -182,13 +185,12 @@ else
TF_NEED_JEMALLOC=0
fi

if [ "$TF_NEED_JEMALLOC" == "1" ]; then
sed_hyphen_i -e "s/WITH_JEMALLOC = False/WITH_JEMALLOC = True/" tensorflow/core/platform/default/build_config.bzl
else
sed_hyphen_i -e "s/WITH_JEMALLOC = True/WITH_JEMALLOC = False/" tensorflow/core/platform/default/build_config.bzl
sed_hyphen_i -e "/with_jemalloc/d" .bazelrc
if [[ "$TF_NEED_JEMALLOC" == "1" ]]; then
echo 'build --define with_jemalloc=true' >>.bazelrc
fi

while [ "$TF_NEED_GCP" == "" ]; do
while [[ "$TF_NEED_GCP" == "" ]]; do
read -p "Do you wish to build TensorFlow with "\
"Google Cloud Platform support? [y/N] " INPUT
case $INPUT in
Expand All @@ -202,23 +204,12 @@ while [ "$TF_NEED_GCP" == "" ]; do
esac
done

if [ "$TF_NEED_GCP" == "1" ]; then
## Verify that libcurl header files are available.
# Only check Linux, since on MacOS the header files are installed with XCode.
if is_linux && [[ ! -f "/usr/include/curl/curl.h" ]]; then
echo "ERROR: It appears that the development version of libcurl is not "\
"available. Please install the libcurl3-dev package."
exit 1
fi

# Update Bazel build configuration.
sed_hyphen_i -e "s/WITH_GCP_SUPPORT = False/WITH_GCP_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
else
# Update Bazel build configuration.
sed_hyphen_i -e "s/WITH_GCP_SUPPORT = True/WITH_GCP_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
sed_hyphen_i -e "/with_gcp_support/d" .bazelrc
if [[ "$TF_NEED_GCP" == "1" ]]; then
echo 'build --define with_gcp_support=true' >>.bazelrc
fi

while [ "$TF_NEED_HDFS" == "" ]; do
while [[ "$TF_NEED_HDFS" == "" ]]; do
read -p "Do you wish to build TensorFlow with "\
"Hadoop File System support? [y/N] " INPUT
case $INPUT in
Expand All @@ -232,16 +223,13 @@ while [ "$TF_NEED_HDFS" == "" ]; do
esac
done

if [ "$TF_NEED_HDFS" == "1" ]; then
# Update Bazel build configuration.
sed_hyphen_i -e "s/WITH_HDFS_SUPPORT = False/WITH_HDFS_SUPPORT = True/" tensorflow/core/platform/default/build_config.bzl
else
# Update Bazel build configuration.
sed_hyphen_i -e "s/WITH_HDFS_SUPPORT = True/WITH_HDFS_SUPPORT = False/" tensorflow/core/platform/default/build_config.bzl
sed_hyphen_i -e "/with_hdfs_support/d" .bazelrc
if [[ "$TF_NEED_HDFS" == "1" ]]; then
echo 'build --define with_hdfs_support=true' >>.bazelrc
fi

## Enable XLA.
while [ "$TF_ENABLE_XLA" == "" ]; do
while [[ "$TF_ENABLE_XLA" == "" ]]; do
read -p "Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)? [y/N] " INPUT
case $INPUT in
[Yy]* ) echo "XLA JIT support will be enabled for TensorFlow"; TF_ENABLE_XLA=1;;
Expand All @@ -251,12 +239,9 @@ while [ "$TF_ENABLE_XLA" == "" ]; do
esac
done

if [ "$TF_ENABLE_XLA" == "1" ]; then
# Update Bazel build configuration.
sed_hyphen_i -e "s/^WITH_XLA_SUPPORT = [FT].*/WITH_XLA_SUPPORT = True/" tensorflow/core/platform/default/build_config_root.bzl
else
# Update Bazel build configuration.
sed_hyphen_i -e "s/^WITH_XLA_SUPPORT = [FT].*/WITH_XLA_SUPPORT = False/" tensorflow/core/platform/default/build_config_root.bzl
sed_hyphen_i -e "/with_xla_support/d" .bazelrc
if [[ "$TF_ENABLE_XLA" == "1" ]]; then
echo 'build --define with_xla_support=true' >>.bazelrc
fi


Expand Down
28 changes: 28 additions & 0 deletions tensorflow/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,34 @@ config_setting(
visibility = ["//visibility:public"],
)

# TODO(jhseu): Enable on other platforms other than Linux.
config_setting(
name = "with_jemalloc",
values = {
"cpu": "k8",
"define": "with_jemalloc=true",
},
visibility = ["//visibility:public"],
)

config_setting(
name = "with_gcp_support",
values = {"define": "with_gcp_support=true"},
visibility = ["//visibility:public"],
)

config_setting(
name = "with_hdfs_support",
values = {"define": "with_hdfs_support=true"},
visibility = ["//visibility:public"],
)

config_setting(
name = "with_xla_support",
values = {"define": "with_xla_support=true"},
visibility = ["//visibility:public"],
)

package_group(
name = "internal",
packages = ["//tensorflow/..."],
Expand Down
48 changes: 19 additions & 29 deletions tensorflow/core/platform/default/build_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ load("@protobuf//:protobuf.bzl", "cc_proto_library")
load("@protobuf//:protobuf.bzl", "py_proto_library")
load("//tensorflow:tensorflow.bzl", "if_not_mobile")

# configure may change the following lines
WITH_GCP_SUPPORT = False
WITH_HDFS_SUPPORT = False
WITH_JEMALLOC = False

# Appends a suffix to a list of deps.
def tf_deps(deps, suffix):
tf_deps = []
Expand Down Expand Up @@ -194,35 +189,30 @@ def tf_additional_test_srcs():
def tf_kernel_tests_linkstatic():
return 0

# jemalloc only enabled on Linux for now.
# TODO(jhseu): Enable on other platforms.
def tf_additional_lib_defines():
defines = []
if WITH_JEMALLOC:
defines += select({
"//tensorflow:linux_x86_64": [
"TENSORFLOW_USE_JEMALLOC"
],
"//conditions:default": [],
})
return defines
return select({
"//tensorflow:with_jemalloc": ["TENSORFLOW_USE_JEMALLOC"],
"//conditions:default": [],
})

def tf_additional_lib_deps():
deps = []
if WITH_JEMALLOC:
deps += select({
"//tensorflow:linux_x86_64": ["@jemalloc"],
"//conditions:default": [],
})
return deps
return select({
"//tensorflow:with_jemalloc": ["@jemalloc"],
"//conditions:default": [],
})

def tf_additional_core_deps():
deps = []
if WITH_GCP_SUPPORT:
deps.append("//tensorflow/core/platform/cloud:gcs_file_system")
if WITH_HDFS_SUPPORT:
deps.append("//tensorflow/core/platform/hadoop:hadoop_file_system")
return deps
return select({
"//tensorflow:with_gcp_support": [
"//tensorflow/core/platform/cloud:gcs_file_system",
],
"//conditions:default": [],
}) + select({
"//tensorflow:with_hdfs_support": [
"//tensorflow/core/platform/hadoop:hadoop_file_system",
],
"//conditions:default": [],
})

# TODO(jart, jhseu): Delete when GCP is default on.
def tf_additional_cloud_op_deps():
Expand Down
18 changes: 8 additions & 10 deletions tensorflow/core/platform/default/build_config_root.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@
# The functions in this file might be referred by tensorflow.bzl. They have to
# be separate to avoid cyclic references.

WITH_XLA_SUPPORT = False

def tf_cuda_tests_tags():
return ["local"]

def tf_sycl_tests_tags():
return ["local"]

def tf_additional_plugin_deps():
deps = []
if WITH_XLA_SUPPORT:
deps.append("//tensorflow/compiler/jit")
return deps
return select({
"//tensorflow:with_xla_support": ["//tensorflow/compiler/jit"],
"//conditions:default": [],
})

def tf_additional_xla_deps_py():
return []

def tf_additional_license_deps():
licenses = []
if WITH_XLA_SUPPORT:
licenses.append("@llvm//:LICENSE.TXT")
return licenses
return select({
"//tensorflow:with_xla_support": ["@llvm//:LICENSE.TXT"],
"//conditions:default": [],
})

0 comments on commit bce77b9

Please sign in to comment.