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

fix: Add libdir to library search path #2476

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shs96c
Copy link
Contributor

@shs96c shs96c commented Dec 6, 2024

We discovered when dealing with libraries such as psycopg2 that the wheel would attempt to link against libpython.a. This fix points the linker at the correct python version being used.

Copy link
Collaborator

@aignas aignas left a comment

Choose a reason for hiding this comment

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

Because this is gated by a feature toggle, it seems to be low risk to include.

@@ -15,6 +15,12 @@
"common attributes for whl_library and pip_repository"

ATTRS = {
"add_libdir_to_library_search_path": attr.bool(
Copy link
Collaborator

Choose a reason for hiding this comment

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

NOTE: this is enabled for both, WORKSPACE and bzlmod: https://rules-python--2476.org.readthedocs.build/en/2476/api/rules_python/python/extensions/pip.html#pip.parse.add_libdir_to_library_search_path

However, bzlmod will not forward this value to underlying whl_library instances, so extension.bzl needs to be updated. I think we should only forward this value to whl_libraries that are following the legacy pip way of downloading deps or downloading an sdist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how to do this. Can you give me a pointer in the right direction, please?

if result.return_code != 0:
fail("Failed to get LDFLAGS path: command: {}, exit code: {}, stdout: {}, stderr: {}".format(command, result.return_code, result.stdout, result.stderr))
libdir = result.stdout
env["LDFLAGS"] = "-L{}".format(libdir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we instead extend the LDFLAGS instead of replacing the value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On line 151 we've checked to make sure that env["LDFLAGS"] hasn't been set. We know we're not replacing anything at this point

@rickeylev
Copy link
Collaborator

Just want to respond to something the comment says:

# [calling the python interpreter in repo-phase]
# is super hacky, but working out something nice is tricky.
# This is in particular needed for psycopg2 which attempts to link libpython.a,
# in order to point the linker at the correct python intepreter.

It's not possible to reliably get the correct Python interpreter. This is because the repo phase doesn't know, and can't know, what the build phase is going to do (i.e. what python interpreter will be used). The basic change in this PR is somewhat an improvement, but yeah -- just wanted to point out it'll still be prone to issues. To really fix this, the sdist building needs to move into the build phase.

@aignas
Copy link
Collaborator

aignas commented Dec 8, 2024

I'll add some ideas about this in #2410.

@shs96c
Copy link
Contributor Author

shs96c commented Dec 19, 2024

Is there anything else you'd like me to do for this PR?

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.

3 participants