Skip to content

Commit 0d9917d

Browse files
Replace manyLinux compliance check action in TF wheel build rule with macros for Linux platforms.
Example of usage: ``` load( "@tsl//:third_party/py/py_manylinux_compliance_test.bzl", "verify_manylinux_compliance_test", ) verify_manylinux_compliance_test( name = "manylinux_compliance_test", aarch64_compliance_tag = "manylinux_2_17_aarch64", test_tags = [ "mac_excluded", "windows_excluded", ], wheel = ":wheel", x86_64_compliance_tag = "manylinux_2_17_x86_64", ) ``` The test target is executed only when specified in Bazel command line. The test passes if `auditwheel show` results have the compliance tag value (depends on the machine type). The test fails otherwise and prints the `auditwheel show` results. PiperOrigin-RevId: 708024471
1 parent 4fc84bd commit 0d9917d

File tree

5 files changed

+61
-51
lines changed

5 files changed

+61
-51
lines changed

opensource_only.files

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,18 @@ third_party/nvtx/LICENSE:
9999
third_party/protobuf/BUILD:
100100
third_party/py/BUILD.tpl:
101101
third_party/py/BUILD:
102+
third_party/py/manylinux_compliance_test.py:
102103
third_party/py/ml_dtypes/BUILD:
103104
third_party/py/ml_dtypes/LICENSE:
104105
third_party/py/numpy/BUILD:
105106
third_party/py/py_import.bzl:
107+
third_party/py/py_manylinux_compliance_test.bzl:
106108
third_party/py/python_configure.bzl:
107109
third_party/py/python_init_pip.bzl:
108110
third_party/py/python_init_repositories.bzl:
109111
third_party/py/python_init_rules.bzl:
110112
third_party/py/python_init_toolchains.bzl:
111113
third_party/py/python_repo.bzl:
112-
third_party/py/verify_manylinux_compliance.py:
113114
third_party/pybind11.BUILD:
114115
third_party/pybind11_bazel/BUILD:
115116
third_party/python_runtime/BUILD:

third_party/py/BUILD

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,8 @@ config_setting(
5353
},
5454
)
5555

