Skip to content

Commit

Permalink
Move rules_pkg targets into //pkg, and add experimental C++ library r…
Browse files Browse the repository at this point in the history
…ules (#9823)

This change moves the `pkg_*` rules into the `//pkg` package, which cleans up the root package.

It also adds an experimental `cc_dist_library` rule, which is similar to Bazel's `cc_import` rule. The goal of `cc_dist_library` is to produce output libraries from several targets. For example, splitting `//:protobuf` into multiple targets means that `bazel-bin/libprotobuf.a` won't contain all of the objects. The `cc_dist_library` creates a single library from several different `cc_library` targets. This may be useful for future packaging targets.
  • Loading branch information
dlj-NaN authored Apr 20, 2022
1 parent f7b9886 commit 46710ca
Show file tree
Hide file tree
Showing 3 changed files with 366 additions and 78 deletions.
95 changes: 17 additions & 78 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library")
load("@rules_pkg//:pkg.bzl", "pkg_zip")
load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
load("@rules_python//python:defs.bzl", "py_library")
load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library")
load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test")
load(":protobuf_release.bzl", "package_naming")

licenses(["notice"])

exports_files(["LICENSE"])
Expand Down Expand Up @@ -353,6 +352,11 @@ filegroup(
visibility = ["//visibility:public"],
)

exports_files(
srcs = WELL_KNOWN_PROTOS,
visibility = ["//pkg:__pkg__"],
)

filegroup(
name = "lite_well_known_protos",
srcs = LITE_WELL_KNOWN_PROTOS,
Expand Down Expand Up @@ -519,70 +523,6 @@ cc_binary(
deps = [":protoc_lib"],
)


################################################################################
# Generates protoc release artifacts.
################################################################################

genrule(
name = "protoc_readme",
visibility = ["//visibility:private"],
cmd = """
echo "Protocol Buffers - Google's data interchange format
Copyright 2008 Google Inc.
https://developers.google.com/protocol-buffers/
This package contains a precompiled binary version of the protocol buffer
compiler (protoc). This binary is intended for users who want to use Protocol
Buffers in languages other than C++ but do not want to compile protoc
themselves. To install, simply place this binary somewhere in your PATH.
If you intend to use the included well known types then don't forget to
copy the contents of the 'include' directory somewhere as well, for example
into '/usr/local/include/'.
Please refer to our official github site for more installation instructions:
https://github.com/protocolbuffers/protobuf" > $@
""",
outs = ["readme.txt"],
)

# plugin.proto is excluded from this list because it belongs in a nested folder (protobuf/compiler/plugin.proto)
pkg_files(
name = "wkt_protos_files",
srcs = [value[0] for value in WELL_KNOWN_PROTO_MAP.values() if not value[0].endswith("plugin.proto")],
visibility = ["//visibility:private"],
prefix = "include/google/protobuf",
)

pkg_files(
name = "compiler_plugin_protos_files",
srcs = ["src/google/protobuf/compiler/plugin.proto"],
visibility = ["//visibility:private"],
prefix = "include/google/protobuf/compiler",
)

pkg_files(
name = "protoc_files",
srcs = [":protoc"],
attributes = pkg_attributes(mode = "0555"),
visibility = ["//visibility:private"],
prefix = "bin/",
)

package_naming(
name = "protoc_pkg_naming",
)

pkg_zip(
name = "protoc_release",
package_file_name = "protoc-{version}-{platform}.zip",
package_variables = ":protoc_pkg_naming",
srcs = [
":protoc_files",
":wkt_protos_files",
":compiler_plugin_protos_files",
"readme.txt",
],
)

################################################################################
# Tests
################################################################################
Expand Down Expand Up @@ -905,10 +845,10 @@ internal_gen_kt_protos(

internal_gen_kt_protos(
name = "gen_well_known_protos_kotlinlite",
lite = True,
visibility = [
"//java:__subpackages__",
],
lite = True,
deps = [proto + "_proto" for proto in LITE_WELL_KNOWN_PROTO_MAP.keys()],
)

Expand Down Expand Up @@ -1340,17 +1280,16 @@ cc_binary(
# ],
# )


java_proto_library(
name = "java_test_protos",
deps = [":generic_test_protos"],
visibility = ["//java:__subpackages__"],
deps = [":generic_test_protos"],
)

java_lite_proto_library(
name = "java_lite_test_protos",
deps = [":generic_test_protos"],
visibility = ["//java:__subpackages__"],
deps = [":generic_test_protos"],
)

java_proto_library(
Expand Down Expand Up @@ -1452,57 +1391,57 @@ filegroup(
proto_library(
name = "kt_unittest_lite",
srcs = [
"src/google/protobuf/unittest_lite.proto",
"src/google/protobuf/map_lite_unittest.proto",
"src/google/protobuf/unittest_import_lite.proto",
"src/google/protobuf/unittest_import_public_lite.proto",
"src/google/protobuf/map_lite_unittest.proto",
"src/google/protobuf/unittest_lite.proto",
],
strip_import_prefix = "src",
)

internal_gen_kt_protos(
name = "gen_kotlin_unittest_lite",
deps = [":kt_unittest_lite"],
lite = True,
visibility = ["//java:__subpackages__"],
deps = [":kt_unittest_lite"],
)

proto_library(
name = "kt_unittest",
srcs = [
"src/google/protobuf/map_proto2_unittest.proto",
"src/google/protobuf/unittest.proto",
"src/google/protobuf/unittest_import.proto",
"src/google/protobuf/unittest_import_public.proto",
"src/google/protobuf/map_proto2_unittest.proto",
],
strip_import_prefix = "src",
)

internal_gen_kt_protos(
name = "gen_kotlin_unittest",
deps = [":kt_unittest"],
visibility = ["//java:__subpackages__"],
deps = [":kt_unittest"],
)

proto_library(
name = "kt_proto3_unittest",
srcs = [
"src/google/protobuf/unittest_proto3.proto",
"src/google/protobuf/unittest_import.proto",
"src/google/protobuf/unittest_import_public.proto",
"src/google/protobuf/unittest_proto3.proto",
],
strip_import_prefix = "src",
)

internal_gen_kt_protos(
name = "gen_kotlin_proto3_unittest_lite",
deps = [":kt_proto3_unittest"],
lite = True,
visibility = ["//java:__subpackages__"],
deps = [":kt_proto3_unittest"],
)

internal_gen_kt_protos(
name = "gen_kotlin_proto3_unittest",
deps = [":kt_proto3_unittest"],
visibility = ["//java:__subpackages__"],
deps = [":kt_proto3_unittest"],
)
117 changes: 117 additions & 0 deletions pkg/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
load("@rules_pkg//:pkg.bzl", "pkg_zip")
load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files")
load("//:protobuf_release.bzl", "package_naming")
load(":cc_dist_library.bzl", "cc_dist_library")

pkg_files(
name = "wkt_protos_files",
srcs = [
"//:any_proto",
"//:api_proto",
"//:duration_proto",
"//:empty_proto",
"//:field_mask_proto",
"//:source_context_proto",
"//:struct_proto",
"//:timestamp_proto",
"//:type_proto",
"//:wrappers_proto",
],
prefix = "include/google/protobuf",
visibility = ["//visibility:private"],
)

pkg_files(
name = "descriptor_protos_files",
srcs = [
"//:descriptor_proto",
],
prefix = "include/google/protobuf",
visibility = ["//visibility:private"],
)

pkg_files(
name = "compiler_plugin_protos_files",
srcs = ["//:compiler_plugin_proto"],
prefix = "include/google/protobuf/compiler",
visibility = ["//visibility:private"],
)

################################################################################
# Generates protoc release artifacts.
################################################################################

genrule(
name = "protoc_readme",
outs = ["readme.txt"],
cmd = """
echo "Protocol Buffers - Google's data interchange format
Copyright 2008 Google Inc.
https://developers.google.com/protocol-buffers/
This package contains a precompiled binary version of the protocol buffer
compiler (protoc). This binary is intended for users who want to use Protocol
Buffers in languages other than C++ but do not want to compile protoc
themselves. To install, simply place this binary somewhere in your PATH.
If you intend to use the included well known types then don't forget to
copy the contents of the 'include' directory somewhere as well, for example
into '/usr/local/include/'.
Please refer to our official github site for more installation instructions:
https://github.com/protocolbuffers/protobuf" > $@
""",
visibility = ["//visibility:private"],
)

pkg_files(
name = "protoc_files",
srcs = ["//:protoc"],
attributes = pkg_attributes(mode = "0555"),
prefix = "bin/",
visibility = ["//visibility:private"],
)

package_naming(
name = "protoc_pkg_naming",
)

pkg_zip(
name = "protoc_release",
srcs = [
":compiler_plugin_protos_files",
":descriptor_protos_files",
":protoc_files",
":protoc_readme",
":wkt_protos_files",
],
package_file_name = "protoc-{version}-{platform}.zip",
package_variables = ":protoc_pkg_naming",
)

################################################################################
# Protobuf runtime libraries.
################################################################################

cc_dist_library(
name = "protobuf_lite",
linkopts = select({
"//:msvc": [],
"//conditions:default": ["-lpthread"],
}),
deps = [
"//:protobuf_lite",
],
)

cc_dist_library(
name = "protobuf",
linkopts = select({
"//:msvc": [],
"//conditions:default": [
"-lz",
"-lpthread",
],
}),
deps = [
"//:protobuf",
"//:protobuf_lite",
],
)
Loading

0 comments on commit 46710ca

Please sign in to comment.