Add python toolchains definition in python configuration
--python_path will be removed in future Bazel, we should switch to use python toolchain. But currently we want Bazel to always use the same python binary specified in configure.py regardless of what's specified in py_binary rule (PY2 or PY3). So we point both py2 and py3 runtime to the same PYTHON_BIN_PATH. PiperOrigin-RevId: 273032026
This commit is contained in:
parent
441d8667ac
commit
98ecdee8e6
@ -18,6 +18,8 @@ load("//tensorflow:workspace.bzl", "tf_repositories")
|
|||||||
# Please add all new TensorFlow dependencies in workspace.bzl.
|
# Please add all new TensorFlow dependencies in workspace.bzl.
|
||||||
tf_repositories()
|
tf_repositories()
|
||||||
|
|
||||||
|
register_toolchains("@local_config_python//:py_toolchain")
|
||||||
|
|
||||||
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
|
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
|
||||||
|
|
||||||
closure_repositories()
|
closure_repositories()
|
||||||
|
28
third_party/py/BUILD.tpl
vendored
28
third_party/py/BUILD.tpl
vendored
@ -2,6 +2,34 @@ licenses(["restricted"])
|
|||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
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 = "%{PYTHON_BIN_PATH}",
|
||||||
|
python_version = "PY2",
|
||||||
|
)
|
||||||
|
|
||||||
|
py_runtime(
|
||||||
|
name = "py3_runtime",
|
||||||
|
interpreter_path = "%{PYTHON_BIN_PATH}",
|
||||||
|
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
|
# 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
|
# See https://docs.python.org/3/extending/windows.html
|
||||||
cc_import(
|
cc_import(
|
||||||
|
1
third_party/py/python_configure.bzl
vendored
1
third_party/py/python_configure.bzl
vendored
@ -323,6 +323,7 @@ def _create_local_python_repository(repository_ctx):
|
|||||||
"numpy_include",
|
"numpy_include",
|
||||||
)
|
)
|
||||||
_tpl(repository_ctx, "BUILD", {
|
_tpl(repository_ctx, "BUILD", {
|
||||||
|
"%{PYTHON_BIN_PATH}": python_bin,
|
||||||
"%{PYTHON_INCLUDE_GENRULE}": python_include_rule,
|
"%{PYTHON_INCLUDE_GENRULE}": python_include_rule,
|
||||||
"%{PYTHON_IMPORT_LIB_GENRULE}": python_import_lib_genrule,
|
"%{PYTHON_IMPORT_LIB_GENRULE}": python_import_lib_genrule,
|
||||||
"%{NUMPY_INCLUDE_GENRULE}": numpy_include_rule,
|
"%{NUMPY_INCLUDE_GENRULE}": numpy_include_rule,
|
||||||
|
@ -2,6 +2,34 @@ licenses(["restricted"])
|
|||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
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
|
# 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
|
# See https://docs.python.org/3/extending/windows.html
|
||||||
cc_import(
|
cc_import(
|
||||||
|
@ -2,6 +2,34 @@ licenses(["restricted"])
|
|||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
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/python3",
|
||||||
|
python_version = "PY2",
|
||||||
|
)
|
||||||
|
|
||||||
|
py_runtime(
|
||||||
|
name = "py3_runtime",
|
||||||
|
interpreter_path = "/usr/bin/python3",
|
||||||
|
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
|
# 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
|
# See https://docs.python.org/3/extending/windows.html
|
||||||
cc_import(
|
cc_import(
|
||||||
|
@ -2,6 +2,34 @@ licenses(["restricted"])
|
|||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
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 = "C:/Python36/python.exe",
|
||||||
|
python_version = "PY2",
|
||||||
|
)
|
||||||
|
|
||||||
|
py_runtime(
|
||||||
|
name = "py3_runtime",
|
||||||
|
interpreter_path = "C:/Python36/python.exe",
|
||||||
|
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
|
# 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
|
# See https://docs.python.org/3/extending/windows.html
|
||||||
cc_import(
|
cc_import(
|
||||||
|
@ -2,6 +2,34 @@ licenses(["restricted"])
|
|||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
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 = "C:/Python37/python.exe",
|
||||||
|
python_version = "PY2",
|
||||||
|
)
|
||||||
|
|
||||||
|
py_runtime(
|
||||||
|
name = "py3_runtime",
|
||||||
|
interpreter_path = "C:/Python37/python.exe",
|
||||||
|
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
|
# 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
|
# See https://docs.python.org/3/extending/windows.html
|
||||||
cc_import(
|
cc_import(
|
||||||
|
Loading…
Reference in New Issue
Block a user