Skip to content

Commit 8137024

Browse files
ssjhvcopybara-github
authored andcommitted
Added Python toolchain setup in WORKSPACE.
TF moved Python toolchain setup from bzl scripts to the main WORKSPACE. However, those bzl scripts (which we use for C++ toolchain setup) expect the Python toolchain setup as done in TF WORKSPACE. PiperOrigin-RevId: 572960752 Change-Id: I4ee41e6c24a6be584efbeacf4f30ee4db3075b7d
1 parent 82c61e7 commit 8137024

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ sudo docker run -i --rm -v /tmp/tensorflow_compression:/tmp/tensorflow_compressi
269269
cd /tensorflow_compression &&
270270
python -m pip install -U pip setuptools wheel &&
271271
python -m pip install -r requirements.txt &&
272-
bazel run -c opt --copt=-mavx --crosstool_top=@ubuntu20.04-gcc9_manylinux2014-cuda11.2-cudnn8.1-tensorrt7.2_config_cuda//crosstool:toolchain :build_pip_pkg -- . /tmp/tensorflow_compression <custom-version>"
272+
bazel build -c opt --copt=-mavx --crosstool_top=@ubuntu20.04-gcc9_manylinux2014-cuda11.2-cudnn8.1-tensorrt7.2_config_cuda//crosstool:toolchain :build_pip_pkg &&
273+
pushd bazel-bin/build_pip_pkg.runfiles/tensorflow_compression &&
274+
python build_pip_pkg.py . /tmp/tensorflow_compression <custom-version> &&
275+
popd"
273276
```
274277

275278
For Darwin, the Docker image and specifying the toolchain is not necessary. We
@@ -281,7 +284,10 @@ git clone https://github.com/tensorflow/compression.git /tensorflow_compression
281284
cd /tensorflow_compression
282285
python -m pip install -U pip setuptools wheel
283286
python -m pip install -r requirements.txt
284-
bazel run -c opt --copt=-mavx --macos_minimum_os=10.14 :build_pip_pkg -- . /tmp/tensorflow_compression <custom-version>"
287+
bazel build -c opt --copt=-mavx --macos_minimum_os=10.14 :build_pip_pkg
288+
pushd bazel-bin/build_pip_pkg.runfiles/tensorflow_compression
289+
python build_pip_pkg.py . /tmp/tensorflow_compression <custom-version>"
290+
popd
285291
```
286292
287293
In both cases, the wheel file is created inside `/tmp/tensorflow_compression`.

WORKSPACE

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
workspace(name = "tensorflow_compression")
22

3-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
43
load("//:workspace.bzl", "tensorflow_compression_workspace")
54
tensorflow_compression_workspace()
65

6+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
7+
8+
# `bazel_skylib` and `rules_python` versions should match the ones used in
9+
# `org_tensorflow`.
10+
http_archive(
11+
name = "bazel_skylib",
12+
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
13+
urls = [
14+
"https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
15+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
16+
],
17+
)
18+
19+
http_archive(
20+
name = "rules_python",
21+
sha256 = "9d04041ac92a0985e344235f5d946f71ac543f1b1565f2cdbc9a2aaee8adf55b",
22+
strip_prefix = "rules_python-0.26.0",
23+
url = "https://github.com/bazelbuild/rules_python/releases/download/0.26.0/rules_python-0.26.0.tar.gz",
24+
)
25+
726
http_archive(
827
name = "org_tensorflow",
928
sha256 = "ce357fd0728f0d1b0831d1653f475591662ec5bca736a94ff789e6b1944df19f",
@@ -14,6 +33,29 @@ http_archive(
1433
)
1534

1635
# Copied from `@org_tensorflow//:WORKSPACE`.
36+
load(
37+
"@rules_python//python:repositories.bzl",
38+
"py_repositories",
39+
"python_register_toolchains",
40+
)
41+
py_repositories()
42+
43+
load(
44+
"@org_tensorflow//tensorflow/tools/toolchains/python:python_repo.bzl",
45+
"python_repository",
46+
)
47+
python_repository(name = "python_version_repo")
48+
load("@python_version_repo//:py_version.bzl", "HERMETIC_PYTHON_VERSION")
49+
50+
# TF workspace scripts below requires `@python` toolchains repo.
51+
# Toolchain setup here is to please the TF workspace scripts,
52+
# and we do not use this Python version to build pip packages.
53+
python_register_toolchains(
54+
name = "python",
55+
ignore_root_user_error = True,
56+
python_version = HERMETIC_PYTHON_VERSION,
57+
)
58+
1759
load("@org_tensorflow//tensorflow:workspace3.bzl", "tf_workspace3")
1860
tf_workspace3()
1961

0 commit comments

Comments
 (0)