README.rst 25.2 KB
Newer Older
1
################################################
Matthew Brett's avatar
Matthew Brett committed
2
Utilities for building on Travis CI and AppVeyor
3
################################################
4

Matthew Brett's avatar
Matthew Brett committed
5
6
7
************************************
Update: Uploads, Rackspace, Anaconda
************************************
Matthew Brett's avatar
Matthew Brett committed
8
9
10
11
12
13

The original Multibuild default was to upload wheels to a Rackspace container,
where Rackspace kindly donated the hosting to the Scikit-learn team.  We had
a URL pointing to the Rackspace container: `http://wheels.scipy.org`.

Rackspace finally stopped subsidizing this container, and the Rackspace of
Matthew Brett's avatar
Matthew Brett committed
14
15
`http://wheels.scipy.org` is no more. Some projects using Multibuild have moved
to using https://anaconda.org/scipy-wheels-nightly/ for weekly uploads and
Matthew Brett's avatar
Matthew Brett committed
16
17
https://anaconda.org/multibuild-wheels-staging for staging wheels to PyPI.

Matthew Brett's avatar
Matthew Brett committed
18
19
20
21
*******************
Uploads to Anaconda
*******************

Hugo van Kemenade's avatar
Hugo van Kemenade committed
22
If you want to upload to Anaconda, and you don't need the extra storage space for nightly builds that Anaconda kindly donates to NumPy, SciPy etc, then you can do this with your own Anaconda organization.
Matthew Brett's avatar
Matthew Brett committed
23

Andrew Murray's avatar
Andrew Murray committed
24
See https://github.com/MacPython/nipy-wheels for a simple example.
Matthew Brett's avatar
Matthew Brett committed
25
26
27
28

* Make an account at Anaconda.org.
* Make an organization - for example we have used ``nipy``.
* Navigate to ``https://anaconda.org/nipy`` (but use your organization).
Andrew Murray's avatar
Andrew Murray committed
29
* Go to your account menu towards the top left. This should be labeled with your
Matthew Brett's avatar
Matthew Brett committed
30
31
32
33
34
35
36
37
38
39
40
41
  organization name.
* Select "Settings", then "Access".
* Create an access token.  Give it permission: "Allow write access to the API
  site", and (not sure if this is necessary) "Allow uploads to PyPI
  repositories".
* "View" your token.  It may be of form
  ``ni-1234abcd-12ab-34dc-1234-d1e1f3a4b5c6``.
* Encrypt this to your repository, maybe using the ``travis`` command line tool
  (``gem install travis``).  Your command will be something like::

      travis encrypt -r MacPython/nipy-wheels ANACONDA_SECRET=ni-1234abcd-12ab-34dc-1234-d1e1f3a4b5c6

Hugo van Kemenade's avatar
Hugo van Kemenade committed
42
  Note that ``MacPython/nipy-wheels`` is your Github organization/repository.  The encryption only applies to Travis CI running against this repository.
Matthew Brett's avatar
Matthew Brett committed
43
44
45
46
47
48
49
50
51
52
53
54

* Go to your `.travis.yml` file and add the output ``secure`` key.  This will
  look something like::

    env:
      global:
        # Following generated with
        # travis encrypt -r MacPython/nipy-wheels ANACONDA_SECRET=<the api key>
        # where <the api key> has API write access to the anaconda.org
        # organization named in $ANACONDA_ORG
        - secure: "IqN7LjXWVBaijggUoB+ohjzFzH6nU0OyxznXEMgWoNxQJRiYXXKAt/Z5c4ldp9LUynefJO306M8foN4Gm8M8PNDlhjElzdOtIkGYtDKUXx7aXtrg8rPk1mzuM1F27er4Dbi7WFtpPClr8z8JKNNV50yeM1o2cXu4HgrPrRKgKk/2D8EQaPQlcOqul0O63D9AjVoW3EIG0aWEnZQQGfuGAPgyr0OS92LX2h1pcD2lNZHhqYmXmm5U0IwZmWL3Y0N7PO3VXcOCeIbiHAlJzhk4C4+86TT7DN+VhmfGyY/s61fOz47K+lEZLVqqeQki+HV75fti0XwYG7rjcSvDanNx+w2J/ogSLQpiNxZ0FZ+W8psXEaFUgFf7oXzRkW9gQ4KAsItEWHifq061ngr5AWLPLh+01LGP1Xg8wT5WEVUzBfD2uJPsy20DLcP9WGYa6cBNwtpqmUkdVgM3ZCPWlro7+v1kqxsKp91uh8SRKVlkD4mwbf0FnWxbNZ9v4Z9gs0pZoRclzL+/YcIcSTYAwiQRqaX7T0tpxaUZ0VYTMwCgpsufUX1idV1HV5+WKr9FUocoq+1RRW/JeXkisX9FRvem8cSGmnxB/hynlxoqzttCVMwtrKWPwxH4dHD+lavouho68Q7iBql1ZBZEhQy0O9NC1wr4Rg2CeDPZuzqVjmSPuXQ="

