Keep Rust native builds from accidentally linking against Linuxbrew libs. On older glibc systems, Homebrew-provided native libraries can require a newer libc than the host linker/runtime supports. When pkg-config resolves xz/bzip2 from Linuxbrew, Cargo inherits those library search path
(env)
| 36 | |
| 37 | |
| 38 | def _sanitize_native_build_env(env): |
| 39 | """Keep Rust native builds from accidentally linking against Linuxbrew libs. |
| 40 | |
| 41 | On older glibc systems, Homebrew-provided native libraries can require a newer |
| 42 | libc than the host linker/runtime supports. When pkg-config resolves xz/bzip2 |
| 43 | from Linuxbrew, Cargo inherits those library search paths and link fails. |
| 44 | """ |
| 45 | |
| 46 | sanitized_env = env.copy() |
| 47 | |
| 48 | pkg_config = sanitized_env.get("PKG_CONFIG") or shutil.which("pkg-config") |
| 49 | if pkg_config and "linuxbrew" in os.path.realpath(pkg_config).lower(): |
| 50 | system_pkg_config = "/usr/bin/pkg-config" |
| 51 | if Path(system_pkg_config).exists(): |
| 52 | sanitized_env["PKG_CONFIG"] = system_pkg_config |
| 53 | |
| 54 | for key in ("PKG_CONFIG_PATH", "LIBRARY_PATH", "LD_LIBRARY_PATH"): |
| 55 | value = sanitized_env.get(key) |
| 56 | if not value: |
| 57 | continue |
| 58 | kept_paths = [ |
| 59 | path |
| 60 | for path in value.split(os.pathsep) |
| 61 | if path and "linuxbrew" not in os.path.realpath(path).lower() |
| 62 | ] |
| 63 | if kept_paths: |
| 64 | sanitized_env[key] = os.pathsep.join(kept_paths) |
| 65 | else: |
| 66 | sanitized_env.pop(key, None) |
| 67 | |
| 68 | return sanitized_env |
| 69 | |
| 70 | |
| 71 | def _get_windows_python_sabi_library() -> Path: |
no test coverage detected