xref: /aosp_15_r20/external/pytorch/.ci/docker/manywheel/build_scripts/manylinux1-check.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1# Logic copied from PEP 513
2
3
4def is_manylinux1_compatible():
5    # Only Linux, and only x86-64 / i686
6    from distutils.util import get_platform
7
8    if get_platform() not in ["linux-x86_64", "linux-i686", "linux-s390x"]:
9        return False
10
11    # Check for presence of _manylinux module
12    try:
13        import _manylinux
14
15        return bool(_manylinux.manylinux1_compatible)
16    except (ImportError, AttributeError):
17        # Fall through to heuristic check below
18        pass
19
20    # Check glibc version. CentOS 5 uses glibc 2.5.
21    return have_compatible_glibc(2, 5)
22
23
24def have_compatible_glibc(major, minimum_minor):
25    import ctypes
26
27    process_namespace = ctypes.CDLL(None)
28    try:
29        gnu_get_libc_version = process_namespace.gnu_get_libc_version
30    except AttributeError:
31        # Symbol doesn't exist -> therefore, we are not linked to
32        # glibc.
33        return False
34
35    # Call gnu_get_libc_version, which returns a string like "2.5".
36    gnu_get_libc_version.restype = ctypes.c_char_p
37    version_str = gnu_get_libc_version()
38    # py2 / py3 compatibility:
39    if not isinstance(version_str, str):
40        version_str = version_str.decode("ascii")
41
42    # Parse string and check against requested version.
43    version = [int(piece) for piece in version_str.split(".")]
44    assert len(version) == 2
45    if major != version[0]:
46        return False
47    if minimum_minor > version[1]:
48        return False
49    return True
50
51
52import sys
53
54
55if is_manylinux1_compatible():
56    print(f"{sys.executable} is manylinux1 compatible")
57    sys.exit(0)
58else:
59    print(f"{sys.executable} is NOT manylinux1 compatible")
60    sys.exit(1)
61