Skip to content

Commit 3ccc48c

Browse files
committed
Add linux wheels build step
1 parent 83d178d commit 3ccc48c

3 files changed

Lines changed: 52 additions & 115 deletions

File tree

.github/workflows/build.yml

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ jobs:
5353
strategy:
5454
fail-fast: False
5555
matrix:
56-
os: [ ubuntu-latest, macos-latest ]
56+
os: [ ubuntu-latest ]
57+
# os: [ ubuntu-latest, macos-latest ]
5758
steps:
5859
- name: Checkout repository
5960
uses: actions/checkout@v2
@@ -65,26 +66,42 @@ jobs:
6566
with:
6667
python-version: 3.8
6768

68-
# - name: Build wheels
69-
# env:
70-
# # only build CPython-3.6 and later and skip 32-bit builds
71-
# CIBW_BUILD: cp36-* cp37-* cp38-*
72-
# CIBW_BEFORE_ALL_LINUX: yum update -y && yum install pcre-devel -y
73-
# CIBW_BEFORE_ALL_MACOS: brew install swig
74-
# CIBW_BEFORE_BUILD: python -m pip install -u pip numpy cibuildwheel==1.5.1
75-
# CIBW_BEFORE_BUILD_LINUX: |
76-
# scripts/install_swig.sh
77-
# python -m pip install cmake
78-
# CIBW_TEST_COMMAND: python {project}/extern/nlopt/test/t_python.py
79-
# run: python -m cibuildwheel --output-dir dist
69+
- name: Build wheels
70+
env:
71+
# only build CPython-3.6 and later and skip 32-bit builds and skip windows
72+
CIBW_BUILD: cp36-* cp37-* cp38-*
73+
CIBW_SKIP: "*-win* *-manylinux_i686"
74+
CIBW_BEFORE_ALL_LINUX: |
75+
yum update -y && yum install pcre-devel cmake3 -y
76+
yum remove cmake -y
77+
ln -s /usr/bin/cmake3 /usr/bin/cmake
78+
79+
if [[ ! -e $(command -v swig) ]]; then
80+
curl -L https://sourceforge.net/projects/swig/files/swig/swig-4.0.2/swig-4.0.2.tar.gz/download --output /tmp/swig.tar.gz
81+
mkdir /tmp/swig
82+
tar -xvzf /tmp/swig.tar.gz -C /tmp/swig --strip-components 1 &> /dev/null
83+
pushd /tmp/swig
84+
./configure --without-alllang --with-python3 && make -j2 && make install > /dev/null
85+
popd
86+
fi
87+
CIBW_BEFORE_ALL_MACOS: brew install swig
88+
CIBW_BEFORE_BUILD: pip install numpy
89+
run: |
90+
pip install -U pip cibuildwheel==1.5.1
91+
python -m cibuildwheel --output-dir dist
92+
93+
- name: Place wheels in artifacts folder
94+
uses: actions/upload-artifact@v2
95+
with:
96+
path: ./dist/*.whl
8097

8198
test-wheels:
8299
name: Test package installation
83-
needs: [ build_wheels_windows ]
100+
needs: [ build_wheels_windows, build_wheels_unix ]
84101
runs-on: ${{ matrix.os }}
85102
strategy:
86103
matrix:
87-
os: [ windows-latest ]
104+
os: [ windows-latest, ubuntu-latest ]
88105
python-version: [ 3.6, 3.7, 3.8 ]
89106

90107
steps:
@@ -104,6 +121,7 @@ jobs:
104121

105122
- name: Test Package Installation
106123
run: |
124+
ls -alR dist
107125
python -m pip install --upgrade pip
108126
109127
# finds path to the right wheel or source file to install later

extensions.py

Lines changed: 19 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -25,88 +25,20 @@ def run(self):
2525
except OSError:
2626
raise RuntimeError("CMake must be installed")
2727

28+
if platform.system() not in ("Windows", "Linux", "Darwin"):
29+
raise RuntimeError(f"Unsupported os: {platform.system()}")
30+
2831
for ext in self.extensions:
2932
if isinstance(ext, NLOptBuildExtension):
3033
self.build_extension(ext)
3134

32-
@property
33-
def nlopt_dir(self):
34-
return Path(__file__).parent / "tern" / "nlopt"
35-
3635
@property
3736
def config(self):
3837
return "Debug" if self.debug else "Release"
3938

40-
def cmake_args(self, ext_dir: str):
41-
prefix = "NLOPT_BUILD"
42-
43-
args = [
44-
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={ext_dir}",
45-
f"-DPYTHON_EXECUTABLE={sys.executable}",
46-
# don't build for matlab and others
47-
"-DNLOPT_GUILE=OFF",
48-
"-DNLOPT_MATLAB=OFF",
49-
"-DNLOPT_OCTAVE=OFF"]
50-
51-
if platform.system() == "Windows":
52-
args += [
53-
"-LAH",
54-
f'-DCMAKE_PREFIX_PATH="{prefix}"',
55-
f'-DCMAKE_INSTALL_PREFIX="{prefix}"'
56-
]
57-
elif platform.system() in ("Linux", "Darwin"):
58-
args += [
59-
f"-DCMAKE_PREFIX_PATH={prefix}",
60-
f"-DCMAKE_INSTALL_PREFIX={prefix}",
61-
"-DCMAKE_INSTALL_LIBDIR=lib",
62-
]
63-
else:
64-
raise RuntimeError(f"Unsupported os: {platform.system()}")
65-
66-
return args
67-
6839
def build_extension(self, ext: Extension):
6940
# - make sure path ends with delimiter
7041
# - required for auto-detection of auxiliary "native" libs
71-
ext_dir = Path(self.get_ext_fullpath(ext.name)).parent.absolute().as_posix()
72-
if not ext_dir.endswith(os.path.sep):
73-
ext_dir += os.path.sep
74-
75-
if platform.system() == "Windows":
76-
self._build_windows(ext)
77-
return
78-
79-
exit(1)
80-
81-
cmake_args = [
82-
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + ext_dir,
83-
"-DPYTHON_EXECUTABLE=" + sys.executable,
84-
]
85-
86-
cfg = "Debug" if self.debug else "Release"
87-
build_args = ["--config", cfg]
88-
89-
if platform.system() == "Windows":
90-
cmake_args += [f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={ext_dir}"]
91-
if sys.maxsize > 2 ** 32:
92-
cmake_args += ["-A", "x64"]
93-
build_args += (["--", "/m"])
94-
else:
95-
build_args += ["--", "-j2"]
96-
97-
env = os.environ.copy()
98-
env["CXXFLAGS"] = f'{env.get("CXXFLAGS", "")} -DVERSION_INFO="{self.distribution.get_version()}"'
99-
100-
build_temp = Path(self.build_temp)
101-
build_temp.mkdir(parents=True, exist_ok=True)
102-
103-
check_call(["cmake", ext.sourcedir, *cmake_args], cwd=self.build_temp, env=env)
104-
check_call(["cmake", "--build", ".", *build_args], cwd=self.build_temp)
105-
106-
nlopt_py = next(Path(self.build_temp).rglob("nlopt.py"))
107-
nlopt_py.rename(Path(ext_dir) / "__init__.py")
108-
109-
def _build_windows(self, ext: NLOptBuildExtension):
11042
ext_dir = Path(self.get_ext_fullpath(ext.name)).parent.absolute()
11143
_ed = ext_dir.as_posix()
11244
if not _ed.endswith(os.path.sep):
@@ -115,18 +47,22 @@ def _build_windows(self, ext: NLOptBuildExtension):
11547
build_dir = create_directory(Path(self.build_temp))
11648

11749
# package builds in 2 steps, first to compile the nlopt package and second to build the DLL
50+
cmd = [
51+
"cmake",
52+
"-LAH",
53+
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={_ed}",
54+
f"-DPYTHON_EXECUTABLE={sys.executable}",
55+
"-DNLOPT_GUILE=OFF",
56+
"-DNLOPT_MATLAB=OFF",
57+
"-DNLOPT_OCTAVE=OFF",
58+
ext.source_dir.as_posix()
59+
]
60+
61+
if platform.system() == "Windows":
62+
cmd.insert(2, f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{self.config.upper()}={_ed}")
63+
11864
execute_command(
119-
cmd=[
120-
"cmake",
121-
"-LAH",
122-
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={_ed}",
123-
f"-DPYTHON_EXECUTABLE={sys.executable}",
124-
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{self.config.upper()}={_ed}",
125-
"-DNLOPT_GUILE=OFF",
126-
"-DNLOPT_MATLAB=OFF",
127-
"-DNLOPT_OCTAVE=OFF",
128-
ext.source_dir.as_posix()
129-
],
65+
cmd=cmd,
13066
cwd=build_dir,
13167
env={
13268
**os.environ.copy(),
@@ -141,7 +77,7 @@ def _build_windows(self, ext: NLOptBuildExtension):
14177
'--config',
14278
self.config,
14379
"--",
144-
"-m"
80+
"-m" if platform.system() == "Windows" else "-j2"
14581
], cwd=build_dir)
14682

14783
# Copy over the important bits

scripts/install_swig.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)