You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 8, 2020. It is now read-only.
$ pip install bblfsh
$ python
Python 3.6.5 (default, Jun 17 2018, 12:13:06)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bblfsh
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/smacker/tmp/json-uast/venv/lib/python3.6/site-packages/bblfsh/__init__.py", line 1, in <module>
from bblfsh.client import BblfshClient
File "/Users/smacker/tmp/json-uast/venv/lib/python3.6/site-packages/bblfsh/client.py", line 9, in <module>
from bblfsh.result_context import ResultContext
File "/Users/smacker/tmp/json-uast/venv/lib/python3.6/site-packages/bblfsh/result_context.py", line 2, in <module>
from bblfsh.node import Node
File "/Users/smacker/tmp/json-uast/venv/lib/python3.6/site-packages/bblfsh/node.py", line 5, in <module>
from bblfsh.pyuast import NodeExt
ImportError: dlopen(/Users/smacker/tmp/json-uast/venv/lib/python3.6/site-packages/bblfsh/pyuast.cpython-36m-darwin.so, 2): Symbol not found: _UastDecode
Referenced from: /Users/smacker/tmp/json-uast/venv/lib/python3.6/site-packages/bblfsh/pyuast.cpython-36m-darwin.so
Expected in: flat namespace
in /Users/smacker/tmp/json-uast/venv/lib/python3.6/site-packages/bblfsh/pyuast.cpython-36m-darwin.so
$ python -V
Python 3.6.5
$ pip list
Package Version
---------------- --------
bblfsh 3.0.3
...
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.3
BuildVersion: 18D109
So the basic issue here is that libuast.so is not being pulled in to resolve the undefined symbols in the shared library. I am able to make it work by manually opening that .so prior to import, e.g.,
This is obviously not a fix, but it suggests we might need to add some additional bits to the setup.py and/or the installation instructions for macOS to ensure we have that .so on the loader's path.
I'm having trouble reproducing the exact environment we get from the pip3 installation, but it looks like the setup.py fetches libuast.so for the wrong architecture on macOS: Specifically, it fixes LIBUAST_ARCH = "linux-amd64" and does not update it from the ambient.
When building, this means we wind up linking against the wrong thing:
$ python3 setup.py build_ext -i
[…]
ld: warning: ignoring file bblfsh/libuast/libuast.a, file was built for archive
which is not the architecture being linked (x86_64): bblfsh/libuast/libuast.a
But I suppose ld considers this a "warning" because it's building a shared library, and it's possible that we have the "right" one installed elsewhere. (In this case, we do not).
So I think the proximal fix here is for us to derive the architecture string from the environment. I think we do not see this in CI because everything is built in Docker containers, all of which run variations of Linux.
Setting the architecture from sys.platform gets us the correct release, but the Darwin release binary does not contain a static libuast.a. It does contain a libuast.so.
The setup script presently assumes there will be a libuast.a and includes it as data for the bblfsh.pyuast external package, but of course on macOS that doesn't exist. Including libuast.so instead doesn't work as-written; the linker doesn't include the file, so once the link is complete the installed .so is still missing symbols.
Distutils is correctly flagging the output .so as a bundle, at least. Next I will see if I can build a static libuast.a manually, and see if that helps. (This is a little tricky on macOS, but I will kludge it for the sake of the experiment).
I manually built libuast.a via go build -mode=c-archive, and copied it into my build tree with GET_LIBUAST set to false. This permits a python3 setup.py install to produce a working extension.
I still have some work to do, because Apple's clang seems by default to prefer a .so if one is available. However, I think we're getting closer to a solution.
I still have some work to do, because Apple's clang seems by default to prefer a .so if one is available
This turned out not to be a problem because our config explicitly names the .a files to be linked on the command line, rather than pulling them in by path. (We do also reference the path, but fortunately explicit arguments supersede library search).
Activity
creachadair commentedon May 1, 2019
So the basic issue here is that
libuast.sois not being pulled in to resolve the undefined symbols in the shared library. I am able to make it work by manually opening that.soprior to import, e.g.,This is obviously not a fix, but it suggests we might need to add some additional bits to the
setup.pyand/or the installation instructions for macOS to ensure we have that.soon the loader's path.creachadair commentedon May 2, 2019
I'm having trouble reproducing the exact environment we get from the
pip3installation, but it looks like thesetup.pyfetcheslibuast.sofor the wrong architecture on macOS: Specifically, it fixesLIBUAST_ARCH = "linux-amd64"and does not update it from the ambient.When building, this means we wind up linking against the wrong thing:
$ python3 setup.py build_ext -i […] ld: warning: ignoring file bblfsh/libuast/libuast.a, file was built for archive which is not the architecture being linked (x86_64): bblfsh/libuast/libuast.aBut I suppose
ldconsiders this a "warning" because it's building a shared library, and it's possible that we have the "right" one installed elsewhere. (In this case, we do not).So I think the proximal fix here is for us to derive the architecture string from the environment. I think we do not see this in CI because everything is built in Docker containers, all of which run variations of Linux.
creachadair commentedon May 2, 2019
Setting the architecture from
sys.platformgets us the correct release, but the Darwin release binary does not contain a staticlibuast.a. It does contain alibuast.so.The setup script presently assumes there will be a
libuast.aand includes it as data for thebblfsh.pyuastexternal package, but of course on macOS that doesn't exist. Includinglibuast.soinstead doesn't work as-written; the linker doesn't include the file, so once the link is complete the installed.sois still missing symbols.Distutils is correctly flagging the output
.soas a bundle, at least. Next I will see if I can build a staticlibuast.amanually, and see if that helps. (This is a little tricky on macOS, but I will kludge it for the sake of the experiment).creachadair commentedon May 2, 2019
I manually built
libuast.aviago build -mode=c-archive, and copied it into my build tree withGET_LIBUASTset to false. This permits apython3 setup.py installto produce a working extension.I still have some work to do, because Apple's
clangseems by default to prefer a.soif one is available. However, I think we're getting closer to a solution.creachadair commentedon May 2, 2019
This turned out not to be a problem because our config explicitly names the
.afiles to be linked on the command line, rather than pulling them in by path. (We do also reference the path, but fortunately explicit arguments supersede library search).creachadair commentedon May 2, 2019
Things to fix:
libuast.afor macOS releases (Link a static version of libuast for Darwin. libuast#101).bblfshPyPI package (https://github.com/bblfsh/client-python/releases/tag/v3.0.4).Link a static version of libuast for Darwin.
creachadair commentedon May 3, 2019
I can confirm this now works after release of v3.0.4.