Skip to content

Commit 14ac223

Browse files
davidzchenVijay Vasudevan
authored and
Vijay Vasudevan
committed
Use external repository for protobuf dependency. (tensorflow#1289)
Currently, TensorFlow uses a Git submodule for its dependency on protobuf. This was due to the hack used in protobuf for building Python support with Bazel, which was required since Bazel's Python rules did not support adding directories to `PYTHONPATH`. Now that the new `imports` attribute has been added to the Python rules in Bazel 0.2 and the hack for Python support in protobuf has been removed, this change removes the `google/protobuf` Git submodule and adds an external repository for including protobuf. This patch also adds gmock.BUILD to the tensorflow repo. Fixes tensorflow#1069 Fixes tensorflow#2021
1 parent 15e51e6 commit 14ac223

File tree

17 files changed

+119
-80
lines changed

17 files changed

+119
-80
lines changed

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "google/protobuf"]
2-
path = google/protobuf
3-
url = https://github.com/google/protobuf.git

WORKSPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tf_workspace()
2020

2121
# Specify the minimum required bazel version.
2222
load("//tensorflow:tensorflow.bzl", "check_version")
23-
check_version("0.1.4")
23+
check_version("0.2.0")
2424

2525
# TENSORBOARD_BOWER_AUTOGENERATED_BELOW_THIS_LINE_DO_NOT_EDIT
2626

configure

-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@
22

33
DO_NOT_SUBMIT_WARNING="Unofficial setting. DO NOT SUBMIT!!!"
44

5-
## Verify that the submodule google/protobuf is available
6-
# TODO(cais): Remove this check once protobuf is no longer depended upon
7-
if [[ ! -f "google/protobuf/protobuf.bzl" ]]; then
8-
echo "ERROR: It appears that the required submodule google/protobuf is not "\
9-
"available in this TensorFlow git clone."
10-
echo "Please be sure to use the --recurse-submodules flag when performing "\
11-
"git clone of TensorFlow."
12-
13-
exit 1
14-
fi
15-
165
## Set up python-related environment settings
176
while true; do
187
fromuser=""

gmock.BUILD

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cc_library(
2+
name = "gtest",
3+
srcs = [
4+
"gmock-1.7.0/gtest/src/gtest-all.cc",
5+
"gmock-1.7.0/src/gmock-all.cc",
6+
],
7+
hdrs = glob([
8+
"gmock-1.7.0/**/*.h",
9+
"gmock-1.7.0/gtest/src/*.cc",
10+
"gmock-1.7.0/src/*.cc",
11+
]),
12+
includes = [
13+
"gmock-1.7.0",
14+
"gmock-1.7.0/gtest",
15+
"gmock-1.7.0/gtest/include",
16+
"gmock-1.7.0/include",
17+
],
18+
linkopts = ["-pthread"],
19+
visibility = ["//visibility:public"],
20+
)
21+
22+
cc_library(
23+
name = "gtest_main",
24+
srcs = ["gmock-1.7.0/src/gmock_main.cc"],
25+
linkopts = ["-pthread"],
26+
visibility = ["//visibility:public"],
27+
deps = [":gtest"],
28+
)

google/protobuf

-1
This file was deleted.

tensorflow/contrib/ffmpeg/default/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cc_library(
1616
"//tensorflow/contrib/ffmpeg:ffmpeg_lib.h",
1717
],
1818
deps = [
19-
"//google/protobuf",
19+
"@protobuf//:protobuf",
2020
"//tensorflow/core:framework_headers_lib",
2121
],
2222
)

