DanielBok / nlopt-python

A project to package the NLOpt library to wheels
Other
29 stars 14 forks source link

Support for Mac OSX #1

Closed Doggie52 closed 4 years ago

Doggie52 commented 4 years ago

Hey, would be great to see Mac OSX support for this. I tried running build.sh on my machine and got to this stage:

Install the project...
-- Install configuration: "Release"
-- Installing: /stevengj/nlopt/install/lib/pkgconfig/nlopt.pc
-- Installing: /stevengj/nlopt/install/include/nlopt.h
-- Installing: /stevengj/nlopt/install/include/nlopt.hpp
-- Installing: /stevengj/nlopt/install/include/nlopt.f
-- Installing: /stevengj/nlopt/install/lib/libnlopt.0.10.0.dylib
-- Installing: /stevengj/nlopt/install/lib/libnlopt.0.dylib
-- Installing: /stevengj/nlopt/install/lib/libnlopt.dylib
-- Installing: /stevengj/nlopt/install/lib/cmake/nlopt/NLoptLibraryDepends.cmake
-- Installing: /stevengj/nlopt/install/lib/cmake/nlopt/NLoptLibraryDepends-release.cmake
-- Installing: /stevengj/nlopt/install/lib/cmake/nlopt/NLoptConfig.cmake
-- Installing: /stevengj/nlopt/install/lib/cmake/nlopt/NLoptConfigVersion.cmake
-- Installing: /stevengj/nlopt/install/share/man/man3/nlopt.3
-- Installing: /stevengj/nlopt/install/share/man/man3/nlopt_minimize.3
-- Installing: /stevengj/nlopt/install/share/man/man3/nlopt_minimize_constrained.3
cp: directory /app/nlopt does not exist
build.sh: line 49: /opt/python/cp37-cp37m/bin/pip: No such file or directory
build.sh: line 53: auditwheel: command not found

Fair enough, that may not be the intended way of generating the wheels but as there are no Mac wheels built on pypi, I suspect it's not officially supported yet.

DanielBok commented 4 years ago

@Doggie52, sorry I missed your message. I believe there's a way to generate the osx wheels. The issue is that I don't have a mac to test out the builds.

The general idea is quite similar to the windows and linux builds.

  1. Compile the nlopt source
    
    cmake -DCMAKE_PREFIX_PATH=${PREFIX} \
    -DCMAKE_INSTALL_PREFIX=${PREFIX} \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DNLOPT_GUILE=OFF \
    -DNLOPT_MATLAB=OFF \
    -DNLOPT_OCTAVE=OFF \
    -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
    -DPYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") \
    ..

generate the .so binaries

make && make install



This is done with gcc on linux. I think you can use clang for the same effect with mac.

2. Then copy the binary in <path>/<to>/lib/python<PY.VER>/site-packages/* over to the 
nlopt module folder.

3. Build the package via `python setup.py bdist_wheel --python-tag cp${PY_VER} --plat-name macosx_10_9_x86_64`

You don't have to use `auditwheel`. That is a tool to convert a linux binary to manylinux binary as there are many flavours of linux.

You should be done then. While the binaries look similar, you'll have to compile a separate one for each version of python. e.g. I compile py37 and py38 separately.
DanielBok commented 4 years ago

@Doggie52, we've added builds for osx now