bazel-contrib / bazel-contrib/rules_python

Runtime error python3xy.dll not found: Missing srcs in python_repository's libpython rule for os:windows

未关闭
#1,823 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
type: toolchain
主要语言
Starlark
星标
688
派生
721
平均合并
15 小时 7 分钟
30 天内合并 PR
76

描述

# 🐞 bug report

The srcs attribute for this cc_library for os:windows is` ["python3.dll", "libs/python{python_version_nodot}.lib"]`. It is missing the version-specific binary, eg python311.dll.

https://github.com/bazelbuild/rules_python/blob/c5c03b2477dd1ce0c06c9dc60bf816995f222bcf/python/repositories.bzl#L318-L326

This will result in a runtime error (python311.dll not found) in the following scenario.
1. User creates a cc_binary which has `#include ` and which depends on the libpython above.
2. User never defines `#Py_LIMITED_ABI `
3. User attempts to run the cc_binary

The Python.h includes the pyconfig.h, which causes msvc to attempt linking against python3xy.dll via the` #pragma comment(lib, ...) `mechanism. The relevant code from the cpython project is here.
https://github.com/python/cpython/blob/d610d821fd210dce63a1132c274ffdf8acc510bc/PC/pyconfig.h.in#L315-L331

I have resolved this locally by globbing *.dll into the libpython cc_library.

A similar issue occurs if the user defines `#Py_DEBUG`, which causes msvc to attempt linking against the debug binary python3xy_d.dll. I did not see a way to request debug binaries using the python_repository rule but if that were enabled, I think globbing *.dll would fix that case too.

### Affected Rule

python_repository

### Is this a regression?

Unsure.

### Description

See above.

## 🔬 Minimal Reproduction

See above.

## 🔥 Exception or Error

Runtime error python3xy.dll not found

## 🌍 Your Environment

**Operating System:**

  

Windows 10

**Output of `bazel version`:**

  

7.0.2

**Rules_python version:**

  

0.31.0

**Anything else relevant?**

贡献指南

打开贡献指南

调研方向

从 python/repositories.bzl 第 318-326 行附近开始,这里定义了 Windows libpython cc_library 的 srcs。在 Windows 上复现报告的 cc_binary 场景,并检查 Python.h 如何选择特定版本的运行时 DLL。当生成的 target 能在运行时提供所需的 python3xy.dll,且不再出现报告中的缺少 DLL 错误时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
build-system
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。