Skip to content

Commit 52dc55d

Browse files
committed
Refactor dependency loading.
- Splits the large repositories.bzl into language-specific deps.bzl files. - Rewrite of require.bzl to return a list of unloaded deps having no native rule, allowing special cases (custom repository rules) to clean up remaining. - "kind" replaced with "rule". - Elimination of shortnames in deps.bzl files, hash key is now workspace name. - New option 'omit_cpp_repositories' to suppress loading of dependent rule sets for authors that want complete control over loading.
1 parent 6b0e1ae commit 52dc55d

File tree

25 files changed

+729
-677
lines changed

25 files changed

+729
-677
lines changed

WORKSPACE

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,47 +66,35 @@ node_repositories()
6666
# ================================================================
6767

6868
load("//protobuf:rules.bzl", "proto_repositories")
69-
7069
proto_repositories()
7170

7271
load("//cpp:rules.bzl", "cpp_proto_repositories")
73-
7472
cpp_proto_repositories()
7573

7674
load("//csharp:rules.bzl", "csharp_proto_repositories")
77-
7875
csharp_proto_repositories()
7976

8077
load("//java:rules.bzl", "java_proto_repositories", "nano_proto_repositories")
81-
8278
java_proto_repositories()
83-
8479
nano_proto_repositories()
8580

8681
load("//go:rules.bzl", "go_proto_repositories")
87-
8882
go_proto_repositories()
8983

9084
load("//gogo:rules.bzl", "gogo_proto_repositories")
91-
9285
gogo_proto_repositories()
9386

9487
load("//grpc_gateway:rules.bzl", "grpc_gateway_proto_repositories")
95-
9688
grpc_gateway_proto_repositories()
9789

9890
load("//node:rules.bzl", "node_proto_repositories")
99-
10091
node_proto_repositories()
10192

10293
load("//objc:rules.bzl", "objc_proto_repositories")
103-
10494
objc_proto_repositories()
10595

10696
load("//python:rules.bzl", "py_proto_repositories")
107-
10897
py_proto_repositories()
10998

11099
load("//ruby:rules.bzl", "ruby_proto_repositories")
111-
112100
ruby_proto_repositories()

cpp/deps.bzl

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# ****************************************************************
2+
# List of external dependencies
3+
# ****************************************************************
4+
5+
DEPS = {
6+
7+
# Grpc repo is required by multiple languages but we put it here.
8+
"com_github_grpc_grpc": {
9+
"rule": "git_repository",
10+
"remote": "https://github.com/grpc/grpc.git",
11+
"init_submodules": True,
12+
"commit": "673fa6c88b8abd542ae50c4480de92880a1e4777",
13+
},
14+
15+
# Hooray! The boringssl team provides a "master-with-bazel" branch
16+
# with all BUILD files ready to go. To update, pick the
17+
# newest-ish commit-id off that branch.
18+
"boringssl": {
19+
"rule": "git_repository",
20+
"remote": "https://boringssl.googlesource.com/boringssl",
21+
"commit": "36b3ab3e5d3a4892444a698f7989f2150824d804", # Aug 3 2016
22+
},
23+
24+
# libssl is required for c++ grpc where it is expected in
25+
# //external:libssl. This can be either boringssl or openssl.
26+
"libssl": {
27+
"rule": "bind",
28+
"actual": "@boringssl//:ssl",
29+
},
30+
31+
# C-library for zlib
32+
"com_github_madler_zlib": {
33+
"rule": "new_git_repository",
34+
"remote": "https://github.com/madler/zlib",
35+
"tag": "v1.2.8",
36+
"build_file": str(Label("//protobuf:build_file/com_github_madler_zlib.BUILD")),
37+
},
38+
39+
# grpc++ expects //external:zlib
40+
"zlib": {
41+
"rule": "bind",
42+
"actual": "@com_github_madler_zlib//:zlib",
43+
},
44+
45+
# grpc++ expects "//external:protobuf_clib"
46+
"protobuf_clib": {
47+
"rule": "bind",
48+
"actual": "@com_github_google_protobuf//:protobuf",
49+
},
50+
51+
# grpc++ requires nanobp (and now has a BUILD file!)
52+
"com_github_nanopb_nanopb": {
53+
"rule": "git_repository",
54+
"remote": "https://github.com/nanopb/nanopb.git",
55+
"commit": "91bb64a47b36b112c9b22391ef76fab29cf2cffc", # Sep 1 2016
56+
},
57+
58+
# grpc++ expects //external:nanopb
59+
"nanopb": {
60+
"rule": "bind",
61+
"actual": "@com_github_nanopb_nanopb//:nanopb",
62+
},
63+
64+
# Bind the executable cc_binary grpc plugin into
65+
# //external:protoc_gen_grpc_cpp. Expects
66+
# //external:protobuf_compiler. TODO: is it really necessary to
67+
# bind it in external?
68+
"protoc_gen_grpc_cpp": {
69+
"rule": "bind",
70+
"actual": "@com_github_grpc_grpc//:grpc_cpp_plugin",
71+
},
72+
73+
# Bind the protobuf proto_lib into //external. Required for
74+
# compiling the protoc_gen_grpc plugin
75+
"protobuf_compiler": {
76+
"rule": "bind",
77+
"actual": "@com_github_google_protobuf//:protoc_lib",
78+
},
79+
80+
# GTest is for our own internal cc tests.
81+
"gtest": {
82+
"rule": "new_git_repository",
83+
"remote": "https://github.com/google/googletest.git",
84+
"commit": "ed9d1e1ff92ce199de5ca2667a667cd0a368482a",
85+
"build_file": str(Label("//protobuf:build_file/gtest.BUILD")),
86+
},
87+
88+
}

