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