Skip to content

Commit 2c7187d

Browse files
authored
fix: support debian multiarch with local toolchains (#3100)
Apparently, there is a "multiarch" style of Python installations, where the shared libraries can be in a sub-directory. The best docs I could find about this are https://wiki.debian.org/Python/MultiArch. To fix, looking at the `MULTIARCH` sysconfig var tells what subdirectory, if any should be looked in. Along the way, fix a changelog issue reference url. Fixes #3099
1 parent cab415d commit 2c7187d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ END_UNRELEASED_TEMPLATE
8585
([#2503](https://github.com/bazel-contrib/rules_python/issues/2503)).
8686
* (toolchains) `local_runtime_repo` now checks if the include directory exists
8787
before attempting to watch it, fixing issues on macOS with system Python
88-
({gh-issue}`3043`).
88+
([#3043](https://github.com/bazel-contrib/rules_python/issues/3043)).
8989
* (pypi) The pipstar `defaults` configuration now supports any custom platform
9090
name.
9191
* Multi-line python imports (e.g. with escaped newlines) are now correctly processed by Gazelle.
92+
* (toolchains) `local_runtime_repo` works with multiarch Debian with Python 3.8
93+
([#3099](https://github.com/bazel-contrib/rules_python/issues/3099)).
9294

9395
{#v0-0-0-added}
9496
### Added

python/private/get_local_runtime_info.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@
3535
# of settings.
3636
# https://stackoverflow.com/questions/47423246/get-pythons-lib-path
3737
# For now, it seems LIBDIR has what is needed, so just use that.
38+
# See also: MULTIARCH
3839
"LIBDIR",
40+
# On Debian, with multiarch enabled, prior to Python 3.10, `LIBDIR` didn't
41+
# tell the location of the libs, just the base directory. The `MULTIARCH`
42+
# sysconfig variable tells the subdirectory within it with the libs.
43+
# See:
44+
# https://wiki.debian.org/Python/MultiArch
45+
# https://git.launchpad.net/ubuntu/+source/python3.12/tree/debian/changelog#n842
46+
"MULTIARCH",
3947
# The versioned libpythonX.Y.so.N file. Usually?
4048
# It might be a static archive (.a) file instead.
4149
"INSTSONAME",

python/private/local_runtime_repo.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def _local_runtime_repo_impl(rctx):
126126
# In some cases, the same value is returned for multiple keys. Not clear why.
127127
shared_lib_names = {v: None for v in shared_lib_names}.keys()
128128
shared_lib_dir = info["LIBDIR"]
129+
multiarch = info["MULTIARCH"]
129130

130131
# The specific files are symlinked instead of the whole directory
131132
# because it can point to a directory that has more than just
@@ -135,6 +136,11 @@ def _local_runtime_repo_impl(rctx):
135136
for name in shared_lib_names:
136137
origin = rctx.path("{}/{}".format(shared_lib_dir, name))
137138

139+
# If the origin doesn't exist, try the multiarch location, in case
140+
# it's an older Python / Debian release.
141+
if not origin.exists and multiarch:
142+
origin = rctx.path("{}/{}/{}".format(shared_lib_dir, multiarch, name))
143+
138144
# The reported names don't always exist; it depends on the particulars
139145
# of the runtime installation.
140146
if origin.exists:

0 commit comments

Comments
 (0)