pybind_extension linkage is problematic for projects with multiple pybind modules

未关闭
#125 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
cpp, python
领域
build-system

调研方向

从 pybind_extension 规则入手,检查其 cc_binary 链接如何静态包含传递依赖并应用 -Bsymbolic。将该行为与 cc_shared_library 进行比较,重点关注如何控制静态依赖和动态依赖。完成的标准是:pybind 模块能够避免进程全局 C++ 状态的私有副本,同时保留所需的扩展链接。

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

描述

bug enhancement OS: Linux OS: MacOS OS: Windows

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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pybind/pybind11_bazel 的其他 Issue

查看 pybind/pybind11_bazel 的全部 Issue

相似的 Issue

更多 Build System Issue

把新 issue 发到你的邮箱

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