Skip to content

Commit 7cace18

Browse files
authored
Support Bazel-based builds. (#452)
This fixes #334. It creates Bazel BUILD and WORKSPACE files to compile the code. The files are automatically kept in sync with the CMake files: our CMake files generate (most of) the contents for the Bazel files. This also introduces a Bazel CI build, and tests to verify the Bazel files are usable when embedded from another project.
1 parent 710a308 commit 7cace18

31 files changed

Lines changed: 819 additions & 40 deletions

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
_build/
44
build-output/
55

6+
# Common bazel output directories
7+
bazel-*
8+
69
# Backup files for Emacs
710
*~
811

912
# Ignore IDEA / IntelliJ files
1013
.idea/
1114
cmake-build-*/
1215

13-
# The Doxygen-generated documentation goes here:
14-
bigtable/doc/html/
15-
doc/html/
16-
1716
# This is a staging directory used to upload the documents to gihub.io
1817
github-io-staging/

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ matrix:
4747
compiler: clang
4848
script: ci/build-macosx.sh
4949
if: type != pull_request
50+
- # Compile on Travis' native environment with Bazel
51+
os: linux
52+
compiler: gcc
53+
git:
54+
submodules: false
55+
apt:
56+
sources:
57+
- ubuntu-toolchain-r-test
58+
packages:
59+
install: ci/install-bazel.sh
60+
script: ci/build-bazel.sh
5061
- # Compile against an installed version of gRPC.
5162
os: linux
5263
compiler: clang

BUILD

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
package(default_visibility = ["//visibility:public"])
16+
17+
licenses(["notice"]) # Apache 2.0
18+
19+
exports_files([
20+
"LICENSE",
21+
])

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ verify and fix the format of your code using:
8686
$ TRAVIS_OS_NAME=linux DISTRO=ubuntu DISTRO_VERSION=17.10 CXX=clang++ CC=clang CHECK_STYLE=yes ./ci/build-linux.sh
8787
```
8888

89+
### Updating CMakeLists.txt and/or BUILD files
90+
91+
If you need to change the list of files associated with a library, please change
92+
the existing `CMakeLists.txt` files, even if you use Bazel as your preferred
93+
build system. Changing the CMake files automatically update the corresponding
94+
`.bzl` files, but changing the `.bzl` files will not. More details in the short
95+
[design doc](doc/working-with-bazel-and-cmake.md).
96+
8997
## Advanced Compilation and Testing
9098

9199
Please see the [README](README.md) for the basic instructions on how to compile

WORKSPACE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
workspace(name = "com_github_googlecloudplatform_google_cloud_cpp")
16+
17+
load("//bazel:google_cloud_cpp_deps.bzl", "google_cloud_cpp_deps")
18+
google_cloud_cpp_deps()
19+
# Have to manually call the corresponding function for gRPC:
20+
# https://github.com/bazelbuild/bazel/issues/1550
21+
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
22+
grpc_deps()

bazel/BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
licenses(["notice"]) # Apache v2
16+
package(default_visibility = ["//:__subpackages__"])

bazel/google_cloud_cpp_deps.bzl

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Load dependencies needed to compile and test the google-cloud-cpp library."""
16+
17+
def google_cloud_cpp_deps():
18+
"""Loads dependencies need to compile the google-cloud-cpp library.
19+
20+
Application developers can call this function from their WORKSPACE file
21+
to obtain all the necessary dependencies for google-cloud-cpp, including
22+
gRPC and its dependencies. This function only loads dependencies that
23+
have not been previously loaded, allowing application developers to
24+
override the version of the dependencies they want to use.
25+
"""
26+
27+
# Load a newer version of google test than what gRPC does.
28+
if "com_google_googletest" not in native.existing_rules():
29+
native.new_http_archive(
30+
name = "com_google_googletest",
31+
build_file = "@com_github_googlecloudplatform_google_cloud_cpp//bazel:googletest.BUILD",
32+
strip_prefix = "googletest-4bd8c4638ada823a8da2569735cc0a9402fb8052",
33+
url = "https://github.com/google/googletest/archive/4bd8c4638ada823a8da2569735cc0a9402fb8052.tar.gz",
34+
sha256 = "9f842f79d92dfa694d9811918efb36a0bcd82d7b32f37a8f852dddde264c0f55",
35+
)
36+
37+
# Load the googleapis dependency.
38+
if "com_github_googleapis_googleapis" not in native.existing_rules():
39+
native.new_http_archive(
40+
name = "com_github_googleapis_googleapis",
41+
url = "https://github.com/google/googleapis/archive/f81082ea1e2f85c43649bee26e0d9871d4b41cdb.zip",
42+
strip_prefix="googleapis-f81082ea1e2f85c43649bee26e0d9871d4b41cdb",
43+
sha256 = "824870d87a176f26bcef663e92051f532fac756d1a06b404055dc078425f4378",
44+
build_file = "@com_github_googlecloudplatform_google_cloud_cpp//bazel:googleapis.BUILD",
45+
workspace_file = "@com_github_googlecloudplatform_google_cloud_cpp//bazel:googleapis.WORKSPACE",
46+
)
47+
48+
# Load gRPC and its dependencies, using a similar pattern to this function.
49+
# This implictly loads "com_google_protobuf", which we use.
50+
if "com_github_grpc_grpc" not in native.existing_rules():
51+
native.http_archive(
52+
name = "com_github_grpc_grpc",
53+
strip_prefix = "grpc-1.10.0",
54+
urls = [
55+
"https://mirror.bazel.build/github.com/grpc/grpc/archive/v1.10.0.tar.gz",
56+
"https://github.com/grpc/grpc/archive/v1.10.0.tar.gz",
57+
],
58+
sha256 = "39a73de6fa2a03bdb9c43c89a4283e09880833b3c1976ef3ce3edf45c8cacf72"
59+
)
60+
61+
# We use the cc_proto_library() rule from @com_google_protobuf, which
62+
# assumes that grpc_cpp_plugin and grpc_lib are in the //external: module
63+
native.bind(
64+
name = "grpc_cpp_plugin",
65+
actual = "@com_github_grpc_grpc//:grpc_cpp_plugin"
66+
)
67+
68+
native.bind(
69+
name = "grpc_lib",
70+
actual = "@com_github_grpc_grpc//:grpc++"
71+
)

bazel/googleapis.BUILD

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
package(default_visibility = ["//visibility:public"])
16+
licenses(["notice"]) # Apache 2.0
17+
18+
load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library")
19+
20+
cc_proto_library(
21+
name = "bigtable_protos",
22+
srcs = [
23+
"google/bigtable/admin/v2/bigtable_instance_admin.proto",
24+
"google/bigtable/admin/v2/bigtable_table_admin.proto",
25+
"google/bigtable/admin/v2/common.proto",
26+
"google/bigtable/admin/v2/instance.proto",
27+
"google/bigtable/admin/v2/table.proto",
28+
"google/bigtable/v2/bigtable.proto",
29+
"google/bigtable/v2/data.proto",
30+
"google/iam/v1/iam_policy.proto",
31+
"google/iam/v1/policy.proto",
32+
"google/longrunning/operations.proto",
33+
"google/rpc/status.proto",
34+
"google/rpc/error_details.proto",
35+
"google/api/annotations.proto",
36+
"google/api/auth.proto",
37+
"google/api/http.proto",
38+
],
39+
include = ".",
40+
protoc = "@com_google_protobuf//:protoc",
41+
default_runtime = "@com_google_protobuf//:protobuf",
42+
deps = ["@com_google_protobuf//:cc_wkt_protos"],
43+
use_grpc_plugin = True,
44+
)

bazel/googleapis.WORKSPACE

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
workspace(name = "com_github_googleapis_googleapis")
16+
17+
http_archive(
18+
name = "com_github_grpc_grpc",
19+
strip_prefix = "grpc-1.10.0",
20+
urls = [
21+
"https://mirror.bazel.build/github.com/grpc/grpc/archive/v1.10.0.tar.gz",
22+
"https://github.com/grpc/grpc/archive/v1.10.0.tar.gz",
23+
],
24+
sha256 = "39a73de6fa2a03bdb9c43c89a4283e09880833b3c1976ef3ce3edf45c8cacf72",
25+
)
26+
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
27+
grpc_deps()
28+

bazel/googletest.BUILD

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
licenses(["notice"])
4+
5+
# Google Test including Google Mock
6+
cc_library(
7+
name = "gtest",
8+
srcs = glob(
9+
include = [
10+
"googletest/src/*.cc",
11+
"googletest/src/*.h",
12+
"googletest/include/gtest/**/*.h",
13+
"googlemock/src/*.cc",
14+
"googlemock/include/gmock/**/*.h",
15+
],
16+
exclude = [
17+
"googletest/src/gtest-all.cc",
18+
"googletest/src/gtest_main.cc",
19+
"googlemock/src/gmock-all.cc",
20+
"googlemock/src/gmock_main.cc",
21+
],
22+
),
23+
hdrs =glob([
24+
"googletest/include/gtest/*.h",
25+
"googlemock/include/gmock/*.h",
26+
]),
27+
includes = [
28+
"googlemock",
29+
"googlemock/include",
30+
"googletest",
31+
"googletest/include",
32+
],
33+
)
34+
35+
cc_library(
36+
name = "gtest_main",
37+
srcs = [
38+
"googlemock/src/gmock_main.cc",
39+
],
40+
deps = ["//:gtest"],
41+
)

0 commit comments

Comments
 (0)