`env!` / `include!` / `include_str!` do not end up in dep-info entries resulting in stale artifacts under rustc-wrapper caches like sccache
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Necesita aclaración
- Estado de actividad
- Tranquilo
- Stack tecnológico
- rust
- Área
- build-system, tooling
Línea de trabajo
Comienza con el reproductor de Docker en github.com/leighmcculloch/rust-sccache-env-proc-macro-cache-collision y compara las entradas dep-info para env!, include! e include_str! con distintos valores de entorno. Lee la evaluación de entrada de MacroString y la ruta de expansión de proc-macro, incluido el workaround const { let _ = #raw }. Se considera terminado cuando se haya establecido el comportamiento esperado de dep-info y cualquier cambio seguro de diseño en MacroString esté claramente delimitado y cubierto por un reproductor.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Rust
- Estrellas
- 46
- Forks
- 2
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Issues similares
-
Selected chart highlights only its values, not its series names and category labelsPosiblemente ocupada @Higgs32584 la tomó hoy. Abiertobug priority: low ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
storytold/gridcraft#4390 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
Los mantenedores suelen responder en 1 día
-
bug bugfix priority: medium
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
quarto-dev/q2#1219 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100