launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.29k stars 1.26k forks source link

Query macros panic if `CARGO` environment variable is not set #1021

Open jplatte opened 3 years ago

jplatte commented 3 years ago

It's not guaranteed that Rust projects are compiled with cargo, so it would probably good to replace this .expect() with a fallback:

https://github.com/launchbadge/sqlx/blob/af7f2594457e991fd84a97a2170f79801fbdf1df/sqlx-macros/src/query/mod.rs#L33-L33

CC rust-analyzer/rust-analyzer/issues/7462

abonander commented 3 years ago

We also require CARGO_MANIFEST_DIR https://github.com/launchbadge/sqlx/blob/af7f2594457e991fd84a97a2170f79801fbdf1df/sqlx-macros/src/query/mod.rs#L54

which is where we look for .env.

I've been told the working dir that proc macros are executed in is always the workspace root, but assuming that is always the case isn't really any better than requiring these env vars to be set.

We need some way to know the directory to search in for sqlx-data.json (or .sqlx/ later on) and .env. Any suggestions?