Skip to content

Commit b4ec825

Browse files
authored
fix: explicitly symlink all .so files, not just ones with lib prefix (#3538)
Some packages, such as tensorflow, have regular C libraries that don't use a `lib*` suffix. The symlink optimization logic wouldn't link these directly, which made the dynamic linker unable to find their dependencies. To fix, explicitly symlink all `.so` files, since we can't determine which are Python C modules and regular C libraries. Fixes #3529
1 parent 044eb26 commit b4ec825

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ END_UNRELEASED_TEMPLATE
8383
that are associated with the target's `srcs` are present.
8484
([#3354](https://github.com/bazel-contrib/rules_python/issues/3354)).
8585

86+
{#v1-8-2}
87+
## [1.8.2] - 2026-01-24
88+
89+
{#v1-8-2-fixed}
90+
### Fixed
91+
* (venvs) relax the C library filename check to make tensorflow work
92+
Fixes [#3524](https://github.com/bazel-contrib/rules_python/issues/3529).
93+
8694
{#v1-8-1}
8795
## [1.8.1] - 2026-01-20
8896

python/private/venv_runfiles.bzl

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,18 +452,11 @@ def get_venv_symlinks(
452452
def _is_linker_loaded_library(filename):
453453
"""Tells if a filename is one that `dlopen()` or the runtime linker handles.
454454
455-
This should return true for regular C libraries, but false for Python
456-
C extension modules.
457-
458-
Python extensions: .so (linux, mac), .pyd (windows)
459-
460-
C libraries: lib*.so (linux), lib*.so.* (linux), lib*.dylib (mac), .dll (windows)
455+
C libraries: *.so (linux), *.so.* (linux), *.dylib (mac), .dll (windows)
461456
"""
462457
if filename.endswith(".dll"):
463458
return True
464-
if filename.startswith("lib") and (
465-
filename.endswith((".so", ".dylib")) or ".so." in filename
466-
):
459+
if filename.endswith((".so", ".dylib")) or ".so." in filename:
467460
return True
468461
return False
469462

tests/venv_site_packages_libs/app_files_building/app_files_building_tests.bzl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _test_optimized_grouping_complex(name):
136136
name = name + "_files",
137137
paths = [
138138
"site-packages/pkg1/a.txt",
139-
"site-packages/pkg1/b/b_mod.so",
139+
"site-packages/pkg1/b/b_mod_so",
140140
"site-packages/pkg1/c/c1.txt",
141141
"site-packages/pkg1/c/c2.txt",
142142
"site-packages/pkg1/d/d1.txt",
@@ -147,6 +147,10 @@ def _test_optimized_grouping_complex(name):
147147
"site-packages/pkg1/q1/q2a/q3/q3a.txt",
148148
"site-packages/pkg1/q1/q2a/q3/q3b.txt",
149149
"site-packages/pkg1/q1/q2b/q2b.txt",
150+
"site-packages/pkg1/q1/q2c/c_mod.so",
151+
"site-packages/pkg1/q1/q2c/q2.txt",
152+
"site-packages/pkg1/q1/q2c/q3/q3a.txt",
153+
"site-packages/pkg1/q1/q2c/q3/q3b.txt",
150154
],
151155
)
152156
analysis_test(
@@ -181,7 +185,7 @@ def _test_optimized_grouping_complex_impl(env, target):
181185
"pkg1/b",
182186
link_to_path = rr + "pkg1/b",
183187
files = [
184-
"tests/venv_site_packages_libs/app_files_building/site-packages/pkg1/b/b_mod.so",
188+
"tests/venv_site_packages_libs/app_files_building/site-packages/pkg1/b/b_mod_so",
185189
],
186190
),
187191
_venv_symlink("pkg1/c", link_to_path = rr + "pkg1/c", files = [
@@ -210,6 +214,16 @@ def _test_optimized_grouping_complex_impl(env, target):
210214
_venv_symlink("pkg1/q1/q2b", link_to_path = rr + "pkg1/q1/q2b", files = [
211215
"tests/venv_site_packages_libs/app_files_building/site-packages/pkg1/q1/q2b/q2b.txt",
212216
]),
217+
_venv_symlink("pkg1/q1/q2c/c_mod.so", link_to_path = rr + "pkg1/q1/q2c/c_mod.so", files = [
218+
"tests/venv_site_packages_libs/app_files_building/site-packages/pkg1/q1/q2c/c_mod.so",
219+
]),
220+
_venv_symlink("pkg1/q1/q2c/q2.txt", link_to_path = rr + "pkg1/q1/q2c/q2.txt", files = [
221+
"tests/venv_site_packages_libs/app_files_building/site-packages/pkg1/q1/q2c/q2.txt",
222+
]),
223+
_venv_symlink("pkg1/q1/q2c/q3", link_to_path = rr + "pkg1/q1/q2c/q3", files = [
224+
"tests/venv_site_packages_libs/app_files_building/site-packages/pkg1/q1/q2c/q3/q3a.txt",
225+
"tests/venv_site_packages_libs/app_files_building/site-packages/pkg1/q1/q2c/q3/q3b.txt",
226+
]),
213227
]
214228
expected = sorted(expected, key = lambda e: (e.link_to_path, e.venv_path))
215229
env.expect.that_collection(
@@ -226,7 +240,7 @@ def _test_optimized_grouping_single_toplevel(name):
226240
paths = [
227241
"site-packages/pkg2/__init__.py",
228242
"site-packages/pkg2/a.txt",
229-
"site-packages/pkg2/b_mod.so",
243+
"site-packages/pkg2/b_mod_so",
230244
],
231245
)
232246
analysis_test(
@@ -256,7 +270,7 @@ def _test_optimized_grouping_single_toplevel_impl(env, target):
256270
files = [
257271
"tests/venv_site_packages_libs/app_files_building/site-packages/pkg2/__init__.py",
258272
"tests/venv_site_packages_libs/app_files_building/site-packages/pkg2/a.txt",
259-
"tests/venv_site_packages_libs/app_files_building/site-packages/pkg2/b_mod.so",
273+
"tests/venv_site_packages_libs/app_files_building/site-packages/pkg2/b_mod_so",
260274
],
261275
),
262276
]

0 commit comments

Comments
 (0)