Skip to content

Commit f757846

Browse files
committed
Fix CI configuration (for real this time..)
1 parent 3238779 commit f757846

4 files changed

Lines changed: 96 additions & 75 deletions

File tree

appveyor.yml

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,25 @@ environment:
2020
RUST_TARGET: "x86_64-pc-windows-msvc"
2121

2222
install:
23-
# Install Python dependencies
24-
- "%PYTHON%\\python.exe -m pip install -U pip setuptools distribute"
25-
- "%PYTHON%\\python.exe -m pip install -U wheel cffi pytest"
26-
# Install Rust
23+
- ".build.cmd %PYTHON%\\python -m pip install -U pip setuptools wheel"
2724
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-nightly-${env:RUST_TARGET}.exe"
2825
- rust-nightly-%RUST_TARGET%.exe /VERYSILENT /NORESTART /DIR="C:\Program Files (x86)\Rust"
2926
- SET PATH=%PATH%;C:\Program Files (x86)\Rust\bin
3027
- SET PATH=%PATH%;C:\MinGW\bin
3128
- rustc -V
3229
- cargo -V
33-
- cd c:\projects\python-rust-fst
34-
# For some reason the binary wheel only gets built the second time we run this...
35-
- ".build.cmd %PYTHON%\\python setup.py bdist_wheel || echo 'First build step done...'"
36-
# Remove the bad wheel
37-
- del /s /q /f dist\*any.whl
38-
# Build the right wheel
39-
- ".build.cmd %PYTHON%\\python setup.py bdist_wheel"
4030

41-
build: off
31+
build_script:
32+
- cd c:\projects\python-rust-fst
33+
- ".build.cmd %PYTHON%\\python -m pip -v wheel . -w .\\wheelhouse"
34+
- dir wheelhouse
4235

4336
test_script:
44-
# We have to be outside of the project directory for the tests
4537
- SET PROJPATH=C:\Projects\python-rust-fst
4638
- cd c:\projects
47-
- "%PROJPATH%\\.build.cmd %PYTHON%\\python -m pip install rust_fst --no-index -f %PROJPATH%\\dist"
48-
- "%PROJPATH%\\.build.cmd %PYTHON%\\python -m pytest %PROJPATH%\\tests"
39+
- "%PROJPATH%\\.build.cmd %PYTHON%\\python -m pip install cffi pytest"
40+
- "%PROJPATH%\\.build.cmd %PYTHON%\\python -m pip -v install rust_fst --no-index -f %PROJPATH%\\wheelhouse"
41+
- "%PROJPATH%\\.build.cmd %PYTHON%\\python -m pytest --verbose %PROJPATH%\\tests"
4942

5043
artifacts:
51-
- path: dist\*
44+
- path: wheelhouse\rust_fst*.whl

build-wheels.sh

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,87 @@
11
#!/bin/bash
22
set -e -x
33

4+
function install_openssl {
5+
# Compile and parallel-install a newer OpenSSL version so that curl can
6+
# download from the rust servers
7+
pushd /usr/src
8+
wget -q ftp://ftp.openssl.org/source/openssl-${1}.tar.gz
9+
tar xf openssl-${1}.tar.gz
10+
cd openssl-${1}
11+
./config --prefix=/opt/openssl shared > /dev/null
12+
make > /dev/null
13+
make install > /dev/null
14+
export LD_LIBRARY_PATH=/opt/openssl/lib:$LD_LIBRARY_PATH
15+
popd
16+
}
17+
18+
function install_curl {
19+
pushd /usr/src
20+
# Compile an up-to-date curl version that links to our own OpenSSL installation
21+
wget -q --no-check-certificate http://curl.haxx.se/download/curl-${1}.tar.gz
22+
tar xf curl-${1}.tar.gz
23+
cd curl-${1}
24+
./configure --with-ssl=/opt/openssl --prefix=/opt/curl > /dev/null
25+
make > /dev/null
26+
make install > /dev/null
27+
export PATH=/opt/curl/bin:$PATH
28+
popd
29+
}
30+
31+
function install_rust {
32+
curl https://static.rust-lang.org/rustup.sh > /tmp/rustup.sh
33+
chmod +x /tmp/rustup.sh
34+
/tmp/rustup.sh -y --disable-sudo --channel=$1
35+
}
36+
37+
function update_certificates {
38+
# Update the Root CA bundle
39+
wget -q --no-check-certificate \
40+
-O /etc/pki/tls/certs/ca-bundle.crt \
41+
http://curl.haxx.se/ca/cacert.pem
42+
}
43+
44+
function clean_project {
45+
# Remove compiled files that might cause conflicts
46+
pushd /io/
47+
rm -rf .cache .eggs rust_fst/_ffi.py build *.egg-info
48+
find ./ -name "__pycache__" -type d -print0 |xargs rm -rf --
49+
find ./ -name "*.pyc" -type f -print0 |xargs rm -rf --
50+
popd
51+
}
52+
453
OPENSSL_VERSION=1.0.2h
554
CURL_VERSION=7.49.0
655
RUST_CHANNEL=nightly
756

