pybind_extension linkage is problematic for projects with multiple pybind modules
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 领域
- build-system
调研方向
从 pybind_extension 规则入手,检查其 cc_binary 链接如何静态包含传递依赖并应用 -Bsymbolic。将该行为与 cc_shared_library 进行比较,重点关注如何控制静态依赖和动态依赖。完成的标准是:pybind 模块能够避免进程全局 C++ 状态的私有副本,同时保留所需的扩展链接。
由索引模型根据 Issue 内容生成。
描述
This has been a long standing issue that shows up in projects with non-trivial / isolated C modules. I'm just finally getting around to actually writing up this problem
Right now, pybind_extension creates a shared library is using cc_binary(). This statically links all the dependencies, transitively. To complicate matters, it uses -Bsymbolic -- what this does is change how the shared library looks up symbols, giving preference to symbols within the shared library (which, because of the static linking, includes all dependencies).
The net effect is the resulting shared library can't participate in process-global state. For example, lets say there's a foo-plugins library, normally provided as libfoo-plugins.so, with the intent that consumers can load the library and register plugins into a static map<...> PLUGINS that is global to the process. Now we create a mybind.so Python C module using pybind_extension, which depends on foo-plugins. Because of how it's linked in, mybind.so has its own private copy of the PLUGINS map. Later, when people start registering plugins and asking which are available, they'll get different answers depending on if they're within mybind.so or outside it.
Such globals aren't uncommon. Absl flags and module initializers are such an example, but are easily found in other C++ libraries.
The fix I suggest is to switch pybind_extension to using something like cc_shared_library, which provides some control over what is statically vs dynamically linked into the Python C module. cc_shared_library is annoying to use, but it can get the job done.
In any case, there needs to be a way to better control what is statically vs dynamically linked into the pybind_extension module.
- 主要语言
- Starlark
- 星标
- 116
- 派生
- 67
- 平均合并
- 22 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pybind/pybind11_bazel 的其他 Issue
-
Output file gets a `.pyd.dll` extension on Windows可能重新可做 @Mizux 于 239 天前认领,目前没有进行中的 PR。 未关闭bug OS: Windows
pybind/pybind11_bazel#132 · 4 条评论 · 已指派 1 人 ·
查看 pybind/pybind11_bazel 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 72/100
-
bug documentation good first issue
难度 2/5 1-3 小时 新手友好度 72/100
Yuefii/NusantaraKita#116 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
bemanproject/exemplar#447 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1 小时以内 新手友好度 72/100
generative-computing/mellea-skills-compiler#147 ·
维护者通常 7 天内回复