56-
# Flag indicating if the target requires manylinux compliance verification.
57-
bool_flag(
58-
name = "verify_manylinux",
59-
# TODO(ybaturina): Enable the flag by default when hermetic C++ toolchain is ready.
60-
build_setting_default = False,
56+
filegroup(
57+
name = "manylinux_compliance_test",
58+
srcs = ["manylinux_compliance_test.py"],
6159
visibility = ["//visibility:public"],
6260
)
63-
64-
py_binary(
65-
name = "verify_manylinux_compliance",
66-
srcs = [
67-
"verify_manylinux_compliance.py",
68-
],
69-
main = "verify_manylinux_compliance.py",
70-
visibility = ["//visibility:public"],
71-
deps = [
72-
"@pypi_auditwheel//:pkg",
73-
],
74-
)

third_party/py/verify_manylinux_compliance.py renamed to third_party/py/manylinux_compliance_test.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
1-
# Copyright 2024 The Tensorflow Authors.
1+
# Copyright 2024 The TensorFlow Authors. All Rights Reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
66
#
7-
# https://www.apache.org/licenses/LICENSE-2.0
7+
# http://www.apache.org/licenses/LICENSE-2.0
88
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under the License is distributed on an "AS IS" BASIS,
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
"""Tool to verify wheel manylinux compliance."""
14+
# ==============================================================================
1515

1616
import argparse
1717
import io
18+
import platform
1819
import re
1920
import sys
2021
from auditwheel import main_show
2122

2223

23-
def parse_args() -> argparse.Namespace:
24+
def parse_args():
2425
"""Arguments parser."""
2526
parser = argparse.ArgumentParser(
26-
description="Helper for auditwheel", fromfile_prefix_chars="@"
27+
description="Helper for manylinux compliance verification",
28+
fromfile_prefix_chars="@",
2729
)
2830
parser.add_argument(
29-
"--wheel_path", required=True, help="Path of the wheel, mandatory"
31+
"--wheel-path", required=True, help="Path of the wheel, mandatory"
3032
)
3133
parser.add_argument(
32-
"--compliance-tag", help="ManyLinux compliance tag", required=False
34+
"--aarch64-compliance-tag",
35+
required=True,
36+
help="ManyLinux compliance tag for aarch64",
3337
)
3438
parser.add_argument(
35-
"--auditwheel-show-log-path",
36-
help="Path to file with auditwheel show results, mandatory",
39+
"--x86_64-compliance-tag",
3740
required=True,
41+
help="ManyLinux compliance tag for x86_64",
3842
)
3943
return parser.parse_args()
4044

@@ -70,39 +74,37 @@ def get_auditwheel_output(wheel_path: str) -> None:
7074
def verify_manylinux_compliance(
7175
auditwheel_log: str,
7276
compliance_tag: str,
73-
auditwheel_show_log_path: str,
7477
) -> None:
7578
"""Verify manylinux compliance.
7679
7780
Args:
7881
auditwheel_log: "auditwheel show" execution results
7982
compliance_tag: manyLinux compliance tag
80-
auditwheel_show_log_path: path to file with auditwheel show results
8183
8284
Raises:
8385
RuntimeError: if the wheel is not manyLinux compliant.
8486
"""
85-
with open(auditwheel_show_log_path, "w") as auditwheel_show_log:
86-
auditwheel_show_log.write(auditwheel_log)
87-
if not compliance_tag:
88-
return
8987
regex = 'following platform tag: "{}"'.format(compliance_tag)
9088
if not re.search(regex, auditwheel_log):
9189
raise RuntimeError(
92-
(
93-
"The wheel is not compliant with tag {tag}."
94-
+ " If you want to disable this check, please provide"
95-
+ " `--@tsl//third_party/py:verify_manylinux=false`."
96-
+ "\n{result}"
97-
).format(tag=compliance_tag, result=auditwheel_log)
90+
("The wheel is not compliant with the tag {tag}.\n{result}").format(
91+
tag=compliance_tag, result=auditwheel_log
92+
)
9893
)
9994

10095

101-
if __name__ == "__main__":
102-
args = parse_args()
96+
def test_manylinux_compliance(args):
97+
machine_type = platform.uname().machine
98+
if machine_type == "x86_64":
99+
compliance_tag = args.x86_64_compliance_tag
100+
else:
101+
compliance_tag = args.aarch64_compliance_tag
103102
auditwheel_output = get_auditwheel_output(args.wheel_path)
104103
verify_manylinux_compliance(
105104
auditwheel_output,
106-
args.compliance_tag,
107-
args.auditwheel_show_log_path,
105+
compliance_tag,
108106
)
107+
108+
109+
if __name__ == "__main__":
110+
test_manylinux_compliance(parse_args())

third_party/py/py_import.bzl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
def _unpacked_wheel_impl(ctx):
44
output_dir = ctx.actions.declare_directory(ctx.label.name)
5-
wheel = None
6-
for w in ctx.files.wheel_rule_outputs:
7-
if w.basename.endswith(".whl"):
8-
wheel = w
9-
break
5+
wheel = ctx.file.wheel
106
script = """
117
{zipper} x {wheel} -d {output}
128
for wheel_dep in {wheel_deps}; do
@@ -22,7 +18,7 @@ def _unpacked_wheel_impl(ctx):
2218
]),
2319
)
2420
ctx.actions.run_shell(
25-
inputs = ctx.files.wheel_rule_outputs + ctx.files.wheel_deps,
21+
inputs = ctx.files.wheel + ctx.files.wheel_deps,
2622
command = script,
2723
outputs = [output_dir],
2824
tools = [ctx.executable.zipper],
@@ -35,7 +31,7 @@ def _unpacked_wheel_impl(ctx):
3531
_unpacked_wheel = rule(
3632
implementation = _unpacked_wheel_impl,
3733
attrs = {
38-
"wheel_rule_outputs": attr.label(mandatory = True, allow_files = True),
34+
"wheel": attr.label(mandatory = True, allow_single_file = True),
3935
"zipper": attr.label(
4036
default = Label("@bazel_tools//tools/zip:zipper"),
4137
cfg = "exec",
@@ -53,7 +49,7 @@ def py_import(
5349
unpacked_wheel_name = name + "_unpacked_wheel"
5450
_unpacked_wheel(
5551
name = unpacked_wheel_name,
56-
wheel_rule_outputs = wheel,
52+
wheel = wheel,
5753
wheel_deps = wheel_deps,
5854
)
5955
native.py_library(
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
""" Macros for manylinux compliance verification test. """
2+
3+
load("@rules_python//python:py_test.bzl", "py_test")
4+
5+
def verify_manylinux_compliance_test(
6+
name,
7+
wheel,
8+
aarch64_compliance_tag,
9+
x86_64_compliance_tag,
10+
test_tags = []):
11+
py_test(
12+
name = name,
13+
srcs = [Label("//third_party/py:manylinux_compliance_test")],
14+
data = [
15+
wheel,
16+
],
17+
deps = ["@pypi_auditwheel//:pkg"],
18+
args = [
19+
"--wheel-path=$(location {})".format(wheel),
20+
"--aarch64-compliance-tag={}".format(aarch64_compliance_tag),
21+
"--x86_64-compliance-tag={}".format(x86_64_compliance_tag),
22+
],
23+
main = "manylinux_compliance_test.py",
24+
tags = ["manual"] + test_tags,
25+
)

0 commit comments

Comments
 (0)