Support omitting automatic rpaths for packaged Linux rust_binary outputs

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

Maintainer thường phản hồi trong vòng 3 ngày

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
46/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust
Lĩnh vực
build-system

Hướng nghiên cứu

Read rustc_compile_action and get_linker_and_args to trace how automatic rpaths reach the linker, then inspect the planned configurability redesign in #4049. Add a regression test comparing default automatic paths with opted-in authored paths and checking refusal when dynamic Rust std is enabled; confirm the public option’s scope with the maintainers.

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

Mô tả

needs-triage

Linux distribution binaries need a way to omit Bazel's automatically computed runtime library paths while preserving explicitly authored linker flags.

A concrete packaging layout is bin/app plus lib/libdependency.so. We compile with static Rust std, copy the executable and its declared shared libraries into an OCI image, and want the sole runtime search path to be $ORIGIN/../lib. Paths into Bazel's _solib and runfiles trees do not exist in that image.

With rules_rust 0.74.0, rustc_compile_action computes rpaths from native dependencies and passes them into get_linker_and_args. Adding an explicit path through rustc_flags preserves the automatic paths too. Disabling the C++ runtime_library_search_directories feature is not a suitable general solution: the configured C++ link action can require that feature during analysis.

We currently use a small downstream correction: a boolean on rust_binary, default false, which leaves the C++ feature configuration intact but passes an empty rpath depset to the linker for an opted-in binary. It preserves user-authored linker flags and normal build-script/proc-macro linking. Our current implementation refuses non-Linux binaries and link_std_dylib=True, so it does not silently break dynamic Rust std loading.

For example, a possible public interface would be:

rust_binary(
    name = "app",
    srcs = ["main.rs"],
    deps = [":shared_native_dependency"],
    relocatable_binary = True,
    rustc_flags = ["-Clink-arg=-Wl,-rpath,$$ORIGIN/../lib"],
)

Validation of the downstream correction includes ARM64 ELF dynamic-section checks after copying out of the execroot, startup of every packaged executable in the exact runtime image, and a backend query that executes packaged V8. The default behavior remains unchanged. These checks were executed against the pinned 0.74.0 correction; I am not claiming execution against upstream main.

I checked main at bbeacc846555ffe6738ad79ea3013f2c255c8081 and the same automatic-rpath path remains. Before proposing a public attribute, as CONTRIBUTING.md requests, would you prefer this narrowly scoped option, an existing supported configuration that I missed, or a hook in the planned configurability redesign (#4049)? A regression test should compare default automatic paths with opted-in authored paths and verify refusal for dynamic Rust std.

Assisted-by: OpenAI Codex

Ngôn ngữ chính
Starlark
Star
857
Fork
701
Merge trung bình
4 ngày 7 giờ
Pull request đã merge (30 ngày)
46

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 bazelbuild/rules_rust

Tất cả issue của bazelbuild/rules_rust

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.