cpp/rules.bzl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
load("//protobuf:rules.bzl", "proto_compile", "proto_repositories")
2+
load("//cpp:deps.bzl", "DEPS")
23

34
def cpp_proto_repositories(
5+
lang_deps = DEPS,
46
lang_requires = [
5-
"external_protobuf_clib",
7+
"protobuf_clib",
68
"gtest",
7-
"grpc",
9+
"com_github_grpc_grpc",
10+
"com_github_madler_zlib",
811
"zlib",
9-
"external_zlib",
12+
"com_github_nanopb_nanopb",
1013
"nanopb",
11-
"external_nanopb",
1214
"boringssl",
1315
"libssl",
14-
"external_protobuf_compiler",
15-
"third_party_protoc",
16-
"external_protoc_gen_grpc_cpp",
16+
"protobuf_compiler",
17+
"protoc_gen_grpc_cpp",
1718
], **kwargs):
18-
proto_repositories(lang_requires = lang_requires, **kwargs)
19+
20+
proto_repositories(lang_deps = lang_deps,
21+
lang_requires = lang_requires,
22+
**kwargs)
1923

2024
PB_COMPILE_DEPS = [
2125
"//external:protobuf_clib",
@@ -25,7 +29,6 @@ GRPC_COMPILE_DEPS = PB_COMPILE_DEPS + [
2529
"@com_github_grpc_grpc//:grpc++",
2630
]
2731

28-
2932
def cpp_proto_compile(langs = [str(Label("//cpp"))], **kwargs):
3033
proto_compile(langs = langs, **kwargs)
3134

csharp/deps.bzl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# ****************************************************************
2+
# List of external dependencies
3+
# ****************************************************************
4+
5+
PROTOBUF_BUILD_FILE = """
6+
load("@io_bazel_rules_dotnet//dotnet:csharp.bzl", "dll_import")
7+
dll_import(
8+
name = "libnet45",
9+
srcs = [
10+
"Google.Protobuf.3.0.0/lib/net45/Google.Protobuf.dll",
11+
],
12+
visibility = ["//visibility:public"],
13+
)
14+
"""
15+
16+
GRPC_BUILD_FILE = """
17+
load("@io_bazel_rules_dotnet//dotnet:csharp.bzl", "dll_import")
18+
dll_import(
19+
name = "runtime_osx",
20+
srcs = glob(["Grpc.Core.1.0.0/runtimes/osx/**/*.dll"]),
21+
visibility = ["//visibility:public"],
22+
)
23+
dll_import(
24+
name = "system_interactive_async",
25+
srcs = glob(["System.Interactive.Async.3.0.0/lib/net45/**/*.dll"]),
26+
visibility = ["//visibility:public"],
27+
)
28+
dll_import(
29+
name = "core",
30+
srcs = glob(["Grpc.Core.1.0.0/lib/net45/**/*.dll"]),
31+
visibility = ["//visibility:public"],
32+
)
33+
"""
34+
35+
DEPS = {
36+
37+
"nuget_google_protobuf": {
38+
"rule": "new_nuget_package",
39+
"package": "Google.Protobuf",
40+
"version": "3.0.0",
41+
"build_file_content": PROTOBUF_BUILD_FILE,
42+
},
43+
44+
"nuget_grpc": {
45+
"rule": "new_nuget_package",
46+
"package": "Grpc",
47+
"version": "1.0.0",
48+
"build_file_content": GRPC_BUILD_FILE,
49+
},
50+
51+
}

csharp/rules.bzl

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,30 @@
11
load("@io_bazel_rules_dotnet//dotnet:csharp.bzl", "nuget_package", "new_nuget_package", "csharp_library", "dll_import")
22
load("//protobuf:rules.bzl", "proto_compile", "proto_repositories", "proto_language_deps")
3-
4-
def csharp_proto_repositories():
5-
proto_repositories()
6-
7-
new_nuget_package(
8-
name = "nuget_google_protobuf",
9-
package = "Google.Protobuf",
10-
version = "3.0.0",
11-
build_file_content =
12-
"""
13-
load("@io_bazel_rules_dotnet//dotnet:csharp.bzl", "dll_import")
14-
dll_import(
15-
name = "libnet45",
16-
srcs = [
17-
"Google.Protobuf.3.0.0/lib/net45/Google.Protobuf.dll",
18-
],
19-
visibility = ["//visibility:public"],
20-
)
21-
"""
22-
)
23-
24-
new_nuget_package(
25-
name = "nuget_grpc",
26-
package = "Grpc",
27-
version = "1.0.0",
28-
build_file_content =
29-
"""
30-
load("@io_bazel_rules_dotnet//dotnet:csharp.bzl", "dll_import")
31-
dll_import(
32-
name = "runtime_osx",
33-
srcs = glob(["Grpc.Core.1.0.0/runtimes/osx/**/*.dll"]),
34-
visibility = ["//visibility:public"],
35-
)
36-
dll_import(
37-
name = "system_interactive_async",
38-
srcs = glob(["System.Interactive.Async.3.0.0/lib/net45/**/*.dll"]),
39-
visibility = ["//visibility:public"],
40-
)
41-
dll_import(
42-
name = "core",
43-
srcs = glob(["Grpc.Core.1.0.0/lib/net45/**/*.dll"]),
44-
visibility = ["//visibility:public"],
45-
)
46-
"""
47-
)
3+
load("//cpp:rules.bzl", "cpp_proto_repositories")
4+
load("//csharp:deps.bzl", "DEPS")
5+
6+
def csharp_proto_repositories(
7+
omit_cpp_repositories = False,
8+
lang_deps = DEPS,
9+
lang_requires = [
10+
"nuget_google_protobuf",
11+
"nuget_grpc",
12+
], **kwargs):
13+
14+
if not omit_cpp_repositories:
15+
cpp_proto_repositories()
16+
17+
rem = proto_repositories(lang_deps = lang_deps,
18+
lang_requires = lang_requires,
19+
**kwargs)
20+
21+
# Load remaining (nuget) deps
22+
for dep in rem:
23+
rule = dep.pop("rule")
24+
if "new_nuget_package" == rule:
25+
new_nuget_package(**dep)
26+
else:
27+
fail("Unknown loading rule %s for %s" % (rule, dep))
4828

4929
PB_COMPILE_DEPS = [
5030
"@nuget_google_protobuf//:libnet45",

go/deps.bzl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ****************************************************************
2+
# List of external dependencies
3+
# ****************************************************************
4+
5+
DEPS = {
6+
7+
"com_github_golang_glog": {
8+
"rule": "new_git_repository",
9+
"remote": "https://github.com/golang/glog.git",
10+
"commit": "23def4e6c14b4da8ac2ed8007337bc5eb5007998", # Jan 25, 2016
11+
"build_file": str(Label("//protobuf:build_file/com_github_golang_glog.BUILD")),
12+
},
13+
14+
"com_github_golang_protobuf": {
15+
"rule": "new_git_repository",
16+
"remote": "https://github.com/golang/protobuf.git",
17+
"commit": "c3cefd437628a0b7d31b34fe44b3a7a540e98527", # Jul 27, 2016
18+
"build_file": str(Label("//protobuf:build_file/com_github_golang_protobuf.BUILD")),
19+
},
20+
21+
"org_golang_google_grpc": {
22+
"rule": "new_git_repository",
23+
"remote": "https://github.com/grpc/grpc-go.git",
24+
"tag": "v1.0.0",
25+
"build_file": str(Label("//protobuf:build_file/org_golang_google_grpc.BUILD")),
26+
},
27+
28+
"org_golang_x_net": {
29+
"rule": "new_git_repository",
30+
"remote": "https://github.com/golang/net.git",
31+
"commit": "2a35e686583654a1b89ca79c4ac78cb3d6529ca3",
32+
"build_file": str(Label("//protobuf:build_file/org_golang_x_net.BUILD")),
33+
},
34+
35+
}

go/rules.bzl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
load("@io_bazel_rules_go//go:def.bzl", "go_library")
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "new_go_repository")
22
load("//protobuf:rules.bzl", "proto_compile", "proto_repositories")
3+
load("//go:deps.bzl", "DEPS")
34

45
def go_proto_repositories(
6+
lang_deps = DEPS,
57
lang_requires = [
6-
"protobuf",
7-
"external_protoc",
88
"com_github_golang_protobuf",
99
"com_github_golang_glog",
1010
"org_golang_google_grpc",
1111
"org_golang_x_net",
1212
], **kwargs):
13-
proto_repositories(lang_requires = lang_requires, **kwargs)
13+
14+
rem = proto_repositories(lang_deps = lang_deps,
15+
lang_requires = lang_requires,
16+
**kwargs)
17+
18+
# Load remaining (special) deps
19+
for dep in rem:
20+
rule = dep.pop("rule")
21+
if "new_go_repository" == rule:
22+
new_go_repository(**dep)
23+
else:
24+
fail("Unknown loading rule %s for %s" % (rule, dep))
1425

1526

1627
PB_COMPILE_DEPS = [

gogo/deps.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# ****************************************************************
2+
# List of external dependencies
3+
# ****************************************************************
4+
5+
DEPS = {
6+
7+
"com_github_gogo_protobuf": {
8+
"rule": "new_go_repository",
9+
"importpath": "github.com/gogo/protobuf",
10+
"commit": "a11c89fbb0ad4acfa8abc4a4d5f7e27c477169b1",
11+
},
12+
13+
}

0 commit comments

Comments
 (0)