57+
# Clean build files
58+
clean_project
59+
60+
install_openssl $OPENSSL_VERSION
61+
install_curl $CURL_VERSION
62+
install_rust $RUST_CHANNEL
63+
864
# Remove old wheels
965
rm -rf /io/wheelhouse/* || echo "No old wheels to delete"
1066

1167
# We don't support Python 2.6
1268
rm -rf /opt/python/cp26*
1369

14-
# Override PATH and LD_LIBRARY so that our curl and openssl installations
15-
# get precedence over the included versions
16-
PATH=/opt/curl/bin:$PATH
17-
LD_LIBRARY_PATH=/opt/openssl/lib:$LD_LIBRARY_PATH
18-
1970
# Install libraries needed for compiling the extension
20-
yum -y install libffi-devel
21-
22-
# Update the Root CA bundle
23-
wget --no-check-certificate \
24-
-O /etc/pki/tls/certs/ca-bundle.crt \
25-
http://curl.haxx.se/ca/cacert.pem
26-
27-
# Compile and parallel-install a newer OpenSSL version so that curl can
28-
# download from the rust servers
29-
# Note that we cannot download from the official OpenSSL servers, since they
30-
# require HTTPS, which does not work with the CentOS5 SSL version...
31-
cd /usr/src
32-
wget http://ftp.vim.org/security/openssl/openssl-${OPENSSL_VERSION}.tar.gz
33-
tar xf openssl-${OPENSSL_VERSION}.tar.gz
34-
cd openssl-${OPENSSL_VERSION}
35-
./config --prefix=/opt/openssl shared
36-
make
37-
make install
38-
cd ..
39-
40-
# Compile an up-to-date curl version that links to our own OpenSSL installation
41-
wget --no-check-certificate http://curl.haxx.se/download/curl-${CURL_VERSION}.tar.gz
42-
tar xf curl-${CURL_VERSION}.tar.gz
43-
cd curl-${CURL_VERSION}
44-
./configure --with-ssl=/opt/openssl --prefix=/opt/curl
45-
make
46-
make install
47-
cd $HOME
48-
49-
# Install rust
50-
curl https://static.rust-lang.org/rustup.sh > /tmp/rustup.sh
51-
chmod +x /tmp/rustup.sh
52-
/tmp/rustup.sh -y --disable-sudo --channel=$RUST_CHANNEL
71+
yum -q -y install libffi-devel
5372

5473
# Compile wheels
5574
for PYBIN in /opt/python/*/bin; do
56-
${PYBIN}/python -m pip install pytest
57-
${PYBIN}/python -m pip wheel /io/ -w wheelhouse/
75+
${PYBIN}/python -m pip wheel /io/ -w /wheelhouse/
76+
clean_project
5877
done
5978

