Support omitting automatic rpaths for packaged Linux rust_binary outputs

オープン
#4,325 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
46/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
rust
領域
build-system

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Starlark
スター
857
フォーク
701
平均マージ
4日 7時間
マージ済み PR(30日)
46

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bazelbuild/rules_rust のほかの issue

bazelbuild/rules_rust の issue をすべて見る

似ている issue

Build System の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。