Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 91f1f53

Browse files
panzhongxiang-easy
authored andcommitted
Simplify WORKSPACE file. (#380)
* Move dependency loading into bazel/deps.bzl file. * Move BUILD file overrides into separate files. * Travis: update bazel version from 0.24 to 0.29.0.
1 parent accf3e7 commit 91f1f53

5 files changed

Lines changed: 131 additions & 113 deletions

File tree

WORKSPACE

Lines changed: 3 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,9 @@
1515
workspace(name = "io_opencensus_cpp")
1616

1717
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
18+
load("//bazel:deps.bzl", "opencensus_cpp_deps")
1819

19-
# Build rules for C++ projects.
20-
http_archive(
21-
name = "rules_cc",
22-
strip_prefix = "rules_cc-master",
23-
urls = ["https://github.com/bazelbuild/rules_cc/archive/master.zip"],
24-
)
25-
26-
# We depend on Abseil.
27-
http_archive(
28-
name = "com_google_absl",
29-
strip_prefix = "abseil-cpp-master",
30-
urls = ["https://github.com/abseil/abseil-cpp/archive/master.zip"],
31-
)
20+
opencensus_cpp_deps()
3221

3322
# GoogleTest framework.
3423
# Only needed for tests, not to build the OpenCensus library.
@@ -46,13 +35,6 @@ http_archive(
4635
urls = ["https://github.com/google/benchmark/archive/master.zip"],
4736
)
4837

49-
# gRPC
50-
http_archive(
51-
name = "com_github_grpc_grpc",
52-
strip_prefix = "grpc-master",
53-
urls = ["https://github.com/grpc/grpc/archive/master.tar.gz"],
54-
)
55-
5638
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
5739

5840
grpc_deps()
@@ -83,87 +65,12 @@ local_repository(
8365
path = "tools/zlib",
8466
)
8567

86-
# Prometheus client library - used by Prometheus exporter.
87-
http_archive(
88-
name = "com_github_jupp0r_prometheus_cpp",
89-
strip_prefix = "prometheus-cpp-master",
90-
urls = ["https://github.com/jupp0r/prometheus-cpp/archive/master.zip"],
91-
)
92-
68+
# Load Prometheus dependencies individually since we load some of them above.
9369
load("@com_github_jupp0r_prometheus_cpp//:repositories.bzl", "load_civetweb")
9470

95-
# Load Prometheus dependencies individually since we load some of them above.
9671
load_civetweb()
9772

98-
# Curl library - used by zipkin exporter.
99-
http_archive(
100-
name = "com_github_curl",
101-
build_file_content =
102-
"""
103-
load("@io_opencensus_cpp//opencensus:curl.bzl", "CURL_COPTS")
104-
package(features = ['no_copts_tokenization'])
105-
106-
config_setting(
107-
name = "windows",
108-
values = {"cpu": "x64_windows"},
109-
visibility = [ "//visibility:private" ],
110-
)
111-
112-
config_setting(
113-
name = "osx",
114-
values = {"cpu": "darwin"},
115-
visibility = [ "//visibility:private" ],
116-
)
117-
118-
cc_library(
119-
name = "curl",
120-
srcs = glob([
121-
"lib/**/*.c",
122-
]),
123-
hdrs = glob([
124-
"include/curl/*.h",
125-
"lib/**/*.h",
126-
]),
127-
includes = ["include/", "lib/"],
128-
copts = CURL_COPTS + [
129-
"-DOS=\\"os\\"",
130-
"-DCURL_EXTERN_SYMBOL=__attribute__((__visibility__(\\"default\\")))",
131-
],
132-
visibility = ["//visibility:public"],
133-
)
134-
""",
135-
strip_prefix = "curl-master",
136-
urls = ["https://github.com/curl/curl/archive/master.zip"],
137-
)
138-
139-
# Rapidjson library - used by zipkin exporter.
140-
http_archive(
141-
name = "com_github_tencent_rapidjson",
142-
build_file_content =
143-
"""
144-
cc_library(
145-
name = "rapidjson",
146-
srcs = [],
147-
hdrs = glob([
148-
"include/rapidjson/*.h",
149-
"include/rapidjson/internal/*.h",
150-
"include/rapidjson/error/*.h",
151-
]),
152-
includes = ["include/"],
153-
visibility = ["//visibility:public"],
154-
)
155-
""",
156-
strip_prefix = "rapidjson-master",
157-
urls = ["https://github.com/Tencent/rapidjson/archive/master.zip"],
158-
)
159-
16073
# Google APIs - used by Stackdriver exporter.
161-
http_archive(
162-
name = "com_google_googleapis",
163-
strip_prefix = "googleapis-master",
164-
urls = ["https://github.com/googleapis/googleapis/archive/master.zip"],
165-
)
166-
16774
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
16875

16976
switched_rules_by_language(
@@ -173,24 +80,8 @@ switched_rules_by_language(
17380
)
17481

17582
# Needed by @opencensus_proto.
176-
http_archive(
177-
name = "io_bazel_rules_go",
178-
sha256 = "9fb16af4d4836c8222142e54c9efa0bb5fc562ffc893ce2abeac3e25daead144",
179-
urls = [
180-
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/0.19.0/rules_go-0.19.0.tar.gz",
181-
"https://github.com/bazelbuild/rules_go/releases/download/0.19.0/rules_go-0.19.0.tar.gz",
182-
],
183-
)
184-
18583
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
18684

18785
go_rules_dependencies()
18886

18987
go_register_toolchains()
190-
191-
# OpenCensus protos - used by OcAgent exporter.
192-
http_archive(
193-
name = "opencensus_proto",
194-
strip_prefix = "opencensus-proto-master/src",
195-
urls = ["https://github.com/census-instrumentation/opencensus-proto/archive/master.zip"],
196-
)

bazel/curl.BUILD

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
load("@io_opencensus_cpp//opencensus:curl.bzl", "CURL_COPTS")
2+
3+
package(features = ["no_copts_tokenization"])
4+
5+
config_setting(
6+
name = "windows",
7+
values = {"cpu": "x64_windows"},
8+
visibility = ["//visibility:private"],
9+
)
10+
11+
config_setting(
12+
name = "osx",
13+
values = {"cpu": "darwin"},
14+
visibility = ["//visibility:private"],
15+
)
16+
17+
cc_library(
18+
name = "curl",
19+
srcs = glob([
20+
"lib/**/*.c",
21+
]),
22+
hdrs = glob([
23+
"include/curl/*.h",
24+
"lib/**/*.h",
25+
]),
26+
copts = CURL_COPTS + [
27+
"-DOS=\"os\"",
28+
"-DCURL_EXTERN_SYMBOL=__attribute__((__visibility__(\"default\")))",
29+
],
30+
includes = [
31+
"include/",
32+
"lib/",
33+
],
34+
visibility = ["//visibility:public"],
35+
)

bazel/deps.bzl

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
3+
4+
def opencensus_cpp_deps():
5+
"""Loads dependencies need to compile the opencensus-cpp library."""
6+
7+
maybe(
8+
http_archive,
9+
name = "rules_cc",
10+
strip_prefix = "rules_cc-master",
11+
urls = ["https://github.com/bazelbuild/rules_cc/archive/master.zip"],
12+
)
13+
14+
# We depend on Abseil.
15+
maybe(
16+
http_archive,
17+
name = "com_google_absl",
18+
strip_prefix = "abseil-cpp-master",
19+
urls = ["https://github.com/abseil/abseil-cpp/archive/master.zip"],
20+
)
21+
22+
# gRPC
23+
maybe(
24+
http_archive,
25+
name = "com_github_grpc_grpc",
26+
strip_prefix = "grpc-master",
27+
urls = ["https://github.com/grpc/grpc/archive/master.tar.gz"],
28+
)
29+
30+
# Prometheus client library - used by Prometheus exporter.
31+
maybe(
32+
http_archive,
33+
name = "com_github_jupp0r_prometheus_cpp",
34+
strip_prefix = "prometheus-cpp-master",
35+
urls = ["https://github.com/jupp0r/prometheus-cpp/archive/master.zip"],
36+
)
37+
38+
# Curl library - used by zipkin exporter.
39+
maybe(
40+
http_archive,
41+
name = "com_github_curl",
42+
build_file = "//:bazel/curl.BUILD",
43+
strip_prefix = "curl-master",
44+
urls = ["https://github.com/curl/curl/archive/master.zip"],
45+
)
46+
47+
# Rapidjson library - used by zipkin exporter.
48+
maybe(
49+
http_archive,
50+
name = "com_github_tencent_rapidjson",
51+
build_file = "//:bazel/rapidjson.BUILD",
52+
strip_prefix = "rapidjson-master",
53+
urls = ["https://github.com/Tencent/rapidjson/archive/master.zip"],
54+
)
55+
56+
# Google APIs - used by Stackdriver exporter.
57+
maybe(
58+
http_archive,
59+
name = "com_google_googleapis",
60+
strip_prefix = "googleapis-master",
61+
urls = ["https://github.com/googleapis/googleapis/archive/master.zip"],
62+
)
63+
64+
# Needed by opencensus-proto.
65+
maybe(
66+
http_archive,
67+
name = "io_bazel_rules_go",
68+
sha256 = "9fb16af4d4836c8222142e54c9efa0bb5fc562ffc893ce2abeac3e25daead144",
69+
urls = [
70+
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/0.19.0/rules_go-0.19.0.tar.gz",
71+
"https://github.com/bazelbuild/rules_go/releases/download/0.19.0/rules_go-0.19.0.tar.gz",
72+
],
73+
)
74+
75+
# OpenCensus proto - used by OcAgent exporter.
76+
maybe(
77+
http_archive,
78+
name = "opencensus_proto",
79+
strip_prefix = "opencensus-proto-master/src",
80+
urls = ["https://github.com/census-instrumentation/opencensus-proto/archive/master.zip"],
81+
)

bazel/rapidjson.BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cc_library(
2+
name = "rapidjson",
3+
srcs = [],
4+
hdrs = glob([
5+
"include/rapidjson/*.h",
6+
"include/rapidjson/internal/*.h",
7+
"include/rapidjson/error/*.h",
8+
]),
9+
includes = ["include/"],
10+
visibility = ["//visibility:public"],
11+
)

tools/travis/build_bazel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if [[ "$TRAVIS_COMPILER" = "clang" ]]; then
2727
export BAZEL_OPTIONS="$BAZEL_OPTIONS --copt=-Werror=thread-safety --copt=-Werror=thread-safety-reference"
2828
fi
2929

30-
export BAZEL_VERSION="0.24.1"
30+
export BAZEL_VERSION="0.29.0"
3131

3232
wget https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-${BAZEL_OS}-x86_64.sh
3333
chmod +x bazel-${BAZEL_VERSION}-installer-${BAZEL_OS}-x86_64.sh

0 commit comments

Comments
 (0)