Skip to content

Commit bf0c69e

Browse files
Yannicacozzette
authored andcommitted
[bazel] Add fixes for --incompatible_load_{cc,java,proto}_rules_from_bzl (Part 2)
This change adds the required loads to examples and zlib. For full compatibility with --incompatible_load_{cc,java,proto}_rules_from_bzl, we will need to roll gtest to a newer version.
1 parent 5b6238e commit bf0c69e

File tree

10 files changed

+39
-50
lines changed

10 files changed

+39
-50
lines changed

BUILD

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,12 +787,9 @@ py_library(
787787
name = "python_srcs",
788788
srcs = glob(
789789
[
790-
"python/google/__init__.py",
791-
"python/google/protobuf/*.py",
792-
"python/google/protobuf/**/*.py",
790+
"python/google/**/*.py",
793791
],
794792
exclude = [
795-
"python/google/protobuf/__init__.py",
796793
"python/google/protobuf/**/__init__.py",
797794
"python/google/protobuf/internal/*_test.py",
798795
"python/google/protobuf/internal/test_util.py",

Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,6 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \
12301230
examples/list_people.py \
12311231
examples/list_people_test.go \
12321232
examples/pubspec.yaml \
1233-
examples/third_party/zlib.BUILD \
12341233
protobuf.bzl \
12351234
protobuf_deps.bzl \
12361235
python/release/wheel/build_wheel_manylinux.sh \

WORKSPACE

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
workspace(name = "com_google_protobuf")
22

3+
local_repository(
4+
name = "com_google_protobuf_examples",
5+
path = "examples",
6+
)
7+
38
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
49
load("//:protobuf_deps.bzl", "protobuf_deps")
510

@@ -19,13 +24,6 @@ http_archive(
1924
urls = ["https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55"],
2025
)
2126

22-
http_archive(
23-
name = "bazel_skylib",
24-
sha256 = "bbccf674aa441c266df9894182d80de104cabd19be98be002f6d478aaa31574d",
25-
strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b",
26-
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
27-
)
28-
2927
bind(
3028
name = "python_headers",
3129
actual = "//util/python:python_headers",

examples/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# the WORKSPACE file in the same directory with this BUILD file for an
55
# example.
66

7+
load("@rules_proto//proto:defs.bzl", "proto_library")
8+
load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library")
9+
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_proto_library")
10+
711
# For each .proto file, a proto_library target should be defined. This target
812
# is not bound to any particular language. Instead, it defines the dependency
913
# graph of the .proto files (i.e., proto imports) and serves as the provider

examples/WORKSPACE

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
1+
workspace(name = "com_google_protobuf_examples")
2+
13
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
24

35
# This com_google_protobuf repository is required for proto_library rule.
46
# It provides the protocol compiler binary (i.e., protoc).
5-
http_archive(
7+
#
8+
# We declare it as local_repository so we can test changes
9+
# before they get merged. You'll want to use the following instead:
10+
#
11+
# http_archive(
12+
# name = "com_google_protobuf",
13+
# strip_prefix = "protobuf-master",
14+
# urls = ["https://github.com/protocolbuffers/protobuf/archive/master.zip"],
15+
# )
16+
local_repository(
617
name = "com_google_protobuf",
7-
strip_prefix = "protobuf-master",
8-
urls = ["https://github.com/protocolbuffers/protobuf/archive/master.zip"],
18+
path = "..",
919
)
1020

11-
# This com_google_protobuf_cc repository is required for cc_proto_library
12-
# rule. It provides protobuf C++ runtime. Note that it actually is the same
13-
# repo as com_google_protobuf but has to be given a different name as
14-
# required by bazel.
15-
http_archive(
16-
name = "com_google_protobuf_cc",
17-
strip_prefix = "protobuf-master",
18-
urls = ["https://github.com/protocolbuffers/protobuf/archive/master.zip"],
19-
)
20-
21-
# Similar to com_google_protobuf_cc but for Java (i.e., java_proto_library).
22-
http_archive(
23-
name = "com_google_protobuf_java",
24-
strip_prefix = "protobuf-master",
25-
urls = ["https://github.com/protocolbuffers/protobuf/archive/master.zip"],
26-
)
27-
28-
# Similar to com_google_protobuf_cc but for Java lite. If you are building
21+
# Similar to com_google_protobuf but for Java lite. If you are building
2922
# for Android, the lite version should be prefered because it has a much
3023
# smaller code size.
3124
http_archive(
@@ -34,17 +27,6 @@ http_archive(
3427
urls = ["https://github.com/protocolbuffers/protobuf/archive/javalite.zip"],
3528
)
3629

37-
http_archive(
38-
name = "bazel_skylib",
39-
sha256 = "bbccf674aa441c266df9894182d80de104cabd19be98be002f6d478aaa31574d",
40-
strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b",
41-
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
42-
)
43-
4430
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
4531

4632
protobuf_deps()
47-
48-
load("@bazel_skylib//lib:versions.bzl", "versions")
49-
50-
versions.check(minimum_bazel_version = "0.5.4")

examples/third_party/zlib.BUILD

Lines changed: 0 additions & 1 deletion
This file was deleted.

protobuf.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
12
load("@bazel_skylib//lib:versions.bzl", "versions")
23

34
def _GetPath(ctx, path):
@@ -276,7 +277,7 @@ def cc_proto_library(
276277
)
277278

278279
# An empty cc_library to make rule dependency consistent.
279-
native.cc_library(
280+
cc_library(
280281
name = name,
281282
**kargs
282283
)
@@ -307,8 +308,7 @@ def cc_proto_library(
307308
cc_libs = cc_libs + [default_runtime]
308309
if use_grpc_plugin:
309310
cc_libs = cc_libs + ["//external:grpc_lib"]
310-
311-
native.cc_library(
311+
cc_library(
312312
name = name,
313313
srcs = gen_srcs,
314314
hdrs = gen_hdrs,

protobuf_deps.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
55
def protobuf_deps():
66
"""Loads common dependencies needed to compile the protobuf library."""
77

8+
if not native.existing_rule("bazel_skylib"):
9+
http_archive(
10+
name = "bazel_skylib",
11+
sha256 = "bbccf674aa441c266df9894182d80de104cabd19be98be002f6d478aaa31574d",
12+
strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b",
13+
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
14+
)
15+
816
if not native.existing_rule("zlib"):
917
http_archive(
1018
name = "zlib",

third_party/zlib.BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package(default_visibility = ["//visibility:public"])
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
22

33
licenses(["notice"]) # BSD/MIT-like license (for zlib)
44

@@ -26,7 +26,6 @@ genrule(
2626
srcs = _ZLIB_HEADERS,
2727
outs = _ZLIB_PREFIXED_HEADERS,
2828
cmd = "cp $(SRCS) $(@D)/zlib/include/",
29-
visibility = ["//visibility:private"],
3029
)
3130

3231
cc_library(
@@ -60,4 +59,5 @@ cc_library(
6059
],
6160
}),
6261
includes = ["zlib/include/"],
62+
visibility = ["//visibility:public"],
6363
)

util/python/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
13
# This is a placeholder for python headers. Projects needing to use
24
# fast cpp protos in protobuf's python interface should build with
35
# --define=use_fast_cpp_protos=true, and in addition, provide

0 commit comments

Comments
 (0)