Skip to content

Commit 93c8133

Browse files
authored
Merge pull request #1187 from pradyunsg/extension
Partially flesh out the binary extensions guide
2 parents 309d259 + 0b59fc4 commit 93c8133

File tree

1 file changed

+77
-25
lines changed

1 file changed

+77
-25
lines changed

source/guides/packaging-binary-extensions.rst

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -230,34 +230,82 @@ The CPython :doc:`Extending and Embedding <python:extending/index>`
230230
guide includes an introduction to writing a
231231
:doc:`custom extension module in C <python:extending/extending>`.
232232

233-
..
233+
FIXME: Elaborate that all this is one of the reasons why you probably
234+
*don't* want to handcode your extension modules :)
234235

235-
FIXME
236236

237-
* mention the stable ABI (3.2+, link to the CPython C API docs)
238-
* mention the module lifecycle
239-
* mention the challenges of shared static state and subinterpreters
240-
* mention the implications of the GIL for extension modules
241-
* mention the memory allocation APIs in 3.4+
237+
Extension module lifecycle
238+
--------------------------
242239

243-
* mention again that all this is one of the reasons why you probably *don't*
244-
want to handcode your extension modules :)
240+
FIXME: This section needs to be fleshed out.
241+
242+
243+
Implications of shared static state and subinterpreters
244+
-------------------------------------------------------
245+
246+
FIXME: This section needs to be fleshed out.
247+
248+
249+
Implications of the GIL
250+
-----------------------
251+
252+
FIXME: This section needs to be fleshed out.
253+
254+
255+
Memory allocation APIs
256+
----------------------
257+
258+
FIXME: This section needs to be fleshed out.
259+
260+
261+
.. _cpython-stable-abi:
262+
263+
ABI Compatibility
264+
-----------------
265+
266+
The CPython C API does not guarantee ABI stability between minor releases
267+
(3.2, 3.3, 3.4, etc.). This means that, typically, if you build an
268+
extension module against one version of Python, it is only guaranteed to
269+
work with the same minor version of Python and not with any other minor
270+
versions.
271+
272+
Python 3.2 introduced the Limited API, with is a well-defined subset of
273+
Python's C API. The symbols needed for the Limited API form the
274+
"Stable ABI" which is guaranteed to be compatible across all Python 3.x
275+
versions. Wheels containing extensions built against the stable ABI use
276+
the ``abi3`` ABI tag, to reflect that they're compatible with all Python
277+
3.x versions.
278+
279+
CPython's :doc:`C API stability<python:c-api/stable>` page provides
280+
detailed information about the API / ABI stability guarantees, how to use
281+
the Limited API and the exact contents of the "Limited API".
245282

246283

247284
Building binary extensions
248285
==========================
249286

287+
FIXME: Cover the build-backends available for building extensions.
288+
250289
Building extensions for multiple platforms
251290
------------------------------------------
252291

253292
If you plan to distribute your extension, you should provide
254-
:term:`wheels <Wheel>` for all the platforms you intend to support. For most
255-
extensions, this is at least one package per Python version times the number of
256-
OS and architectures you support. These are usually built on continuous
257-
integration (CI) systems. There are tools to help you build highly
258-
redistributable binaries from CI; these include :ref:`cibuildwheel` and
259-
:ref:`multibuild`.
293+
:term:`wheels <Wheel>` for all the platforms you intend to support. These
294+
are usually built on continuous integration (CI) systems. There are tools
295+
to help you build highly redistributable binaries from CI; these include
296+
:ref:`cibuildwheel` and :ref:`multibuild`.
297+
298+
For most extensions, you will need to build wheels for all the platforms
299+
you intend to support. This means that the number of wheels you need to
300+
build is the product of::
301+
302+
count(Python minor versions) * count(OS) * count(architectures)
260303

304+
Using CPython's :ref:`Stable ABI <cpython-stable-abi>` can help significantly
305+
reduce the number of wheels you need to provide, since a single wheel on a
306+
platform can be used with all Python minor versions; eliminating one dimension
307+
of the matrix. It also removes the need to generate new wheels for each new
308+
minor version of Python.
261309

262310
Binary extensions for Windows
263311
-----------------------------
@@ -310,20 +358,24 @@ Spinning Wheels wiki
310358
Publishing binary extensions
311359
============================
312360

313-
For interim guidance on this topic, see the discussion in
314-
:issue:`this issue <284>`.
361+
Publishing binary extensions through PyPI uses the same upload mechanisms as
362+
publishing pure Python packages. You build a wheel file for your extension
363+
using the build-backend and upload it to PyPI using
364+
:doc:`twine <twine:index>`.
315365

316-
..
366+
Avoid binary-only releases
367+
--------------------------
317368

318-
FIXME
369+
It is strongly recommended that you publish your binary extensions as
370+
well as the source code that was used to build them. This allows users to
371+
build the extension from source if they need to. Notably, this is required
372+
for certain Linux distributions that build from source within their
373+
own build systems for the distro package repositories.
319374

320-
* cover publishing as wheel files on PyPI or a custom index server
321-
* cover creation of Windows and macOS installers
322-
* cover weak linking
323-
* mention the fact that Linux distros have a requirement to build from
324-
source in their own build systems, so binary-only releases are strongly
325-
discouraged
375+
Weak linking
376+
------------
326377

378+
FIXME: This section needs to be fleshed out.
327379

328380
Additional resources
329381
====================

0 commit comments

Comments
 (0)