Hugo van Kemenade's avatar
Hugo van Kemenade committed
55
  When Travis CI runs, this causes the ``ANACONDA_SECRET`` environment variable
Matthew Brett's avatar
Matthew Brett committed
56
57
58
59
60
61
  to contain the API key above.

  Also add this to your global environment variables::

      - ANACONDA_ORG="nipy"

Hugo van Kemenade's avatar
Hugo van Kemenade committed
62
*  To upload from Travis CI, add a clause like this to the end of your
Matthew Brett's avatar
Matthew Brett committed
63
64
65
66
67
68
69
70
71
72
   ``.travis.yml``::

     after_success:
         # Upload wheels to Anaconda.org
         - pip install git+https://github.com/Anaconda-Platform/anaconda-project
         - pip install git+https://github.com/Anaconda-Platform/anaconda-client
         - anaconda -t ${ANACONDA_SECRET} upload --force -u ${ANACONDA_ORG} ${TRAVIS_BUILD_DIR}/wheelhouse/*.whl

   ``wheelhouse/*.whl`` defines the files you want to upload.

Hugo van Kemenade's avatar
Hugo van Kemenade committed
73
*   You might also want to build and upload from AppVeyor.  To encrypt the API
Andrew Murray's avatar
Andrew Murray committed
74
    key above, go to https://ci.appveyor.com/account/matthew-brett/settings
Hugo van Kemenade's avatar
Hugo van Kemenade committed
75
    (where ``matthew-brett`` is the account from which your AppVeyor job runs.
Matthew Brett's avatar
Matthew Brett committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
    Click on "Encrypt YaML" on the left.  Type in your API key value (e.g.
    ``ni-1234abcd-12ab-34dc-1234-d1e1f3a4b5c6``) as the value to encrypt. Click "Encrypt" and note the text it suggests.  Now, at the top of your ``appveyor.yml`` file, add something like::

        environment:
          global:
            ANACONDA_ORG: "nipy"
            ANACONDA_SECRET:
              secure: Ds0PkQD0b/QOfoNoiPuFJb01zg0Mq0dkAxIG2jRXocCAereSXdWw6XYaDrutHWme

    where ``secure:`` is the text suggested from "Encrypt" above, and ``nipy`` is your Anaconda organization.

    Finally, add a clause like the following to the end of your ``appveyor.yml`` file::

      on_success:
        # Upload the generated wheel package to Anaconda.org
        - pip install git+https://github.com/Anaconda-Platform/anaconda-project
        - pip install git+https://github.com/Anaconda-Platform/anaconda-client
        - anaconda -t %ANACONDA_SECRET% upload --force -u %ANACONDA_ORG% nipy\dist\*.whl

    where ``nipy\dist\*.whl`` finds the files you want to upload.

There's a simple example of these steps applied at
Andrew Murray's avatar
Andrew Murray committed
98
https://github.com/MacPython/nipy-wheels.
Matthew Brett's avatar
Matthew Brett committed
99

Matthew Brett's avatar
Matthew Brett committed
100
101
Here is the NumPy code (for running on Travis CI) to upload to Anaconda:
https://github.com/MacPython/numpy-wheels/blob/master/.travis.yml#L99
Matthew Brett's avatar
Matthew Brett committed
102

Matthew Brett's avatar
Matthew Brett committed
103
For projects housed under the MacPython GitHub organization, you have access to
Matthew Brett's avatar
Matthew Brett committed
104
105
Anaconda upload tokens via the "Organization Secrets"
https://github.com/MacPython/numexpr-wheels/settings/secrets . You can use
Matthew Brett's avatar
Matthew Brett committed
106
these to move to GitHub Actions (they provide x86 machines for Windows, Linux
Matthew Brett's avatar
Matthew Brett committed
107
and Mac). Otherwise we (please raise an issue here) will need to negotiate
Matthew Brett's avatar
Matthew Brett committed
108
109
110
111
112
113
114
115
116
117
getting you tokens, or you can make your own, as above.

**********************
Use Github for uploads
**********************

Another option is to use GitHub for staging --- as do Cython `for Travis CI
<https://github.com/MacPython/cython-wheels/blob/master/.travis.yml#L144>`_ and
`for AppVeyor
<https://github.com/MacPython/cython-wheels/blob/master/appveyor.yml#L118>`_.
Matthew Brett's avatar
Matthew Brett committed
118
119
120
121
122

************
Introduction
************

Hugo's avatar
Hugo committed
123
A set of scripts to automate builds of macOS and Manylinux1 wheels on the
124
`Travis CI <https://travis-ci.org/>`_ infrastructure, and also Windows
125
wheels on the `AppVeyor <https://ci.appveyor.com/>`_ infrastructure.
Matthew Brett's avatar
Matthew Brett committed
126

127
The Travis CI scripts are designed to build *and test*:
Matthew Brett's avatar
Matthew Brett committed
128

129
* 64-bit macOS wheels built for macOS 10.9+
robbuckley's avatar
robbuckley committed
130
* 64/32-bit macOS wheels built for macOS 10.6+
mattip's avatar
mattip committed
131
* 64-bit ``manylinuxX_x86_64`` wheels, both narrow and wide Unicode builds,
132
  where `X` is any valid Manylinux version: `1`, `2010`, `2014`, `_2_24` or `_2_28`.
133
* 32-bit ``manylinuxX_i686`` wheels, both narrow and wide Unicode builds
Matthew Brett's avatar
Matthew Brett committed
134

Hugo van Kemenade's avatar
Hugo van Kemenade committed
135
136
You can currently build and test against Pythons 2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10
and 3.11.
Matthew Brett's avatar
Matthew Brett committed
137

robbuckley's avatar
robbuckley committed
138
The small innovation here is that you can test against Linux 32-bit builds, both
139
140
wide and narrow Unicode Python 2 builds, which was not easy on the default
Travis CI configurations.
Matthew Brett's avatar
Matthew Brett committed
141

142
143
The AppVeyor setup is designed to build *and test*:

144
145
* 64-bit Windows ``win_amd64`` wheels
* 32-bit Windows ``win32`` wheels
146

Hugo van Kemenade's avatar
Hugo van Kemenade committed
147
148
You can currently build and test against Pythons 2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10
and 3.11.
149

150
151
152
153
154
155
156
157
158
159
*****************
How does it work?
*****************

Multibuild is a series of bash scripts that define bash functions to build and
test wheels.

Configuration is by overriding the default build function, and defining a test
function.

robbuckley's avatar
robbuckley committed
160
The bash scripts are layered, in the sense that they are composed of a number of scripts
Rob Buckley's avatar
Rob Buckley committed
161
which are sourced in sequence, each one potentially overriding previous ones.
162

Hugo's avatar
Hugo committed
163
164
macOS
=====
165

Rob Buckley's avatar
Rob Buckley committed
166
The following bash scripts are sourced in this order::
167

robbuckley's avatar
readme  
robbuckley committed
168
169
170
171
172
173
    multibuild/common_utils.sh
    multibuild/osx_utils.sh
    env_vars.sh
    multibuild/configure_build.sh
    multibuild/library_builders.sh
    config.sh
174

Rob Buckley's avatar
Rob Buckley committed
175
See ``multibuild/travis_osx_steps.sh``
176

robbuckley's avatar
robbuckley committed
177
The macOS build / test phases run on the macOS VM started by Travis CI.
robbuckley's avatar
readme  
robbuckley committed
178
Therefore any environment variable defined in ``.travis.yml`` or the bash
Matthew Brett's avatar
Matthew Brett committed
179
shell scripts listed above are available for your build and test.
180

robbuckley's avatar
readme  
robbuckley committed
181
182
Build options are controlled mainly by the following environment
variables:
183

184
* ``MB_PYTHON_VER`` sets the Python version targeted: ``major.minor.patch``
mattip's avatar
mattip committed
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
  for CPython, or ``pypy-major.minor`` for PyPy.
* ``MB_PYTHON_OSX_VER`` sets the minimum macOS SDK version for any C
  extensions. For CPython targets it may be set to 10.6 or 10.9, provided a
  corresponding Python build is available at `python.org
  <https://www.python.org/downloads/mac-osx/>`_. It defaults to the highest
  version available. It's ignored for PyPy targets.
* ``PLAT`` sets the architectures built for any C extensions: ``x86_64`` or
  ``intel`` for 64-bit or 64/32-bit respectively. It defaults to the same
  arches as the target Python version: 64-bit for CPython macOS 10.9 or PyPy,
  and 64/32-bit for CPython 10.6.

In most cases it's best to rely on the defaults for ``MB_PYTHON_OSX_VER`` and
``PLAT``, rather than setting them explicitly. Examples of exceptions to this
guideline include:

* setting ``MB_PYTHON_OSX_VER=10.6`` to build a 10.6 64/32-bit CPython wheel
  for Python 2.7 (default for 2.7 is 10.9 64-bit)
* setting ``MB_PYTHON_OSX_VER=10.6 and PLAT=x86_64`` to build a 10.6 64-bit
  only wheel (10.6 would normally be 64/32-bit). Such a wheel would still have
  a platform tag of ``macosx_10_6_intel`` , advertising support for both 64 and
mattip's avatar
mattip committed
205
  32-bit, but wouldn't work in 32-bit mode. This may be OK given how unlikely it
mattip's avatar
mattip committed
206
207
  is that there is still anyone actually running Python on macOS in 32-bit
  mode.
208

Rob Buckley's avatar
Rob Buckley committed
209
210
The ``build_wheel`` function builds the wheel, and ``install_run``
function installs and tests it.  Look in ``multibuild/common_utils.sh`` for
mattip's avatar
mattip committed
211
212
default definitions of these functions.  See below for more details, many of
which are common to macOS and Linux.
213

Matthew Brett's avatar
Matthew Brett committed
214
215
Manylinux
=========
216

217
The build phase is in a Manylinux Docker container, but the test phase is in
mattip's avatar
mattip committed
218
a clean container.
219

220

Matthew Brett's avatar
Matthew Brett committed
221
222
Build phase
-----------
223

224
Specify the Manylinux version to build for with the ``MB_ML_VER`` environment
225
variable. The default version is ``2014``.  Versions that are currently valid are:
226

Hugo van Kemenade's avatar
Hugo van Kemenade committed
227
228
* ``1`` corresponding to manylinux1 (see `PEP 513 <https://www.python.org/dev/peps/pep-0513>`_).
* ``2010``  corresponding to manylinux2010 (see `PEP 571 <https://www.python.org/dev/peps/pep-0571>`_).
229
* ``2014`` corresponding to manylinux2014 and adds more architectures to ``PLAT``
Hugo van Kemenade's avatar
Hugo van Kemenade committed
230
  (see `PEP 599 <https://www.python.org/dev/peps/pep-0599>`_).
mattip's avatar
mattip committed
231
* ``_2_24`` corresponding to manylinux_2_24 (see `PEP 600 <https://www.python.org/dev/peps/pep-0600>`_).
232
* ``_2_28`` corresponding to manylinux_2_28 (see `PEP 600 <https://www.python.org/dev/peps/pep-0600>`_).
233
234
235

The environment variable specified which Manylinux docker container you are building in.

236
237
238
239
240
241
242
243
244
245
246
The ``PLAT`` environment variable can be one of

* ``x86_64``, for 64-bit x86
* ``i686``, for 32-bit x86
* ``s390x``, for 64-bit s390x
* ``ppc64le``, for PowerPC
* ``aarch64``, for ARM
* ``arm64``, for Apple silicon
* ``universal2``, for both Apple silicon and 64-bit x86

The default is ``x86_64``. Only ``x86_64`` and ``i686`` are valid on manylinux1 and manylinux2010.
247

Matthew Brett's avatar
Matthew Brett committed
248
``multibuild/travis_linux_steps.sh`` defines the ``build_wheel`` function,
Hugo's avatar
Hugo committed
249
which starts up the Manylinux1 Docker container to run a wrapper script
Matthew Brett's avatar
Matthew Brett committed
250
``multibuild/docker_build_wrap.sh``, that (within the container) sources the
Rob Buckley's avatar
Rob Buckley committed
251
following bash scripts::
Matthew Brett's avatar
Matthew Brett committed
252

Rob Buckley's avatar
Rob Buckley committed
253
254
255
256
257
258
    multibuild/common_utils.sh
    multibuild/manylinux_utils.sh
    env_vars.sh
    multibuild/configure_build.sh
    multibuild/library_builders.sh
    config.sh
Matthew Brett's avatar
Matthew Brett committed
259

260
261
See ``docker_build_wrap.sh`` to review the order of script sourcing.

262
263
See the definition of ``build_multilinux`` in
``multibuild/travis_linux_steps.sh`` for the environment variables passed from
264
Travis CI to the Manylinux1 container.
Matthew Brett's avatar
Matthew Brett committed
265
266
267
268
269
270
271
272

Once in the container, after sourcing the scripts above, the wrapper runs the
real ``build_wheel`` function, which now comes (by default) from
``multibuild/common_utils.sh``.

Test phase
----------

273
Specify the version to test with the ``DOCKER_TEST_IMAGE`` environment
274
variable. The default version is dependent on ``MB_ML_LIBC`` and ``PLAT``.
275

276
277
278
279
280
281
282
283
284
285
286
When ``MB_ML_LIBC`` is ``musllinux``:

* ``multibuild/alpine3.15_x86_64``,  when ``PLAT`` is ``x86_64``

Otherwise:

* ``multibuild/focal_x86_64``, when ``PLAT`` is ``x86_64``
* ``matthewbrett/trusty:32`` when ``PLAT`` is ``i686`` (Yes, an older image for 32-bit)
* ``multibuild/focal_arm64v8`` when ``PLAT`` is ``aarch64``
* ``multibuild/focal_ppc64le`` when ``PLAT`` is ``ppc64le``
* ``multibuild/focal_s390x`` when ``PLAT`` is ``s390x``
287
288
289

Other valid values are any in https://hub.docker.com/orgs/multibuild/repositories,
using the correct platform code. Alternatively, you can use the substitution
290
pattern ``multibuild/focal_{PLAT}`` in the ``.travis.yml`` file.
mattip's avatar
mattip committed
291
292
293
294
295
296
297

See ``multibuild/docker_test_wrap.sh``.

``multibuild/travis_linux_steps.sh`` defines the ``install_run`` function,
which starts up the testing Docker container with the wrapper script
``multibuild/docker_test_wrap.sh``. The wrapper script sources the following
bash scripts::
Matthew Brett's avatar
Matthew Brett committed
298

Rob Buckley's avatar
Rob Buckley committed
299
300
    multibuild/common_utils.sh
    config.sh
Matthew Brett's avatar
Matthew Brett committed
301

302
303
See ``docker_test_wrap.sh`` for script source order.

Matthew Brett's avatar
Matthew Brett committed
304
305
306
307
308
See ``install_run`` in ``multibuild/travis_linux_steps.sh`` for the
environment variables passed into the container.

It then (in the container) runs the real ``install_run`` command, which comes
(by default) from ``multibuild/common_utils.sh``.
309
310
311
312
313

*********************************
Standard build and test functions
*********************************

Andrew Murray's avatar
Andrew Murray committed
314
The standard build command is ``build_wheel``.  This is a bash function.  By
Hugo's avatar
Hugo committed
315
default the function that is run on macOS, and in the Manylinux container for
Matthew Brett's avatar
Matthew Brett committed
316
317
318
the build phase, is defined in ``multibuild/common_utils.sh``.  You can
override the default function in the project ``config.sh`` file (see below).

robbuckley's avatar
typos  
robbuckley committed
319
If you are building a wheel from PyPI, rather than from a source repository,
320
321
322
323
324
325
326
you can use the ``build_index_wheel`` command, again defined in
``multibuild/common_utils.sh``.

Typically, you can get away with leaving the default ``build_wheel`` /
``build_index_wheel`` functions to do their thing, but you may need to define
a ``pre_build`` function in ``config.sh``.  The default ``build_wheel`` and
``build_index_wheel`` functions will call the ``pre_build`` function, if
327
328
329
defined, before building the wheel, so ``pre_build`` is a good place to build
any required libraries.

Matthew Brett's avatar
Matthew Brett committed
330
The standard test command is the bash function ``install_run``.  The version
Hugo's avatar
Hugo committed
331
run on macOS and in the Linux testing container is also defined in
Matthew Brett's avatar
Matthew Brett committed
332
``multibuild/common_utils.sh``.  Typically, you do not override this function,
333
334
335
336
but you in that case you will need to define a ``run_tests`` function, to run
your tests, returning a non-zero error code for failure.  The default
``install_run`` implementation calls the ``run_tests`` function, which you
will likely define in ``config.sh``.  See the examples below for examples of
Andrew Murray's avatar
Andrew Murray committed
337
less and more complicated builds, where the complicated builds override more
338
of the default implementations.
339
340
341
342

********************
To use these scripts
********************
Matthew Brett's avatar
Matthew Brett committed
343

344
* Make a repository for building wheels on Travis CI - e.g.
Matthew Brett's avatar
Matthew Brett committed
345
346
347
348
349
  https://github.com/MacPython/astropy-wheels - or in your case maybe
  ``https://github.com/your-org/your-project-wheels``;

* Add this (here) repository as a submodule::

Hugo van Kemenade's avatar
Hugo van Kemenade committed
350
    git submodule add https://github.com/multi-build/multibuild.git
Matthew Brett's avatar
Matthew Brett committed
351
352
353
354
355
356
357
358

* Add your own project repository as another submodule::

    git submodule add https://github.com/your-org/your-project.git

* Create a ``.travis.yml`` file, something like this::

    env:
359
360
361
362
363
        global:
            - REPO_DIR=your-project
            # Commit from your-project that you want to build
            - BUILD_COMMIT=v0.1.0
            # pip dependencies to _build_ your project
robbuckley's avatar
typos  
robbuckley committed
364
            - BUILD_DEPENDS="cython numpy"
365
366
367
            # pip dependencies to _test_ your project.  Include any dependencies
            # that you need, that are also specified in BUILD_DEPENDS, this will be
            # a separate install.
Matthew Brett's avatar
Matthew Brett committed
368
369
            # Now see the Uploads section for the stuff you need to
            # upload your wheels after CI has built them.
Matthew Brett's avatar
Matthew Brett committed
370

371
372
373
374
375
376
377
    # You will likely prefer "language: generic" for travis configuration,
    # rather than, say "language: python". Multibuild doesn't use
    # Travis-provided Python but rather installs and uses its own, where the
    # Python version is set from the MB_PYTHON_VERSION variable. You can still
    # specify a language here if you need it for some unrelated logic and you
    # can't use Multibuild-provided Python or other software present on a
    # builder.
378
    language: generic
379
380
381

    # For CPython macOS builds only, the minimum supported macOS version and
    # architectures of any C extensions in the wheel are set with the variable
Rob Buckley's avatar
Rob Buckley committed
382
383
384
385
386
    # MB_PYTHON_OSX_VER: 10.9 (64-bit only) or 10.6 (64/32-bit dual arch). By
    # default this is set to the highest available for the Python version selected
    # using MB_PYTHON_VERSION. You should only need to set this explicitly if you
    # are building a 10.6 dual-arch build for a CPython version where both a 10.9 and
    # 10.6 build are available (for example, 2.7 or 3.7).
387
388
    # All PyPy macOS builds are 64-bit only.

Andrew Murray's avatar
Andrew Murray committed
389
    # Required in Linux to invoke `docker` ourselves
Matthew Brett's avatar
Matthew Brett committed
390
391
    services: docker

392
393
394
    # Host distribution.  This is the distribution from which we run the build
    # and test containers, via docker.
    dist: xenial
Matthew Brett's avatar
Matthew Brett committed
395

Isuru Fernando's avatar
Isuru Fernando committed
396
397
    # osx image that enables building Apple silicon libraries
    osx_image: xcode12.2
398

Matthew Brett's avatar
Matthew Brett committed
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
    matrix:
      include:
        - os: linux
          env: MB_PYTHON_VERSION=2.7
        - os: linux
          env:
            - MB_PYTHON_VERSION=2.7
            - UNICODE_WIDTH=16
        - os: linux
          env:
            - MB_PYTHON_VERSION=2.7
            - PLAT=i686
        - os: linux
          env:
            - MB_PYTHON_VERSION=2.7
            - PLAT=i686
            - UNICODE_WIDTH=16
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.5
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.5
            - PLAT=i686
riddell1's avatar
riddell1 committed
423
424
425
426
427
428
429
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.6
        - os: linux
          env:
            - MB_PYTHON_VERSION=3.6
            - PLAT=i686
Matthew Brett's avatar
Matthew Brett committed
430
431
432
        - os: osx
          env:
            - MB_PYTHON_VERSION=2.7
Rob Buckley's avatar
Rob Buckley committed
433
            - MB_PYTHON_OSX_VER=10.6
robbuckley's avatar
readme  
robbuckley committed
434
435
436
        - os: osx
          env:
            - MB_PYTHON_VERSION=2.7
Matthew Brett's avatar
Matthew Brett committed
437
438
439
        - os: osx
          env:
            - MB_PYTHON_VERSION=3.5
riddell1's avatar
riddell1 committed
440
441
442
        - os: osx
          env:
            - MB_PYTHON_VERSION=3.6
Kyle Stewart's avatar
Kyle Stewart committed
443
        - os: osx
444
          env:
445
            - MB_PYTHON_VERSION=3.7
Rob Buckley's avatar
Rob Buckley committed
446
447
448
449
450
451
452
            - MB_PYTHON_OSX_VER=10.6
        - os: osx
          env:
            - MB_PYTHON_VERSION=3.7
        - os: osx
          env:
            - MB_PYTHON_VERSION=3.8
453
454
455
456
        - os: osx
          env:
            - MB_PYTHON_VERSION=3.9
            - PLAT="universal2"
457
458
459
        - os: osx
          env:
            - MB_PYTHON_VERSION=3.9
Kyle Stewart's avatar
Kyle Stewart committed
460
461
462
        - os: osx
          language: generic
          env:
463
            - MB_PYTHON_VERSION=pypy-5.7
Matthew Brett's avatar
Matthew Brett committed
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478

    before_install:
        - source multibuild/common_utils.sh
        - source multibuild/travis_steps.sh
        - before_install

    install:
        # Maybe get and clean and patch source
        - clean_code $REPO_DIR $BUILD_COMMIT
        - build_wheel $REPO_DIR $PLAT

    script:
        - install_run $PLAT

    after_success:
Matthew Brett's avatar
Matthew Brett committed
479
480
        # Here you should put the code to upload your wheels
        # See the Uploads section for more details.
Matthew Brett's avatar
Matthew Brett committed
481

Hugo's avatar
Hugo committed
482
  The example above is for a project building from a Git submodule.  If you
483
484
485
486
487
488
489
490
491
492
493
494
495
496
  aren't building from a submodule, but want to use ``pip`` to build from a
  source archive on https://pypi.org or similar, replace the first few lines
  of the ``.travis.yml`` file with something like::

    env:
        global:
            # Instead of REPO_DIR, BUILD_COMMIT
            - PROJECT_SPEC="tornado==4.1.1"

  then your ``install`` section could look something like this::

    install:
        - build_index_wheel $PROJECT_SPEC

497

Matthew Brett's avatar
Matthew Brett committed
498
499
500
501
502
* Next create a ``config.sh`` for your project, that fills in any steps you
  need to do before building the wheel (such as building required libraries).
  You also need this file to specify how to run your tests::

    # Define custom utilities
Andrew Murray's avatar
Andrew Murray committed
503
    # Test for macOS with [ -n "$IS_MACOS" ]
Matthew Brett's avatar
Matthew Brett committed
504
505
506
507
508
509
510
511
512
513
514
515
516

    function pre_build {
        # Any stuff that you need to do before you start building the wheels
        # Runs in the root directory of this repository.
        :
    }

    function run_tests {
        # Runs tests on installed distribution from an empty directory
        python --version
        python -c 'import sys; import yourpackage; sys.exit(yourpackage.test())'
    }

517
518
  Optionally you can specify a different location for ``config.sh`` file with
  the ``$CONFIG_PATH`` environment variable.
519

520
* Optionally, create an ``env_vars.sh`` file to override the defaults for any
521
522
523
  environment variables used by
  ``configure_build.sh``/``library_builders.sh``. In Linux, the environment
  variables used for the build cannot be set in the ``.travis.yml`` file,
524
  because the build processing runs in a Docker container, so the only
525
526
527
528
529
530
531
532
  environment variables that reach the container are those passed in via the
  ``docker run`` command, or those set in ``env_vars.sh``.

  As for the ``config.sh`` file, you can specify a different location for the
  file by setting the ``$ENV_VARS_PATH`` environment variable.  The path in
  ``$ENV_VARS_PATH`` is relative to the repository root directory.  For
  example, if your repository had a subdirectory ``scripts`` with a file
  ``my_env_vars.sh``, you should set ``ENV_VARS_PATH=scripts/my_env_vars.sh``.
533

534
* Make sure your project is set up to build on Travis CI, and you should now
Matthew Brett's avatar
Matthew Brett committed
535
  be ready (to begin the long slow debugging process, probably).
536

537
538
539
540
541
* For the Windows wheels, create an ``appveyor.yml`` file, something like:

  - https://github.com/MacPython/astropy-wheels/blob/master/appveyor.yml
  - https://github.com/MacPython/nipy-wheels/blob/master/appveyor.yml
  - https://github.com/MacPython/pytables-wheels/blob/master/appveyor.yml
542

543
544
  Note the Windows test customizations etc are inside ``appveyor.yml``,
  and that ``config.sh`` and ``env_vars.sh`` are only for the
545
  Linux/Mac builds on Travis CI.
546

Matthew Brett's avatar
Matthew Brett committed
547
* Make sure your project is set up to build on AppVeyor, and you should now
548
  be ready (for what could be another round of slow debugging).
Matthew Brett's avatar
Matthew Brett committed
549

550
551
552
* For Apple silicon support you can either create an ``arm64`` wheel or
  a ``universal2`` wheel by supplying ``PLAT`` env variable.
  ``universal2`` builds work on both ``arm64`` and ``x86_64`` platforms
553
554
  and also make it possible for the wheel code to work when switching the
  architecture on Apple silicon machines where ``x86_64`` can be run
555
556
557
  using Rosetta2 emulation.

  There are two ways to build ``universal2`` builds.
Isuru Fernando's avatar
Isuru Fernando committed
558

559
560
  1. Build with ``-arch x86_64 -arch arm64``.
     These flags instruct the C/C++ compiler to compile twice and create a
561
     fat object/executable/library. This is the easiest, but has several
562
563
564
565
566
567
568
     drawbacks. If you are using C/C++ libraries that are built using
     library_builders, it's highly likely that they don't build correctly
     because most build systems and packages don't support building fat binaries.
     We could possibly build them separately and fuse them, but the headers might
     not be identical which is required when building the wheel as a ``universal2``
     wheel. If you are using Fortran, ``gfortran`` doesn't support fat binaries.

Andrew Murray's avatar
Andrew Murray committed
569
  2. Build ``arm64`` and ``x86_64`` wheels separately and fuse them.
570
571
572
573
574
575
     For this to work, we need to build the C/C++ libraries twice. Therefore,
     the library building is once called with ``BUILD_PREFIX=${BUILD_PREFIX:-/usr/local}``
     for ``x86_64`` and then called again with ``BUILD_PREFIX=/opt/arm64-builds``.
     Once the two wheels are created, these two are merged. Both the
     ``arm64`` and ``universal2`` wheels are outputs for this build.

576
577
  In multibuild we are going with option 2. You can override this behaviour by
  overriding the function ``wrap_wheel_builder``.
578
579
580
  To build Apple silicon builds, you should use a CI service with Xcode 12 with
  universal build support and make sure that xcode is the default.

Hugo's avatar
Hugo committed
581
582
If your project depends on NumPy, you will want to build against the earliest
NumPy that your project supports - see `forward, backward NumPy compatibility
Andrew Murray's avatar
Andrew Murray committed
583
<https://stackoverflow.com/questions/17709641/valueerror-numpy-dtype-has-the-wrong-size-try-recompiling/18369312#18369312>`_.
584
See the `astropy-wheels Travis file
Matthew Brett's avatar
Matthew Brett committed
585
<https://github.com/MacPython/astropy-wheels/blob/master/.travis.yml>`_ for an
Hugo's avatar
Hugo committed
586
example specifying NumPy build and test dependencies.
Matthew Brett's avatar
Matthew Brett committed
587
588
589
590
591
592
593
594
595

Here are some simple example projects:

* https://github.com/MacPython/astropy-wheels
* https://github.com/scikit-image/scikit-image-wheels
* https://github.com/MacPython/nipy-wheels
* https://github.com/MacPython/dipy-wheels

Less simple projects where there are some serious build dependencies, and / or
Hugo's avatar
Hugo committed
596
macOS / Linux differences:
Matthew Brett's avatar
Matthew Brett committed
597
598
599
600

* https://github.com/MacPython/matplotlib-wheels
* https://github.com/python-pillow/Pillow-wheels
* https://github.com/MacPython/h5py-wheels
601
602
603
604
605
606

**********************
Multibuild development
**********************

The main multibuild repository is always at
Hugo van Kemenade's avatar
Hugo van Kemenade committed
607
https://github.com/multi-build/multibuild
608

609
610
We try to keep the ``master`` branch stable and do testing and development
in the ``devel`` branch.  From time to time we merge ``devel`` into ``master``.
611

612
613
In practice, you can check out the newest commit from ``devel`` that works
for you, then stay at it until you need newer features.