bzlmod: override_target_build_script and override_target_proc_macro are silent no-ops (override_targets key mismatch)

オープン 初心者向け
#4,152 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
1/5
見積もり時間
1〜3時間
初心者へのやさしさ
90/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
rust
領域
build-system

調査の方向性

extensions.bzl で override_targets の再構築から始め、そのキーを crate_context.rs の override_target_key と比較します。bzlmod のキーを文書化された kind の語彙に揃え、その後 build script または proc macro を含む crate を再度 pin して、生成された BUILD を調べ、override が指定された label への alias を出力することを確認します。

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

説明

The bzlmod module extension reconstructs override_targets from the four split override_target_* attributes using the keys "build_script" and "proc_macro":

https://github.com/bazelbuild/rules_rust/blob/main/crate_universe/extensions.bzl (search for override_target_build_script)

replacement = annotation_dict.pop("override_target_proc_macro")
if replacement:
    annotation_dict["override_targets"]["proc_macro"] = str(replacement)

replacement = annotation_dict.pop("override_target_build_script")
if replacement:
    annotation_dict["override_targets"]["build_script"] = str(replacement)

But rendering looks the rule up by its cargo-metadata Target.kind via override_target_key(), which returns "proc-macro" and "custom-build":

https://github.com/bazelbuild/rules_rust/blob/main/crate_universe/src/context/crate_context.rs (override_target_key)

pub(crate) fn override_target_key(&self) -> &'static str {
    match self {
        Self::Library(..) => "lib",
        Self::ProcMacro(..) => "proc-macro",
        Self::Binary(..) => "bin",
        Self::BuildScript(..) => "custom-build",
    }
}

"lib" and "bin" agree in both spellings, so those overrides work. "build_script" and "proc_macro" never match, so under bzlmod override_target_build_script and override_target_proc_macro are silently ignored: the generated BUILD keeps its own cargo_build_script instead of emitting the alias to the override label. No error or warning is produced.

The non-bzlmod crate.annotation(override_targets = ...) documents the kind-style vocabulary ("Keys can be proc-macro, custom-build, lib, bin" in crate_universe/private/crate.bzl), which is presumably why this went unnoticed: WORKSPACE users pass the dict directly with the correct keys.

Repro: annotate any crate that has a build script with override_target_build_script = "//some:target" under bzlmod, repin, and inspect the generated BUILD: it still contains the generated cargo_build_script rather than an alias to //some:target.

Fix: align the two keys in extensions.bzl with the documented vocabulary:

-                annotation_dict["override_targets"]["proc_macro"] = str(replacement)
+                annotation_dict["override_targets"]["proc-macro"] = str(replacement)
...
-                annotation_dict["override_targets"]["build_script"] = str(replacement)
+                annotation_dict["override_targets"]["custom-build"] = str(replacement)

We are running with exactly this two-line patch applied to 0.70.0 and override_target_build_script works as documented with it.

主要言語
Starlark
スター
853
フォーク
680
平均マージ
3日 4時間
マージ済み PR(30日)
19

環境構築

はじめの一歩

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

bazelbuild/rules_rust のほかの issue

bazelbuild/rules_rust の issue をすべて見る

似ている issue

Build System の issue をもっと見る

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

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