STT-tensorflow/third_party/remote_config/remote_platform_configure.bzl
Koan-Sin Tan 369e2d8f5d make bazel build work on aarch64/arm linux
make
```
bazel build //tensorflow/tools/pip_package:build_pip_package
````
work again on aarch64 (e.g., EdgeTPU Dev board and Jetson boards)
and arm (e.g, Raspberry Pi 3/4 boards) Linux platforms

without this patch, I saw

```
...
ERROR: While resolving toolchains for target //tensorflow:libtensorflow_framework.so.2.1.0: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
```
2020-05-06 12:18:31 +00:00

50 lines
1.6 KiB
Python

"""Repository rule to create a platform for a docker image to be used with RBE."""
def _remote_platform_configure_impl(repository_ctx):
platform = repository_ctx.attr.platform
if platform == "local":
os = repository_ctx.os.name.lower()
if os.startswith("windows"):
platform = "windows"
elif os.startswith("mac os"):
platform = "osx"
else:
platform = "linux"
cpu = "x86_64"
machine_type = repository_ctx.execute(["bash", "-c", "echo $MACHTYPE"]).stdout
if (machine_type.startswith("ppc") or
machine_type.startswith("powerpc")):
cpu = "ppc"
elif machine_type.startswith("s390x"):
cpu = "s390x"
elif machine_type.startswith("aarch64"):
cpu = "aarch64"
elif machine_type.startswith("arm"):
cpu = "arm"
exec_properties = repository_ctx.attr.platform_exec_properties
serialized_exec_properties = "{"
for k, v in exec_properties.items():
serialized_exec_properties += "\"%s\" : \"%s\"," % (k, v)
serialized_exec_properties += "}"
repository_ctx.template(
"BUILD",
Label("@org_tensorflow//third_party/remote_config:BUILD.tpl"),
{
"%{platform}": platform,
"%{exec_properties}": serialized_exec_properties,
"%{cpu}": cpu,
},
)
remote_platform_configure = repository_rule(
implementation = _remote_platform_configure_impl,
attrs = {
"platform_exec_properties": attr.string_dict(mandatory = True),
"platform": attr.string(default = "linux", values = ["linux", "windows", "local"]),
},
)