protobuf_release.bzl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """
  2. Generates package naming variables for use with rules_pkg.
  3. """
  4. load("@rules_pkg//:providers.bzl", "PackageVariablesInfo")
  5. load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
  6. load(":protobuf_version.bzl", "PROTOBUF_VERSION")
  7. def _package_naming_impl(ctx):
  8. values = {}
  9. values["version"] = PROTOBUF_VERSION
  10. # infer from the current cpp toolchain.
  11. toolchain = find_cpp_toolchain(ctx)
  12. cpu = toolchain.cpu
  13. system_name = toolchain.target_gnu_system_name
  14. # rename cpus to match what we want artifacts to be
  15. if cpu == "systemz":
  16. cpu = "s390_64"
  17. elif cpu == "aarch64":
  18. cpu = "aarch_64"
  19. elif cpu == "ppc64":
  20. cpu = "ppcle_64"
  21. # use the system name to determine the os and then create platform names
  22. if "apple" in system_name:
  23. values["platform"] = "osx-" + cpu
  24. elif "linux" in system_name:
  25. values["platform"] = "linux-" + cpu
  26. elif "mingw" in system_name:
  27. if cpu == "x86_64":
  28. values["platform"] = "win64"
  29. else:
  30. values["platform"] = "win32"
  31. else:
  32. values["platform"] = "unknown"
  33. return PackageVariablesInfo(values = values)
  34. package_naming = rule(
  35. implementation = _package_naming_impl,
  36. attrs = {
  37. # Necessary data dependency for find_cpp_toolchain.
  38. "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")),
  39. },
  40. toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
  41. incompatible_use_toolchain_transition = True,
  42. )