tensorflow/contrib/layers/kernels/BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cc_library(
1111
name = "bucketization_kernel",
1212
srcs = ["bucketization_kernel.cc"],
1313
deps = [
14-
"//google/protobuf",
14+
"@protobuf//:protobuf",
1515
"//tensorflow/core:framework_headers_lib",
1616
"//third_party/eigen3",
1717
],
@@ -22,7 +22,7 @@ cc_library(
2222
name = "sparse_feature_cross_kernel",
2323
srcs = ["sparse_feature_cross_kernel.cc"],
2424
deps = [
25-
"//google/protobuf",
25+
"@protobuf//:protobuf",
2626
"//tensorflow/core:framework_headers_lib",
2727
"//third_party/eigen3",
2828
],

tensorflow/contrib/linear_optimizer/kernels/BUILD

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cc_library(
2121
"squared-loss.h",
2222
],
2323
deps = [
24-
"//google/protobuf",
24+
"@protobuf//:protobuf",
2525
"//tensorflow/core:framework_headers_lib",
2626
],
2727
)
@@ -43,7 +43,7 @@ cc_library(
4343
srcs = ["resources.cc"],
4444
hdrs = ["resources.h"],
4545
deps = [
46-
"//google/protobuf",
46+
"@protobuf//:protobuf",
4747
"//tensorflow/core:framework_headers_lib",
4848
"//third_party/eigen3",
4949
],
@@ -68,7 +68,7 @@ cc_library(
6868
deps = [
6969
":loss_updaters",
7070
":resources",
71-
"//google/protobuf",
71+
"@protobuf//:protobuf",
7272
"//tensorflow/core:framework_headers_lib",
7373
"//tensorflow/core/kernels:bounds_check_lib",
7474
"//third_party/eigen3",

tensorflow/contrib/metrics/kernels/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cc_library(
1111
name = "set_kernels",
1212
srcs = ["set_kernels.cc"],
1313
deps = [
14-
"//google/protobuf",
14+
"@protobuf//:protobuf",
1515
"//tensorflow/core:framework_headers_lib",
1616
"//third_party/eigen3",
1717
],

tensorflow/contrib/tensor_forest/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cc_library(
2525
"core/ops/tree_utils.h",
2626
],
2727
deps = [
28-
"//google/protobuf",
28+
"@protobuf//:protobuf",
2929
"//tensorflow/core:framework_headers_lib",
3030
"//third_party/eigen3",
3131
],

tensorflow/core/platform/default/build_config.bzl

+45-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Platform-specific build configurations.
22

3-
load("//google/protobuf:protobuf.bzl", "cc_proto_library")
4-
load("//google/protobuf:protobuf.bzl", "py_proto_library")
3+
load("@protobuf//:protobuf.bzl", "cc_proto_library")
4+
load("@protobuf//:protobuf.bzl", "py_proto_library")
55

66
# configure may change the following line to True
77
WITH_GCP_SUPPORT = False
@@ -31,49 +31,63 @@ def tf_proto_library_cc(name, srcs = [], has_services = None,
3131
cc_api_version = 2, go_api_version = 2,
3232
java_api_version = 2,
3333
py_api_version = 2):
34-
native.filegroup(name=name + "_proto_srcs",
35-
srcs=srcs + tf_deps(deps, "_proto_srcs"),
36-
testonly=testonly,)
34+
native.filegroup(
35+
name = name + "_proto_srcs",
36+
srcs = srcs + tf_deps(deps, "_proto_srcs"),
37+
testonly = testonly,
38+
)
3739

3840
use_grpc_plugin = None
3941
if cc_grpc_version:
4042
use_grpc_plugin = True
41-
cc_proto_library(name=name + "_cc",
42-
srcs=srcs + tf_deps(deps, "_proto_srcs"),
43-
deps=deps + ["//google/protobuf:cc_wkt_protos"],
44-
cc_libs = cc_libs + ["//google/protobuf:protobuf"],
45-
use_grpc_plugin = use_grpc_plugin,
46-
testonly=testonly,
47-
visibility=visibility,)
43+
cc_proto_library(
44+
name = name + "_cc",
45+
srcs = srcs + tf_deps(deps, "_proto_srcs"),
46+
deps = deps + ["@protobuf//:cc_wkt_protos"],
47+
cc_libs = cc_libs + ["@protobuf//:protobuf"],
48+
protoc = "@protobuf//:protoc",
49+
default_runtime = "@protobuf//:protobuf",
50+
use_grpc_plugin = use_grpc_plugin,
51+
testonly = testonly,
52+
visibility = visibility,
53+
)
4854

4955
def tf_proto_library_py(name, srcs=[], deps=[], visibility=[], testonly=0,
5056
srcs_version="PY2AND3"):
51-
py_proto_library(name = name + "_py",
52-
srcs = srcs,
53-
srcs_version = srcs_version,
54-
deps = deps,
55-
visibility = visibility,
56-
testonly = testonly)
57+
py_proto_library(
58+
name = name + "_py",
59+
srcs = srcs,
60+
srcs_version = srcs_version,
61+
deps = deps,
62+
protoc = "@protobuf//:protoc",
63+
default_runtime = "@protobuf//:protobuf_python",
64+
visibility = visibility,
65+
testonly = testonly,
66+
)
5767

5868
def tf_proto_library(name, srcs = [], has_services = None,
5969
deps = [], visibility = [], testonly = 0,
6070
cc_libs = [],
6171
cc_api_version = 2, go_api_version = 2,
6272
java_api_version = 2,
6373
py_api_version = 2):
64-
tf_proto_library_cc(name=name,
65-
srcs=srcs + tf_deps(deps, "_proto_srcs"),
66-
deps=deps,
67-
cc_libs=cc_libs,
68-
testonly=testonly,
69-
visibility=visibility,)
70-
71-
tf_proto_library_py(name=name,
72-
srcs=srcs + tf_deps(deps, "_proto_srcs"),
73-
srcs_version="PY2AND3",
74-
deps=deps + ["//google/protobuf:protobuf_python"],
75-
testonly=testonly,
76-
visibility=visibility,)
74+
tf_proto_library_cc(
75+
name = name,
76+
srcs = srcs + tf_deps(deps, "_proto_srcs"),
77+
deps = deps,
78+
cc_libs = cc_libs,
79+
testonly = testonly,
80+
visibility = visibility,
81+
)
82+
83+
tf_proto_library_py(
84+
name = name,
85+
srcs = srcs + tf_deps(deps, "_proto_srcs"),
86+
srcs_version = "PY2AND3",
87+
deps = deps + ["@protobuf//:protobuf_python"],
88+
testonly = testonly,
89+
visibility = visibility,
90+
)
7791

7892
def tf_additional_lib_srcs():
7993
return [

tensorflow/python/BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ cc_binary(
134134
}),
135135
linkshared = 1,
136136
deps = [
137-
"//google/protobuf",
137+
"@protobuf//:protobuf",
138138
"//tensorflow/core:framework_headers_lib",
139139
],
140140
)
@@ -885,7 +885,7 @@ py_library(
885885
name = "util",
886886
srcs = glob(["util/**/*.py"]),
887887
srcs_version = "PY2AND3",
888-
deps = ["//google/protobuf:protobuf_python"],
888+
deps = ["@protobuf//:protobuf_python"],
889889
)
890890

891891
tf_proto_library(

tensorflow/tensorflow.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def cc_header_only_library(name, deps=[], **kwargs):
539539

540540
def tf_custom_op_library_additional_deps():
541541
return [
542-
"//google/protobuf",
542+
"@protobuf//:protobuf",
543543
"//third_party/eigen3",
544544
"//tensorflow/core:framework_headers_lib",
545545
]

tensorflow/tools/benchmark/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ tf_cc_test(
6161
# --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
6262
#
6363
# NOTE: currently '-pthread' must be removed from the LINK_OPTS variable
64-
# in google/protobuf/BUILD to sucessfully build for Android. This is temporary
64+
# in @protobuf//:BUILD to sucessfully build for Android. This is temporary
6565
# pending an update of the version of the protobuf library that Tensorflow
6666
# uses.
6767
cc_binary(

tensorflow/tools/pip_package/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ sh_binary(
2727
"MANIFEST.in",
2828
"README",
2929
"setup.py",
30-
"//tensorflow/core:framework_headers",
3130
":other_headers",
3231
":simple_console",
3332
"//tensorflow:tensorflow_py",
33+
"//tensorflow/core:framework_headers",
3434
"//tensorflow/examples/tutorials/mnist:package",
3535
"//tensorflow/models/embedding:package",
3636
"//tensorflow/models/image/alexnet:all_files",

tensorflow/tools/pip_package/build_pip_package.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ function main() {
6161

6262
# protobuf pip package doesn't ship with header files. Copy the headers
6363
# over so user defined ops can be compiled.
64+
mkdir -p ${TMPDIR}/google
6465
rsync --include "*/" --include "*.h" --exclude "*" --prune-empty-dirs -a \
65-
$RUNFILES/google ${TMPDIR}
66+
$RUNFILES/external/protobuf ${TMPDIR}/google
6667
rsync -a $RUNFILES/third_party/eigen3 ${TMPDIR}/third_party
6768

6869
cp tensorflow/tools/pip_package/MANIFEST.in ${TMPDIR}

tensorflow/workspace.bzl

+30-19
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,13 @@
44
# within the workspace (e.g. "tensorflow/"), and tf_repo_name is the name of the
55
# local_repository rule (e.g. "@tf").
66
def tf_workspace(path_prefix = "", tf_repo_name = ""):
7-
native.new_http_archive(
8-
name = "gmock_archive",
9-
url = "https://archive.openswitch.net/gmock-1.7.0.zip",
10-
sha256 = "26fcbb5925b74ad5fc8c26b0495dfc96353f4d553492eb97e85a8a6d2f43095b",
11-
build_file = path_prefix + "google/protobuf/gmock.BUILD",
12-
)
13-
147
native.new_http_archive(
158
name = "eigen_archive",
169
url = "https://bitbucket.org/eigen/eigen/get/f3a13643ac1f.tar.gz",
1710
sha256 = "a9266e60366cddb371a23d86b11a297eee86372a89ef4b38a3509012f9cc37ec",
1811
build_file = path_prefix + "eigen.BUILD",
1912
)
2013

21-
native.bind(
22-
name = "gtest",
23-
actual = "@gmock_archive//:gtest",
24-
)
25-
26-
native.bind(
27-
name = "gtest_main",
28-
actual = "@gmock_archive//:gtest_main",
29-
)
30-
3114
native.git_repository(
3215
name = "re2",
3316
remote = "https://github.com/google/re2.git",
@@ -85,16 +68,44 @@ def tf_workspace(path_prefix = "", tf_repo_name = ""):
8568
actual = "@six_archive//:six",
8669
)
8770

71+
native.git_repository(
72+
name = "protobuf",
73+
remote = "https://github.com/google/protobuf",
74+
commit = "ed87c1fe2c6e1633cadb62cf54b2723b2b25c280",
75+
)
76+
77+
native.new_http_archive(
78+
name = "gmock_archive",
79+
url = "https://archive.openswitch.net/gmock-1.7.0.zip",
80+
sha256 = "26fcbb5925b74ad5fc8c26b0495dfc96353f4d553492eb97e85a8a6d2f43095b",
81+
build_file = path_prefix + "gmock.BUILD",
82+
)
83+
84+
native.bind(
85+
name = "gtest",
86+
actual = "@gmock_archive//:gtest",
87+
)
88+
89+
native.bind(
90+
name = "gtest_main",
91+
actual = "@gmock_archive//:gtest_main",
92+
)
93+
94+
native.bind(
95+
name = "python_headers",
96+
actual = tf_repo_name + "//util/python:python_headers",
97+
)
98+
8899
# grpc expects //external:protobuf_clib and //external:protobuf_compiler
89100
# to point to the protobuf's compiler library.
90101
native.bind(
91102
name = "protobuf_clib",
92-
actual = tf_repo_name + "//google/protobuf:protoc_lib",
103+
actual = "@protobuf//:protoc_lib",
93104
)
94105

95106
native.bind(
96107
name = "protobuf_compiler",
97-
actual = tf_repo_name + "//google/protobuf:protoc_lib",
108+
actual = "@protobuf//:protoc_lib",
98109
)
99110

100111
native.git_repository(

0 commit comments

Comments
 (0)