cargo sqlx prepare: fix to consistently trigger recompile

This commit is contained in:
Austin Bonander 2020-05-19 20:50:02 -07:00 committed by Ryan Leckey
parent 119167e13a
commit 1bdc3e9057
3 changed files with 12 additions and 10 deletions

View file

@ -37,7 +37,8 @@ pub enum Command {
#[structopt(long)] #[structopt(long)]
check: bool, check: bool,
/// Any arguments to pass to `cargo check`. /// Any arguments to pass to `cargo rustc`;
/// Cargo args (preceding `--` in `cargo rustc ... -- ...`) only.
#[structopt(name = "Cargo args", last = true)] #[structopt(name = "Cargo args", last = true)]
cargo_args: Vec<String>, cargo_args: Vec<String>,
}, },

View file

@ -76,13 +76,17 @@ fn run_prepare_step(cargo_args: Vec<String>) -> anyhow::Result<QueryData> {
.context("`prepare` subcommand may only be invoked as `cargo sqlx prepare``")?; .context("`prepare` subcommand may only be invoked as `cargo sqlx prepare``")?;
let check_status = Command::new(&cargo) let check_status = Command::new(&cargo)
.arg("check") .arg("rustc")
.args(cargo_args) .args(cargo_args)
// set an always-changing env var that the macros depend on via `env!()` .arg("--")
.env( .arg("--emit")
"__SQLX_RECOMPILE_TRIGGER", .arg("dep-info,metadata")
SystemTime::UNIX_EPOCH.elapsed()?.as_millis().to_string(), // set an always-changing cfg so we can consistently trigger recompile
) .arg("--cfg")
.arg(format!(
"__sqlx_recompile_trigger=\"{}\"",
SystemTime::UNIX_EPOCH.elapsed()?.as_millis()
))
.status()?; .status()?;
if !check_status.success() { if !check_status.success() {

View file

@ -222,9 +222,6 @@ where
(#($#arg_names:expr),*) => {{ (#($#arg_names:expr),*) => {{
use sqlx::arguments::Arguments as _; use sqlx::arguments::Arguments as _;
// lets `cargo sqlx prepare` ensure that we can always trigger a recompile
const _: Option<&'static str> = option_env!("__SQLX_RECOMPILE_TRIGGER");
#args_tokens #args_tokens
#output #output