Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtualenv links against wrong python #978 #1001

Merged
merged 6 commits into from Jul 9, 2019
Merged

Conversation

themperek
Copy link
Contributor

Addressing #978. It seems cleaner.

PS. In case this gets accepted please squash.

@imphil
Copy link
Member

imphil commented Jul 9, 2019

Thanks for this improvement @themperek, looks cleaner indeed.

However, I'm a bit worried about the performance impact of calling Python multiple times. Can we get away with calling PYTHON_BIN once, and then letting make split the result into the individual variables?

@themperek
Copy link
Contributor Author

Can we get away with calling PYTHON_BIN once, and then letting make split the result into the individual variables?

We can but then we need to parse this with some Unix tools and this will be ugly (in my opinion).

@eric-wieser
Copy link
Member

What if we invoked python once, and had it output makefile syntax? $(eval $(shell cocotb-config get-makefile-vars))

@themperek
Copy link
Contributor Author

Seems like we still (how long @imphil ?) want to be able to use cocotb without cocotb-config?

endif

PYLIBS = $(shell $(PY_CFG_EXE) --libs)
PYLIBS:=$(shell $(PYTHON_BIN) -c 'from __future__ import print_function; from distutils import sysconfig; import os; print("-l"+os.path.splitext(sysconfig.get_config_var("LIBRARY"))[0][3:])')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the implementation of python-config.py, the implementation should be something like:

    elif opt in ('--libs', '--ldflags'):
        libs = []
        if '--embed' in opt_flags:
            libs.append('-lpython' + pyver + sys.abiflags)
        else:
            libpython = getvar('LIBPYTHON')
            if libpython:
                libs.append(libpython)
        libs.extend(getvar('LIBS').split() + getvar('SYSLIBS').split())

        # add the prefix/lib/pythonX.Y/config dir, but only if there is no
        # shared library in prefix/lib/.
        if opt == '--ldflags':
            if not getvar('Py_ENABLE_SHARED'):
                libs.insert(0, '-L' + getvar('LIBPL'))
        print(' '.join(libs))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should wait with all those changes until we can use cocotb-config.

@imphil
Copy link
Member

imphil commented Jul 9, 2019

Make can do word-splitting natively with $(word n,text) (https://www.gnu.org/software/make/manual/html_node/Text-Functions.html), with one important limitation: spaces spaces in paths are not supported. This is a general make limitation, not only for this function.

However, it feels to me that the "no spaces in paths" rule wasn't as important until now as most paths to source files are relative. With absolute paths and Windows added to the mix it's a whole different story.

So:

  • I'd take this patch as-is, as it strictly improves things.
  • Open a follow-up trying to find a sane way to avoid these multiple calls to an external tool, be it PYTHON_BIN or cocotb-config. (It's the same overhead.)

@imphil
Copy link
Member

imphil commented Jul 9, 2019

Seems like we still (how long @imphil ?) want to be able to use cocotb without cocotb-config?

We can require cocotb-config. We just cannot require it being installed into PATH. Instead, we need to look it up from the old COCOTB environment variable. (I will do that in #990 when I find time for it, hopefully in the next couple of days.)

@themperek
Copy link
Contributor Author

themperek commented Jul 9, 2019

Alternatively, we go into the direction to generate some makefile (with cocotb-config?) with all this configuration handled in python?

Edit: Can be done once during setup.

Copy link
Member

@imphil imphil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this PR now, as it strictly improves things and fixes an actual bug. @themperek please open a new issue/PR to capture the further enhancements we discussed, there were some really nice ideas. However, I'd like to keep this PR focused on the actual fix. Is this PR ready to go in from your side @themperek?

@themperek
Copy link
Contributor Author

It looks to me it is OK. And seems to work across diffrent build environments.
The objection I would have is that "LDLIBRARY"/"LIBRARY" variable is not really documented although a GitHub search suggests this is widely used.

@imphil imphil merged commit 7937072 into cocotb:master Jul 9, 2019
@imphil imphil added this to the 1.2 milestone Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants