Skip to content

Commit

Permalink
Add manylinux compliance check macros for Linux platforms.
Browse files Browse the repository at this point in the history
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: 705993270
  • Loading branch information
Google-ML-Automation committed Dec 17, 2024
1 parent d80d15e commit 47daf5a
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 9 deletions.
6 changes: 6 additions & 0 deletions third_party/py/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ py_binary(
"@pypi_auditwheel//:pkg",
],
)

filegroup(
name = "manylinux_compliance_test",
srcs = ["manylinux_compliance_test.py"],
visibility = ["//visibility:public"],
)
2 changes: 2 additions & 0 deletions third_party/tsl/opensource_only.files
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ third_party/nvtx/LICENSE:
third_party/protobuf/BUILD:
third_party/py/BUILD.tpl:
third_party/py/BUILD:
third_party/py/manylinux_compliance_test.py:
third_party/py/ml_dtypes/BUILD:
third_party/py/ml_dtypes/LICENSE:
third_party/py/numpy/BUILD:
third_party/py/py_import.bzl:
third_party/py/py_manylinux_compliance_test.bzl:
third_party/py/python_configure.bzl:
third_party/py/python_init_pip.bzl:
third_party/py/python_init_repositories.bzl:
Expand Down
6 changes: 6 additions & 0 deletions third_party/tsl/third_party/py/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ py_binary(
"@pypi_auditwheel//:pkg",
],
)

filegroup(
name = "manylinux_compliance_test",
srcs = ["manylinux_compliance_test.py"],
visibility = ["//visibility:public"],
)
68 changes: 68 additions & 0 deletions third_party/tsl/third_party/py/manylinux_compliance_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2024 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

import argparse
import platform
import subprocess
import sys


def parse_args():
"""Arguments parser."""
parser = argparse.ArgumentParser(
description="Helper for auditwheel", fromfile_prefix_chars="@"
)
parser.add_argument(
"--verify-manylinux-compliance-script",
required=True,
help="Path of the verify manylinux compliance script, mandatory",
)
parser.add_argument(
"--wheel-path", required=True, help="Path of the wheel, mandatory"
)
parser.add_argument(
"--aarch64-compliance-tag",
required=True,
help="ManyLinux compliance tag for aarch64",
)
parser.add_argument(
"--x86_64-compliance-tag",
required=True,
help="ManyLinux compliance tag for x86_64",
)
return parser.parse_args()


def test_manylinux_compliance(comliance_check_args):
machine_type = platform.uname().machine
if machine_type == "x86_64":
compliance_tag = compliance_check_args.x86_64_compliance_tag
else:
compliance_tag = compliance_check_args.aarch64_compliance_tag
subprocess.run(
[
sys.executable,
comliance_check_args.verify_manylinux_compliance_script,
"--wheel-path={}".format(comliance_check_args.wheel_path),
"--compliance-tag={}".format(compliance_tag),
"--auditwheel-show-log-path=auditwheel_show.log",
],
check=True,
)


if __name__ == "__main__":
compliance_check_args = parse_args()
test_manylinux_compliance(compliance_check_args)
12 changes: 4 additions & 8 deletions third_party/tsl/third_party/py/py_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

def _unpacked_wheel_impl(ctx):
output_dir = ctx.actions.declare_directory(ctx.label.name)
wheel = None
for w in ctx.files.wheel_rule_outputs:
if w.basename.endswith(".whl"):
wheel = w
break
wheel = ctx.file.wheel
script = """
{zipper} x {wheel} -d {output}
for wheel_dep in {wheel_deps}; do
Expand All @@ -22,7 +18,7 @@ def _unpacked_wheel_impl(ctx):
]),
)
ctx.actions.run_shell(
inputs = ctx.files.wheel_rule_outputs + ctx.files.wheel_deps,
inputs = ctx.files.wheel + ctx.files.wheel_deps,
command = script,
outputs = [output_dir],
tools = [ctx.executable.zipper],
Expand All @@ -35,7 +31,7 @@ def _unpacked_wheel_impl(ctx):
_unpacked_wheel = rule(
implementation = _unpacked_wheel_impl,
attrs = {
"wheel_rule_outputs": attr.label(mandatory = True, allow_files = True),
"wheel": attr.label(mandatory = True, allow_single_file = True),
"zipper": attr.label(
default = Label("@bazel_tools//tools/zip:zipper"),
cfg = "exec",
Expand All @@ -53,7 +49,7 @@ def py_import(
unpacked_wheel_name = name + "_unpacked_wheel"
_unpacked_wheel(
name = unpacked_wheel_name,
wheel_rule_outputs = wheel,
wheel = wheel,
wheel_deps = wheel_deps,
)
native.py_library(
Expand Down
27 changes: 27 additions & 0 deletions third_party/tsl/third_party/py/py_manylinux_compliance_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
""" Macros for manylinux compliance verification test. """

load("@rules_python//python:py_test.bzl", "py_test")

def verify_manylinux_compliance_test(
name,
wheel,
aarch64_compliance_tag,
x86_64_compliance_tag,
test_tags = []):
verify_manylinux_compliance_target = Label("//third_party/py:verify_manylinux_compliance")
py_test(
name = name,
srcs = [Label("//third_party/py:manylinux_compliance_test")],
data = [
wheel,
verify_manylinux_compliance_target,
],
args = [
"--verify-manylinux-compliance-script=$(location {})".format(verify_manylinux_compliance_target),
"--wheel-path=$(location {})".format(wheel),
"--aarch64-compliance-tag={}".format(aarch64_compliance_tag),
"--x86_64-compliance-tag={}".format(x86_64_compliance_tag),
],
main = "manylinux_compliance_test.py",
tags = ["manual"] + test_tags,
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def parse_args() -> argparse.Namespace:
description="Helper for auditwheel", fromfile_prefix_chars="@"
)
parser.add_argument(
"--wheel_path", required=True, help="Path of the wheel, mandatory"
"--wheel-path", required=True, help="Path of the wheel, mandatory"
)
parser.add_argument(
"--compliance-tag", help="ManyLinux compliance tag", required=False
Expand Down

0 comments on commit 47daf5a

Please sign in to comment.