Skip to content

Commit bbe0712

Browse files
authored
support binary wheels (bazel-contrib#388)
Support binary wheels Also allow other Python tag specifiers like cp35, to constrain to a particular Python version.
1 parent c972655 commit bbe0712

4 files changed

Lines changed: 68 additions & 10 deletions

File tree

experimental/examples/wheel/BUILD

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ py_wheel(
146146
],
147147
)
148148

149+
py_wheel(
150+
name = "python_abi3_binary_wheel",
151+
abi = "abi3",
152+
distribution = "example_python_abi3_binary_wheel",
153+
platform = "manylinux2014_x86_64",
154+
python_requires = ">=3.8",
155+
python_tag = "cp38",
156+
version = "0.0.1",
157+
)
158+
149159
py_test(
150160
name = "wheel_test",
151161
srcs = ["wheel_test.py"],
@@ -156,6 +166,7 @@ py_test(
156166
":customized",
157167
":minimal_with_py_library",
158168
":minimal_with_py_package",
159-
":python_requires_in_a_package"
169+
":python_abi3_binary_wheel",
170+
":python_requires_in_a_package",
160171
],
161172
)

experimental/examples/wheel/wheel_test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,44 @@ def test_python_requires_wheel(self):
181181
UNKNOWN
182182
""")
183183

184+
def test_python_abi3_binary_wheel(self):
185+
filename = os.path.join(
186+
os.environ["TEST_SRCDIR"],
187+
"rules_python",
188+
"experimental",
189+
"examples",
190+
"wheel",
191+
"example_python_abi3_binary_wheel-0.0.1-cp38-abi3-manylinux2014_x86_64.whl",
192+
)
193+
with zipfile.ZipFile(filename) as zf:
194+
metadata_contents = zf.read(
195+
"example_python_abi3_binary_wheel-0.0.1.dist-info/METADATA"
196+
)
197+
# The entries are guaranteed to be sorted.
198+
self.assertEqual(
199+
metadata_contents,
200+
b"""\
201+
Metadata-Version: 2.1
202+
Name: example_python_abi3_binary_wheel
203+
Version: 0.0.1
204+
Requires-Python: >=3.8
205+
206+
UNKNOWN
207+
""",
208+
)
209+
wheel_contents = zf.read(
210+
"example_python_abi3_binary_wheel-0.0.1.dist-info/WHEEL"
211+
)
212+
self.assertEqual(
213+
wheel_contents,
214+
b"""\
215+
Wheel-Version: 1.0
216+
Generator: bazel-wheelmaker 1.0
217+
Root-Is-Purelib: false
218+
Tag: cp38-abi3-manylinux2014_x86_64
219+
""",
220+
)
221+
184222

185223
if __name__ == '__main__':
186224
unittest.main()

experimental/python/wheel.bzl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,27 @@ This should match the project name onm PyPI. It's also the name that is used to
203203
refer to the package in other packages' dependencies.
204204
""",
205205
),
206-
# TODO(pstradomski): Support non-pure wheels
207206
"platform": attr.string(
208207
default = "any",
209-
doc = "Supported platforms. 'any' for pure-Python wheel.",
208+
doc = """\
209+
Supported platform. Use 'any' for pure-Python wheel.
210+
211+
If you have included platform-specific data, such as a .pyd or .so
212+
extension module, you will need to specify the platform in standard
213+
pip format. If you support multiple platforms, you can define
214+
platform constraints, then use a select() to specify the appropriate
215+
specifier, eg:
216+
217+
platform = select({
218+
"//platforms:windows_x86_64": "win_amd64",
219+
"//platforms:macos_x86_64": "macosx_10_7_x86_64",
220+
"//platforms:linux_x86_64": "manylinux2014_x86_64",
221+
})
222+
""",
210223
),
211224
"python_tag": attr.string(
212225
default = "py3",
213-
doc = "Supported Python major version. 'py2' or 'py3'",
214-
values = ["py2", "py3"],
226+
doc = "Supported Python version(s), eg 'py3', 'cp35.cp36', etc",
215227
),
216228
"version": attr.string(
217229
mandatory = True,

experimental/tools/wheelmaker.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ def add_wheelfile(self):
123123
wheel_contents = """\
124124
Wheel-Version: 1.0
125125
Generator: bazel-wheelmaker 1.0
126-
Root-Is-Purelib: true
127-
"""
126+
Root-Is-Purelib: {}
127+
""".format("true" if self._platform == "any" else "false")
128128
for tag in self.disttags():
129129
wheel_contents += "Tag: %s\n" % tag
130130
self.add_string(self.distinfo_path('WHEEL'), wheel_contents)
@@ -255,9 +255,6 @@ def main():
255255
"Can be supplied multiple times.")
256256
arguments = parser.parse_args(sys.argv[1:])
257257

258-
# add_wheelfile and add_metadata currently assume pure-Python.
259-
assert arguments.platform == 'any', "Only pure-Python wheels are supported"
260-
261258
if arguments.input_file:
262259
input_files = [i.split(';') for i in arguments.input_file]
263260
else:

0 commit comments

Comments
 (0)