Skip to content

Commit 0d63f5e

Browse files
abonandermehcode
authored andcommitted
cargo sqlx prepare: fix to consistently trigger recompile
1 parent 9cd9aa4 commit 0d63f5e

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

sqlx-cli/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ pub enum Command {
3737
#[structopt(long)]
3838
check: bool,
3939

40-
/// Any arguments to pass to `cargo check`.
40+
/// Any arguments to pass to `cargo rustc`;
41+
/// Cargo args (preceding `--` in `cargo rustc ... -- ...`) only.
4142
#[structopt(name = "Cargo args", last = true)]
4243
cargo_args: Vec<String>,
4344
},

sqlx-cli/src/prepare.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ fn run_prepare_step(cargo_args: Vec<String>) -> anyhow::Result<QueryData> {
7676
.context("`prepare` subcommand may only be invoked as `cargo sqlx prepare``")?;
7777

7878
let check_status = Command::new(&cargo)
79-
.arg("check")
79+
.arg("rustc")
8080
.args(cargo_args)
81-
// set an always-changing env var that the macros depend on via `env!()`
82-
.env(
83-
"__SQLX_RECOMPILE_TRIGGER",
84-
SystemTime::UNIX_EPOCH.elapsed()?.as_millis().to_string(),
85-
)
81+
.arg("--")
82+
.arg("--emit")
83+
.arg("dep-info,metadata")
84+
// set an always-changing cfg so we can consistently trigger recompile
85+
.arg("--cfg")
86+
.arg(format!(
87+
"__sqlx_recompile_trigger=\"{}\"",
88+
SystemTime::UNIX_EPOCH.elapsed()?.as_millis()
89+
))
8690
.status()?;
8791

8892
if !check_status.success() {

sqlx-macros/src/query/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@ where
222222
(#($#arg_names:expr),*) => {{
223223
use sqlx::arguments::Arguments as _;
224224

225-
// lets `cargo sqlx prepare` ensure that we can always trigger a recompile
226-
const _: Option<&'static str> = option_env!("__SQLX_RECOMPILE_TRIGGER");
227-
228225
#args_tokens
229226

230227
#output

0 commit comments

Comments
 (0)