pybind_extension linkage is problematic for projects with multiple pybind modules

Đang mở
#125 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
cpp, python
Lĩnh vực
build-system

Hướng nghiên cứu

Bắt đầu từ rule pybind_extension và kiểm tra cách việc liên kết cc_binary đưa các dependency bắc cầu vào một cách tĩnh và áp dụng -Bsymbolic. So sánh hành vi đó với cc_shared_library, tập trung vào cách có thể kiểm soát dependency tĩnh so với dependency động. Công việc được xem là hoàn tất khi một module pybind có thể tránh các bản sao riêng của trạng thái C++ toàn cục của tiến trình mà vẫn giữ được việc liên kết extension cần thiết.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Starlark
Star
116
Fork
67
Merge trung bình
22 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pybind/pybind11_bazel

Tất cả issue của pybind/pybind11_bazel

Issue tương tự

Thêm issue về Build System

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.