diff --git a/experimental/examples/wheel/BUILD b/experimental/examples/wheel/BUILD index d721e4c0ae..0613e6a74c 100644 --- a/experimental/examples/wheel/BUILD +++ b/experimental/examples/wheel/BUILD @@ -146,6 +146,16 @@ py_wheel( ], ) +py_wheel( + name = "python_abi3_binary_wheel", + abi = "abi3", + distribution = "example_python_abi3_binary_wheel", + platform = "manylinux2014_x86_64", + python_requires = ">=3.8", + python_tag = "cp38", + version = "0.0.1", +) + py_test( name = "wheel_test", srcs = ["wheel_test.py"], @@ -156,6 +166,7 @@ py_test( ":customized", ":minimal_with_py_library", ":minimal_with_py_package", - ":python_requires_in_a_package" + ":python_abi3_binary_wheel", + ":python_requires_in_a_package", ], ) diff --git a/experimental/examples/wheel/wheel_test.py b/experimental/examples/wheel/wheel_test.py index b392457990..e461fa9dde 100644 --- a/experimental/examples/wheel/wheel_test.py +++ b/experimental/examples/wheel/wheel_test.py @@ -181,6 +181,44 @@ def test_python_requires_wheel(self): UNKNOWN """) + def test_python_abi3_binary_wheel(self): + filename = os.path.join( + os.environ["TEST_SRCDIR"], + "rules_python", + "experimental", + "examples", + "wheel", + "example_python_abi3_binary_wheel-0.0.1-cp38-abi3-manylinux2014_x86_64.whl", + ) + with zipfile.ZipFile(filename) as zf: + metadata_contents = zf.read( + "example_python_abi3_binary_wheel-0.0.1.dist-info/METADATA" + ) + # The entries are guaranteed to be sorted. + self.assertEqual( + metadata_contents, + b"""\ +Metadata-Version: 2.1 +Name: example_python_abi3_binary_wheel +Version: 0.0.1 +Requires-Python: >=3.8 + +UNKNOWN +""", + ) + wheel_contents = zf.read( + "example_python_abi3_binary_wheel-0.0.1.dist-info/WHEEL" + ) + self.assertEqual( + wheel_contents, + b"""\ +Wheel-Version: 1.0 +Generator: bazel-wheelmaker 1.0 +Root-Is-Purelib: false +Tag: cp38-abi3-manylinux2014_x86_64 +""", + ) + if __name__ == '__main__': unittest.main() diff --git a/experimental/python/wheel.bzl b/experimental/python/wheel.bzl index 3de218fc6f..4a785cd997 100644 --- a/experimental/python/wheel.bzl +++ b/experimental/python/wheel.bzl @@ -203,15 +203,27 @@ This should match the project name onm PyPI. It's also the name that is used to refer to the package in other packages' dependencies. """, ), - # TODO(pstradomski): Support non-pure wheels "platform": attr.string( default = "any", - doc = "Supported platforms. 'any' for pure-Python wheel.", + doc = """\ +Supported platform. Use 'any' for pure-Python wheel. + +If you have included platform-specific data, such as a .pyd or .so +extension module, you will need to specify the platform in standard +pip format. If you support multiple platforms, you can define +platform constraints, then use a select() to specify the appropriate +specifier, eg: + + platform = select({ + "//platforms:windows_x86_64": "win_amd64", + "//platforms:macos_x86_64": "macosx_10_7_x86_64", + "//platforms:linux_x86_64": "manylinux2014_x86_64", + }) +""", ), "python_tag": attr.string( default = "py3", - doc = "Supported Python major version. 'py2' or 'py3'", - values = ["py2", "py3"], + doc = "Supported Python version(s), eg 'py3', 'cp35.cp36', etc", ), "version": attr.string( mandatory = True, diff --git a/experimental/tools/wheelmaker.py b/experimental/tools/wheelmaker.py index 799eed75e6..18e63573e9 100644 --- a/experimental/tools/wheelmaker.py +++ b/experimental/tools/wheelmaker.py @@ -123,8 +123,8 @@ def add_wheelfile(self): wheel_contents = """\ Wheel-Version: 1.0 Generator: bazel-wheelmaker 1.0 -Root-Is-Purelib: true -""" +Root-Is-Purelib: {} +""".format("true" if self._platform == "any" else "false") for tag in self.disttags(): wheel_contents += "Tag: %s\n" % tag self.add_string(self.distinfo_path('WHEEL'), wheel_contents) @@ -255,9 +255,6 @@ def main(): "Can be supplied multiple times.") arguments = parser.parse_args(sys.argv[1:]) - # add_wheelfile and add_metadata currently assume pure-Python. - assert arguments.platform == 'any', "Only pure-Python wheels are supported" - if arguments.input_file: input_files = [i.split(';') for i in arguments.input_file] else: