summaryrefslogtreecommitdiff
path: root/tools/manylinux/build-wheels.sh
blob: 308c38a908ba8f4a20c6129ad20912b135424c0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
#
# Called inside the manylinux image
echo "Started $0 $@"

set -e -x
REQUIREMENTS=/io/requirements.txt
WHEELHOUSE=/io/wheelhouse
SDIST=$1

build_wheel() {
    pybin="$1"
    source="$2"
    [ -n "$source" ] || source=/io

    env STATIC_DEPS=true \
        LDFLAGS="$LDFLAGS -fPIC" \
        CFLAGS="$CFLAGS -fPIC" \
        ${pybin}/pip \
            wheel \
            "$source" \
            -w $WHEELHOUSE
}

assert_importable() {
    # Install packages and test
    for PYBIN in /opt/python/*/bin/; do
        ${PYBIN}/pip install lxml --no-index -f $WHEELHOUSE

        (cd $HOME; ${PYBIN}/python -c 'import lxml.etree, lxml.objectify')
    done
}

prepare_system() {
    #yum install -y zlib-devel
    # Remove Python 2.6 symlinks
    rm -f /opt/python/cp26*
    echo "Python versions found: $(cd /opt/python && echo cp* | sed -e 's|[^ ]*-||g')"
}

build_wheels() {
    # Compile wheels for all python versions
    test -e "$SDIST" && source="$SDIST" || source=
    FIRST=
    SECOND=
    for PYBIN in /opt/python/*/bin; do
        # Install build requirements if we need them and file exists
        test -n "$source" -o ! -e "$REQUIREMENTS" \
            || ${PYBIN}/pip install -r "$REQUIREMENTS"

        build_wheel "$PYBIN" "$source" &
        SECOND=$!

        [ -z "$FIRST" ] || wait ${FIRST}
        FIRST=$SECOND
    done
    wait
}

repair_wheels() {
    # Bundle external shared libraries into the wheels
    for whl in $WHEELHOUSE/*.whl; do
        auditwheel repair $whl -w $WHEELHOUSE
    done
}

show_wheels() {
    filename=${SDIST##*/}
    ls -l $WHEELHOUSE/${filename%%.tar.gz}
}

prepare_system
build_wheels
repair_wheels
assert_importable
show_wheels