codypiersall / pynng

Python bindings for Nanomsg Next Generation.
https://pynng.readthedocs.io
MIT License
260 stars 58 forks source link

'pip3 install -e .' fails on MacOS #89

Open The-QA-Geek opened 2 years ago

The-QA-Geek commented 2 years ago

At least on my M1, 'pip3 install -e .' fails with this error:

'clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -Inng/include -I/Users/leslie/.pyenv/versions/3.9.6/envs/python-build/include -I/Users/leslie/.pyenv/versions/3.9.6/include/python3.9 -c build/temp.macosx-11.4-arm64-3.9/pynng._nng.c -o build/temp.macosx-11.4-arm64-3.9/build/temp.macosx-11.4-arm64-3.9/pynng._nng.o clang -bundle -undefined dynamic_lookup -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/readline/lib -L/Users/leslie/.pyenv/versions/3.9.6/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/readline/lib -L/Users/leslie/.pyenv/versions/3.9.6/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib build/temp.macosx-11.4-arm64-3.9/build/temp.macosx-11.4-arm64-3.9/pynng._nng.o ./nng/build/libnng.a ./mbedtls/prefix/lib/libmbedtls.a ./mbedtls/prefix/lib/libmbedx509.a ./mbedtls/prefix/lib/libmbedcrypto.a -lpthread -latomic -o build/lib.macosx-11.4-arm64-3.9/pynng/_nng.abi3.so ld: library not found for -latomic clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command '/usr/bin/clang' failed with exit code 1

'python setup.py bdist_wheel' fails with the same missing library.

I don't know whether that is a missing source file or a missing dependency on my Mac (it looks more like a missing dependency on my Mac), but I haven't been able to find any information on the 'atomic' library. If someone could explain how to fix this I would greatly appreciate it, and it might help other people using the M1 Macs.

The-QA-Geek commented 2 years ago

Would anyone like to be paid to solve this? If so, how much would you charge and how long will it take?

codypiersall commented 2 years ago

Thanks for opening an issue here—a month ago! Sorry for the lack of an update. Things have been busy.

The problem I believe is the hacky solution I came up with to track the system libraries that need to be linked in order to use pynng. Even when I did the fix i noted how bad it was 1a7ad771a43d3c486ffa9b08d92be43b44fd25db: commit message was "Fix (still really bad) heuristic for when to link libatomic."

The better way is to somehow use CMake to determine what libraries need to be linked with—possible build pynng as a shared library.

For your situation, for now, possibly it will work to just not link libatomic. If you change line 32 of build_pynng.py to not add libatomic it may build on the new M1. I don't have a Mac, let alone one of the new ones, so I can't test it... but hopefully it will work!

I'm not at a point where I can spend much time on open source at the present, and although I genuinely appreciate the offer of payment my main problem right now is time, not interest or money. Of course I can't speak for anyone else, others are free to do as they wish!

The-QA-Geek commented 2 years ago

Sweet; that lets me build pynng on an M1 Mac. I have a bit more work to do before I can actually pass messages through pynng to a receiver; that will confirm that everything really works. I should be able to do that on Monday.

I had already tried 'brew install libatomic_ops', but that didn't help.

I will post updated status, pass or fail, in a few days.

The-QA-Geek commented 2 years ago

Commenting out Lines 32 and 33 works; I was able to send and receive messages. Thank you very much for the help.

regcs commented 2 years ago

We are currently also struggling with that M1 issue. Is there any way to build pynng for M1 from an Intel Mac?

The-QA-Geek commented 2 years ago

I was able to build it on my M1 Mac simply by commenting out lines 32 and 33. I didn't have to install any other libraries or special tools.

regcs commented 2 years ago

That is good to know. But I don't have a M1 Mac available and I am wondering: How would I build a wheel for it from an Intel Mac?

regcs commented 2 years ago

Ok, I found a way. Commenting lines 32 and 33 above out and using a GitHub Action I was now able to cross-compile a "universal2" wheel, which works on both Intel and M1 chips:

https://github.com/regcs/pynng/blob/master/.github/workflows/cibuildwheel.yml

@codypiersall: Would it make sense to prepare a pull request for that cross-compilation? Then you could make a new release and upload the M1 compatible wheels to PyPI so that others could pip install pynng.

janosh commented 2 years ago

@regcs Thanks for figuring this out. A PR that fixes this would be great!

lingster commented 2 years ago

@janosh : I have just submitted PR #100 to fix this issue.

regcs commented 2 years ago

@janosh: Sorry for the late response!😅

Since @lingster's PR #100 seems to fail, I created a new PR #102. This also adds support for Python 3.10 (#98) in addition to Apple Silicon compatibility. I hope @codypiersall finds some time to merge the PR and upload the new wheels to PyPi so that it can be pip installed.

codypiersall commented 1 year ago

If you can post more of the build log I might be able to help. I don't have a Mac so I can't test anything on my end. The chunk you posted doesn't actually have the error in it, unfortunately, at least not the specifics.