diff --git a/third_party/toolchains/preconfig/ubuntu16.04/py3_opt/BUILD b/third_party/toolchains/preconfig/ubuntu16.04/py3_opt/BUILD index 689465253b8..6a5e02d7b2a 100755 --- a/third_party/toolchains/preconfig/ubuntu16.04/py3_opt/BUILD +++ b/third_party/toolchains/preconfig/ubuntu16.04/py3_opt/BUILD @@ -2,6 +2,34 @@ licenses(["restricted"]) package(default_visibility = ["//visibility:public"]) +# Point both runtimes to the same python binary to ensure we always +# use the python binary specified by ./configure.py script. +load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair") + +py_runtime( + name = "py2_runtime", + interpreter_path = "/usr/bin/python2", + python_version = "PY2", +) + +py_runtime( + name = "py3_runtime", + interpreter_path = "/usr/bin/python2", + python_version = "PY3", +) + +py_runtime_pair( + name = "py_runtime_pair", + py2_runtime = ":py2_runtime", + py3_runtime = ":py3_runtime", +) + +toolchain( + name = "py_toolchain", + toolchain = ":py_runtime_pair", + toolchain_type = "@bazel_tools//tools/python:toolchain_type", +) + # To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib # See https://docs.python.org/3/extending/windows.html cc_import(