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
This describes a modifcation to the py_executable-based rules and intersects with
py_test
py_binary
py_library
cc_import / cc_library
Description
When a py_test depends on a python extension module that was not built within bazel, the DT_NEEDED entries cannot be resolved in a hermetic environment because the imported extension module (DSO) will be missing or have an incorrect runpath / rpath.
I believe this is substantially different from #2562 such that it warrants its own feature request.
Given some new py_xxx argument or --@rules_python//python/config_settings flag, we would inspect cc_info.linking_context.linker_inputs.to_list() from inside _create_run_environment_info() and inject / extend LD_LIBRARY_PATH in the RunEnvironmentInfo.environment with the path(s) to the dependent dynamic libraries (see the "Sample Patch" below for details).
I think this would also be doable using a wrapper-generating rule, but it's not super clear to me how well it would interact with the existing sh / python wrapper script for py executable rules.
Instead of setting RunEnvironmentInfo.environment, this could be added to the existing wrapper (shell or python depending on bootstrap_impl).
The text was updated successfully, but these errors were encountered:
instead of using RunEnvironmentInfo, set it in bootstrap
RunEnvironmentInfo can't be used because those values are only respected for bazel test or bazel run. So yes, setting LD_LIBRARY_PATH has to be done in the bootstrap.
I don't like setting LD_LIBRARY_PATH, but its the only tool we have available when we're given a prebuilt binary that we can't modify. Well, maybe not only tool. The other option is to modify the interpreter at build time to add some rpath entries. LD_LIBRARY_PATH is a simpler, though.
Don't sort the path entries, though -- order matters because the first library to be loaded and define a symbol wins. I think the libs will be in "top down" order (i.e. a target closer to the binary comes earlier in the ordering), which allows a binary to control ordering in case deps further away aren't in an order it needs.
The logic in your diff looks pretty good otherwise.
I'm not sure the logic has to loop over everything though. I think CcToolchainInfo.solib_dir has the directory that dynamically loaded libs get put into, though I don't remember offhand if that's publicly accessible. The py_internal.cc_helper object might provide a way to get at it if its not.
If you look at the paths for the artifacts in cc_info, you should see paths like e.g. _solib_<something>/libfoo.so -- thats the directory i'm talking about.
🚀 feature request
Relevant Rules
This describes a modifcation to the
py_executable
-based rules and intersects withpy_test
py_binary
py_library
cc_import
/cc_library
Description
When a
py_test
depends on a python extension module that was not built within bazel, theDT_NEEDED
entries cannot be resolved in a hermetic environment because the imported extension module (DSO) will be missing or have an incorrect runpath / rpath.I believe this is substantially different from #2562 such that it warrants its own feature request.
I've provided a minimal test case here: https://github.com/wade-arista/bazel-demo/tree/min-py-ext-case#overview where it simulates the external dynamic libs by using
chrpath
to remove RPATH and then re-imports the built libs. I also brought it up on slack.Describe the solution you'd like
Given some new
py_xxx
argument or--@rules_python//python/config_settings
flag, we would inspectcc_info.linking_context.linker_inputs.to_list()
from inside_create_run_environment_info()
and inject / extendLD_LIBRARY_PATH
in theRunEnvironmentInfo.environment
with the path(s) to the dependent dynamic libraries (see the "Sample Patch" below for details).Sample Patch
Describe alternatives you've considered
RunEnvironmentInfo.environment
, this could be added to the existing wrapper (shell or python depending onbootstrap_impl
).The text was updated successfully, but these errors were encountered: