Use a proper bazel toolchain for Python

This patch removes the old `--python_top` approach and instead turns
out Python toolchain into a proper Bazel toolchain. It's now used in
toolchain resolution.

    $ bazel run aos:flatbuffers_static --toolchain_resolution_debug
    WARNING: Option 'ui' is deprecated
    INFO: Invocation ID: 5ed4f6d5-e72d-4705-a853-c9a91264d74c
    INFO: Build option --toolchain_resolution_debug has changed, discarding analysis cache.
    INFO: ToolchainResolution:   Type @bazel_tools//tools/cpp:toolchain_type: target platform //tools/platforms:linux_x86: execution //tools/platforms:linux_x86: Selected toolchain //tools/cpp:cc-compiler-k8
    INFO: ToolchainResolution:   Type @bazel_tools//tools/python:toolchain_type: target platform //tools/platforms:linux_x86: execution //tools/platforms:linux_x86: Selected toolchain //tools/python:py_runtime
    INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //tools/platforms:linux_x86: Rejected toolchain //tools/cpp:cc-compiler-armhf-debian; mismatching values: raspberry_pi
    INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //tools/platforms:linux_x86: Rejected toolchain //tools/cpp:cc-compiler-roborio; mismatching values: roborio
    INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //tools/platforms:linux_x86: Rejected toolchain //tools/cpp:cc-compiler-cortex-m4f; mismatching values: none, cortex_m4f
    INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //tools/platforms:linux_x86: Rejected toolchain @local_config_cc//:cc-compiler-armeabi-v7a; mismatching values: arm, android
    INFO: ToolchainResolution: Target platform //tools/platforms:linux_x86: Selected execution platform //tools/platforms:linux_x86, type @bazel_tools//tools/python:toolchain_type -> toolchain //tools/python:py_runtime, type @bazel_tools//tools/cpp:toolchain_type -> toolchain //tools/cpp:cc-compiler-k8
    INFO: ToolchainResolution: Target platform //tools/platforms:linux_x86: Selected execution platform //tools/platforms:linux_x86,
    INFO: ToolchainResolution: Target platform //tools/platforms:linux_x86: Selected execution platform //tools/platforms:linux_x86,
    INFO: ToolchainResolution:   Type @bazel_tools//tools/cpp:toolchain_type: target platform //tools/platforms:linux_x86: execution //tools/platforms:linux_x86: Selected toolchain //tools/cpp:cc-compiler-k8
    INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //tools/platforms:linux_x86: Rejected toolchain //tools/cpp:cc-compiler-armhf-debian; mismatching values: raspberry_pi
    INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //tools/platforms:linux_x86: Rejected toolchain //tools/cpp:cc-compiler-roborio; mismatching values: roborio
    INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //tools/platforms:linux_x86: Rejected toolchain //tools/cpp:cc-compiler-cortex-m4f; mismatching values: none, cortex_m4f
    INFO: ToolchainResolution:     Type @bazel_tools//tools/cpp:toolchain_type: target platform //tools/platforms:linux_x86: Rejected toolchain @local_config_cc//:cc-compiler-armeabi-v7a; mismatching values: arm, android
    INFO: ToolchainResolution: Target platform //tools/platforms:linux_x86: Selected execution platform //tools/platforms:linux_x86, type @bazel_tools//tools/cpp:toolchain_type -> toolchain //tools/cpp:cc-compiler-k8
    INFO: ToolchainResolution: Target platform //tools/platforms:linux_x86: Selected execution platform //tools/platforms:linux_x86,
    INFO: Analyzed target //aos:flatbuffers_static (0 packages loaded, 45236 targets configured).
    INFO: Found 1 target...
    INFO: Writing explanation of rebuilds to '/tmp/bazel_explain.log'
    Target //aos:flatbuffers_static up-to-date:
      bazel-bin/aos/flatbuffers_static
    INFO: Elapsed time: 2.740s, Critical Path: 0.07s
    INFO: 1 process: 1 internal.
    INFO: Build completed successfully, 1 total action
    INFO: Build completed successfully, 1 total action

Notice the selection of `//tools/python:py_runtime`.

Change-Id: I5adfae4cd11e73b5527a2fc98cef0de6a92464ab
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
diff --git a/tools/python/BUILD b/tools/python/BUILD
index 2181b31..32093d3 100644
--- a/tools/python/BUILD
+++ b/tools/python/BUILD
@@ -1,9 +1,31 @@
+load("@rules_python//python:defs.bzl", "py_runtime_pair")
+
 py_runtime(
-    name = "runtime",
+    name = "python3_runtime",
     files = [
         "runtime_binary.sh",
         "@python_repo//:all_files",
     ],
     interpreter = "runtime_binary.sh",
-    visibility = ["//visibility:public"],
+    python_version = "PY3",
+)
+
+py_runtime_pair(
+    name = "py_runtime",
+    py2_runtime = None,
+    py3_runtime = ":python3_runtime",
+)
+
+toolchain(
+    name = "python_toolchain",
+    target_compatible_with = [
+        "@platforms//cpu:x86_64",
+        "@platforms//os:linux",
+    ],
+    exec_compatible_with = [
+        "@platforms//cpu:x86_64",
+        "@platforms//os:linux",
+    ],
+    toolchain = ":py_runtime",
+    toolchain_type = "@rules_python//python:toolchain_type",
 )