2021-11-04 22:57:29 +00:00
|
|
|
"""
|
|
|
|
Generates package naming variables for use with rules_pkg.
|
|
|
|
"""
|
|
|
|
|
|
|
|
load("@rules_pkg//:providers.bzl", "PackageVariablesInfo")
|
|
|
|
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
|
|
|
|
load(":protobuf_version.bzl", "PROTOBUF_VERSION")
|
|
|
|
|
|
|
|
def _package_naming_impl(ctx):
|
|
|
|
values = {}
|
|
|
|
values["version"] = PROTOBUF_VERSION
|
|
|
|
|
|
|
|
# infer from the current cpp toolchain.
|
|
|
|
toolchain = find_cpp_toolchain(ctx)
|
2021-11-24 21:27:54 +00:00
|
|
|
cpu = toolchain.cpu
|
|
|
|
system_name = toolchain.target_gnu_system_name
|
|
|
|
|
|
|
|
# rename cpus to match what we want artifacts to be
|
|
|
|
if cpu == "systemz":
|
|
|
|
cpu = "s390_64"
|
|
|
|
elif cpu == "aarch64":
|
|
|
|
cpu = "aarch_64"
|
|
|
|
|
|
|
|
# use the system name to determine the os and then create platform names
|
|
|
|
if "apple" in system_name:
|
|
|
|
values["platform"] = "osx-" + cpu
|
|
|
|
elif "linux" in system_name:
|
|
|
|
values["platform"] = "linux-" + cpu
|
|
|
|
elif "mingw" in system_name:
|
2022-02-24 00:45:56 +00:00
|
|
|
if cpu == "x86_64":
|
2021-11-24 21:27:54 +00:00
|
|
|
values["platform"] = "win64"
|
|
|
|
else:
|
|
|
|
values["platform"] = "win32"
|
|
|
|
else:
|
2021-11-29 23:54:09 +00:00
|
|
|
values["platform"] = "unknown"
|
2021-11-24 21:27:54 +00:00
|
|
|
|
2021-11-04 22:57:29 +00:00
|
|
|
return PackageVariablesInfo(values = values)
|
|
|
|
|
|
|
|
|
|
|
|
package_naming = rule(
|
|
|
|
implementation = _package_naming_impl,
|
|
|
|
attrs = {
|
|
|
|
# Necessary data dependency for find_cpp_toolchain.
|
|
|
|
"_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")),
|
|
|
|
},
|
|
|
|
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
|
|
|
|
incompatible_use_toolchain_transition = True,
|
|
|
|
)
|