aboutsummaryrefslogtreecommitdiff
path: root/BUILD.bazel
blob: c3f9f69ab2d36c6a7b0a5ee3d0b5ab70d1e12d19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Copyright (C) 2022 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This BUILD.bazel file is a handcrafted addition to the one generated
# from Android.bp. The BUILD file in this folder is unused, it's from
# the protocol-buffers github repo.
load("//build/bazel/rules/python:py_proto.bzl", "py_proto_library")
load("//build/bazel/rules/java:proto.bzl", "java_proto_sources_gen")

py_library(
    name = "libprotobuf-python",
    srcs = glob(["python/google/**/*.py"]) + [":libprotobuf-python-copy-protos"],
    imports = ["python"],
    deps = ["//external/python/six:py-six"],
)

proto_filenames = [
    "google/protobuf/descriptor",
    "google/protobuf/any",
    "google/protobuf/source_context",
    "google/protobuf/type",
    "google/protobuf/compiler/plugin",
    "google/protobuf/api",
    "google/protobuf/duration",
    "google/protobuf/empty",
    "google/protobuf/field_mask",
    "google/protobuf/struct",
    "google/protobuf/timestamp",
    "google/protobuf/wrappers",
]

# Copy protobufs to the python/ folder. They must be in the same folder
# as other source files in the same package, adding more folders to
# the PYTHONPATH won't help because the interpreter stops once it sees
# the first folder matching the package name of an import.
genrule(
    name = "libprotobuf-python-copy-protos",
    srcs = [":libprotobuf-python-proto-gen"],
    outs = ["python/" + f + "_pb2.py" for f in proto_filenames],
    cmd = "cp -rf $(BINDIR)/external/protobuf/libprotobuf-python-proto-gen_proto_gen/google $(BINDIR)/external/protobuf/python/"
)

py_proto_library(
    name = "libprotobuf-python-proto-gen",
    deps = [":libprotobuf-proto"],
)

proto_library(
    name = "libprotobuf-proto",
    srcs = ["src/" + f + ".proto" for f in proto_filenames],
    strip_import_prefix = "src",
)

java_library(
    name = "libprotobuf-java-full",
    java_version = "1.7",
    srcs = [
        ":libprotobuf-internal-java-full-srcs",
        ":libprotobuf-java-full_proto_gen",
    ],
    target_compatible_with = select({
        "//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
)

java_library(
    name = "libprotobuf-java-full-neverlink",
    exports = [":libprotobuf-java-full"],
    java_version = "1.7",
    neverlink = True,
    target_compatible_with = select({
        "//build/bazel_common_rules/platforms/os:android": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
)

java_proto_sources_gen(
    name = "libprotobuf-java-full_proto_gen",
    deps = [":libprotobuf-internal-protos_proto"],
)