protobuf/pkg/BUILD
David L. Jones d76f8c868c
Add source distribution packaging rules (#9835)
This change adds `rules_pkg`-based targets that will produce source distribution archives, similar to `make dist`.

These rules produce nearly the same outputs as `make dist`. However, there are some differences and caveats:

1. The outputs do not contain vendored googletest sources.
2. You have to run `autogen.sh` before `blaze build pkg:all`. This produces several autotools-related files directly into the source tree.
3. The output .zip files do not have a directory prefix like `protobuf-3.20.1-rc-1` (this will be addressed after [Substitute package variables in `pkg_zip#package_dir`. bazelbuild/rules_pkg#577](https://github.com/bazelbuild/rules_pkg/pull/577); the tar files do have this prefix, though.)
4. One file is missing from the archives, which is produced during the `make` build: benchmarks/gogo/cpp_no_group/cpp_benchmark.cc
5. In several places, I have explicitly excluded some files that are not in the autotools distribution outputs. I think most of those files should probably be included, but for now, I'm aiming for parity with `make dist`. These are marked with comments, so it should be easy to clean them up later.
2022-04-22 16:58:16 -07:00

365 lines
8.7 KiB
Python

load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
load(
"@rules_pkg//:mappings.bzl",
"pkg_attributes",
"pkg_filegroup",
"pkg_files",
)
load("//:protobuf_release.bzl", "package_naming")
load(":cc_dist_library.bzl", "cc_dist_library")
package_naming(
name = "protobuf_pkg_naming",
)
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"],
)
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 = ":protobuf_pkg_naming",
)
################################################################################
# Source distribution packaging
#
# TODO: these will eventually replace autotools for release artifact packaging.
################################################################################
pkg_filegroup(
name = "dist_common",
srcs = [
"//:common_dist_files",
"//:conformance_dist_files",
"//:cpp_dist_files", # to build protoc
"//benchmarks:all_dist_files",
"@com_google_protobuf_examples//:dist_files",
],
)
pkg_filegroup(
name = "cpp_srcs",
srcs = [
":dist_common",
"//:cpp_dist_files",
],
)
pkg_tar(
name = "dist_cpp_tar",
srcs = [":cpp_srcs"],
extension = "tar.gz",
package_dir = "protobuf-{version}",
package_file_name = "protobuf-cpp-{version}.tar.gz",
package_variables = ":protobuf_pkg_naming",
)
pkg_zip(
name = "dist_cpp_zip",
srcs = [":cpp_srcs"],
package_file_name = "protobuf-cpp-{version}.zip",
package_variables = ":protobuf_pkg_naming",
)
pkg_filegroup(
name = "csharp_srcs",
srcs = [
":dist_common",
"//:csharp_dist_files",
"//csharp:dist_files",
],
)
pkg_tar(
name = "dist_csharp_tar",
srcs = [":csharp_srcs"],
extension = "tar.gz",
package_dir = "protobuf-{version}",
package_file_name = "protobuf-csharp-{version}.tar.gz",
package_variables = ":protobuf_pkg_naming",
)
pkg_zip(
name = "dist_csharp_zip",
srcs = [":csharp_srcs"],
package_file_name = "protobuf-csharp-{version}.zip",
package_variables = ":protobuf_pkg_naming",
)
pkg_filegroup(
name = "java_srcs",
srcs = [
":dist_common",
"//java:all_dist_files",
],
)
pkg_tar(
name = "dist_java_tar",
srcs = [":java_srcs"],
extension = "tar.gz",
package_dir = "protobuf-{version}",
package_file_name = "protobuf-java-{version}.tar.gz",
package_variables = ":protobuf_pkg_naming",
)
pkg_zip(
name = "dist_java_zip",
srcs = [":java_srcs"],
package_file_name = "protobuf-java-{version}.zip",
package_variables = ":protobuf_pkg_naming",
)
pkg_filegroup(
name = "js_srcs",
srcs = [
":dist_common",
"//js:dist_files",
],
)
pkg_tar(
name = "dist_js_tar",
srcs = [":js_srcs"],
extension = "tar.gz",
package_dir = "protobuf-{version}",
package_file_name = "protobuf-js-{version}.tar.gz",
package_variables = ":protobuf_pkg_naming",
)
pkg_zip(
name = "dist_js_zip",
srcs = [":js_srcs"],
package_file_name = "protobuf-js-{version}.zip",
package_variables = ":protobuf_pkg_naming",
)
pkg_filegroup(
name = "objectivec_srcs",
srcs = [
":dist_common",
"//:objectivec_dist_files",
"//objectivec:dist_files",
],
)
pkg_tar(
name = "dist_objectivec_tar",
srcs = [":objectivec_srcs"],
extension = "tar.gz",
package_dir = "protobuf-{version}",
package_file_name = "protobuf-objectivec-{version}.tar.gz",
package_variables = ":protobuf_pkg_naming",
)
pkg_zip(
name = "dist_objectivec_zip",
srcs = [":objectivec_srcs"],
package_file_name = "protobuf-objectivec-{version}.zip",
package_variables = ":protobuf_pkg_naming",
)
pkg_filegroup(
name = "php_srcs",
srcs = [
":dist_common",
"//:php_dist_files",
"//php:dist_files",
],
)
pkg_tar(
name = "dist_php_tar",
srcs = [":php_srcs"],
extension = "tar.gz",
package_dir = "protobuf-{version}",
package_file_name = "protobuf-php-{version}.tar.gz",
package_variables = ":protobuf_pkg_naming",
)
pkg_zip(
name = "dist_php_zip",
srcs = [":php_srcs"],
package_file_name = "protobuf-php-{version}.zip",
package_variables = ":protobuf_pkg_naming",
)
pkg_filegroup(
name = "python_srcs",
srcs = [
":dist_common",
"//:python_dist_files",
],
)
pkg_tar(
name = "dist_python_tar",
srcs = [":python_srcs"],
extension = "tar.gz",
package_dir = "protobuf-{version}",
package_file_name = "protobuf-python-{version}.tar.gz",
package_variables = ":protobuf_pkg_naming",
)
pkg_zip(
name = "dist_python_zip",
srcs = [":python_srcs"],
package_file_name = "protobuf-python-{version}.zip",
package_variables = ":protobuf_pkg_naming",
)
pkg_filegroup(
name = "ruby_srcs",
srcs = [
":dist_common",
"//ruby:dist_files",
],
)
pkg_tar(
name = "dist_ruby_tar",
srcs = [":ruby_srcs"],
extension = "tar.gz",
package_dir = "protobuf-{version}",
package_file_name = "protobuf-ruby-{version}.tar.gz",
package_variables = ":protobuf_pkg_naming",
)
pkg_zip(
name = "dist_ruby_zip",
srcs = [":ruby_srcs"],
package_file_name = "protobuf-ruby-{version}.zip",
package_variables = ":protobuf_pkg_naming",
)
pkg_filegroup(
name = "dist_all",
srcs = [
":cpp_srcs",
":csharp_srcs",
":java_srcs",
":js_srcs",
":objectivec_srcs",
":php_srcs",
":python_srcs",
":ruby_srcs",
],
)
pkg_tar(
name = "dist_all_tar",
srcs = [":dist_all"],
extension = "tar.gz",
package_dir = "protobuf-{version}",
package_file_name = "protobuf-all-{version}.tar.gz",
package_variables = ":protobuf_pkg_naming",
)
pkg_zip(
name = "dist_all_zip",
srcs = [":dist_all"],
package_file_name = "protobuf-all-{version}.zip",
package_variables = ":protobuf_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",
],
)