6079
# Move pure wheels to output wheelhouse
6180
mkdir -p /io/wheelhouse/
62-
mv wheelhouse/*any.whl /io/wheelhouse/ || echo "No pure wheels found."
81+
mv /wheelhouse/*any.whl /io/wheelhouse/ || echo "No pure wheels found."
6382

6483
# Bundle external shared libraries into the wheels
65-
for whl in wheelhouse/*.whl; do
84+
for whl in /wheelhouse/*.whl; do
6685
auditwheel repair $whl -w /io/wheelhouse/
6786
done
6887

@@ -71,9 +90,8 @@ chmod -R a+rw /io/wheelhouse
7190

7291
# Install packages and test
7392
for PYBIN in /opt/python/*/bin/; do
93+
${PYBIN}/python -m pip install pytest
7494
${PYBIN}/python -m pip install rust_fst --no-index -f /io/wheelhouse
7595
${PYBIN}/python -m pytest --verbose /io/tests
76-
rm -f /io/rust_fst/_ffi.py
77-
find /io -name "__pycache__" -type d -print0 |xargs rm -rf --
78-
find /io -name "*.pyc" -type f -print0 |xargs rm -rf --
96+
clean_project
7997
done

rust_setuptools.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
2-
""" Code by Armin Ronacher.
2+
""" Based on code by Armin Ronacher and James Salter
33
44
https://github.com/mitsuhiko/rust-setuptools
5+
https://github.com/novocaine/rust-python-ext
56
"""
67
from __future__ import print_function
78

@@ -12,6 +13,7 @@
1213

1314
from distutils.cmd import Command
1415
from distutils.command.install_lib import install_lib
16+
from distutils.dist import Distribution
1517

1618

1719
if sys.platform == 'win32':
@@ -22,6 +24,16 @@
2224
DYNAMIC_LIB_SUFFIX = '.so'
2325

2426

27+
class RustDistribution(Distribution):
28+
29+
def __init__(self, attrs=None):
30+
Distribution.__init__(self, attrs)
31+
self.ext_modules = []
32+
33+
def has_ext_modules(self):
34+
return True
35+
36+
2537
class RustBuildCommand(Command):
2638
description = 'build rust crates into Python extensions'
2739

@@ -35,6 +47,10 @@ def finalize_options(self):
3547
pass
3648

3749
def run(self):
50+
# Force binary wheel
51+
self.distribution.has_ext_modules = lambda: True
52+
self.distribution.ext_modules = []
53+
3854
# Make sure that if pythonXX-sys is used, it builds against the
3955
# current executing python interpreter.
4056
bindir = os.path.dirname(sys.executable)
@@ -111,7 +127,6 @@ class _RustBuildCommand(RustBuildCommand):
111127
'extra_cargo_args': extra_cargo_args,
112128
'quiet': quiet,
113129
}
114-
115130
return _RustBuildCommand
116131

117132

@@ -124,11 +139,3 @@ def build(self):
124139
if not self.skip_build:
125140
self.run_command('build_rust')
126141
return _RustInstallLibCommand
127-
128-
129-
def rust_crates(dist, attr, value):
130-
dist.has_ext_modules = lambda: True
131-
dist.ext_modules = []
132-
dist.cmdclass['build_rust'] = build_rust_cmdclass(value)
133-
dist.cmdclass['install_lib'] = build_install_lib_cmdclass(
134-
dist.cmdclass.get('install_lib'))

setup.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from setuptools import setup
22

3+
from rust_setuptools import (build_rust_cmdclass, build_install_lib_cmdclass,
4+
RustDistribution)
35

46
setup(
57
name='rust-fst',
@@ -17,11 +19,12 @@
1719
'pytest-runner'],
1820
install_requires=['cffi>=1.0.0'],
1921
cffi_modules=['rust_fst/_build_ffi.py:ffi'],
20-
entry_points={'distutils.setup_keywords': [
21-
'rust_crates = rust_setuptools:rust_crates'
22-
]},
2322
tests_require=['pytest'],
24-
rust_crates=[('fstwrapper', 'rust_fst')],
23+
distclass=RustDistribution,
24+
cmdclass={
25+
'build_rust': build_rust_cmdclass([('fstwrapper', 'rust_fst')]),
26+
'install_lib': build_install_lib_cmdclass()
27+
},
2528
packages=['rust_fst'],
2629
zip_safe=False,
2730
classifiers=[

0 commit comments

Comments
 (0)