`env!` / `include!` / `include_str!` do not end up in dep-info entries resulting in stale artifacts under rustc-wrapper caches like sccache
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 静か
- 技術スタック
- rust
- 領域
- build-system, tooling
調査の方向性
github.com/leighmcculloch/rust-sccache-env-proc-macro-cache-collision の Docker reproducer から始め、変更した環境値にわたって env!、include!、include_str! の dep-info エントリを比較します。const { let _ = #raw } workaround を含め、MacroString 入力の評価と proc-macro 展開パスを読みます。期待される dep-info の動作が確立され、安全な MacroString の設計変更があればその範囲が明確に定義され、reproducer でカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I've been debugging a situation with a procmacro that uses macro-string where changes to an environment variable used in it via env! and passed through a macro-string resulted in stale build artifacts rather than the latest environment value being embedded.
pub const GIT_REVISION: &str = mymacrolib::baked!(env!("GIT_REVISION"));
I created a Docker image that reproduces the problem with sccache setup, and a repo with a procmacro using macro-string:
My understanding so far is that this is happening because macro-string evaluates and expands the env! within the procmacro meaning that rustc never sees the env! in the crate and so is unaware that it is a dependency and the env value doesn't get included in the build artifact's dep-info. When rebuilding the build artifact with a different env! sccache will return the earlier cached artifact because it cannot distinguish between them since the env is not included in the dep-info.
As a work-around I've found that having my procmacro emit a const { let _ = #input } can resurface the env! back in the context of the crate unexpanded. For example:
#[proc_macro]
pub fn baked(input: TokenStream) -> TokenStream {
let raw = proc_macro2::TokenStream::from(input.clone());
let macro_string = parse_macro_input!(input as MacroString);
let s = macro_string.eval().unwrap();
let lit = proc_macro2::Literal::string(&s);
quote! {
{
const { let _ = #raw; }; // surface env!()/include!() to rustc's dep-info
#lit
}
}
.into()
}
Is the dep-info loss of env!/include!/include_str! expected / known issue?
Because macro-string is an embedded detail in macros it can be difficult to know if it is safe to use sccache for a build or not with a rust library, because internally or somewhere in the dependency tree it may be in use in a way that poisons the cache.
Would it be reasonable for MacroString to somehow encourage re-exporting of the input as a way to reduce the occurrence of this bug? It's not obvious to me how this would be achieved so I expect my question is naive at best.
- 主要言語
- Rust
- スター
- 46
- フォーク
- 2
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
似ている issue
-
Selected chart highlights only its values, not its series names and category labels対応中かも @Higgs32584 が今日担当しました。 オープンbug priority: low ui
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
storytold/gridcraft#4390 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
bug bugfix priority: medium
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
quarto-dev/q2#1219 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100