sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Running `sqlx prepare` without Cargo

Open alexkirsz opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

We're using Bazel and rules_rust to build all of our Rust libraries and binaries. We don't use Cargo at all, which means that we don't have any Cargo.toml file to describe our workspace or crates, and as such cargo build cannot compile our project. Everything is defined in BUILD.bazel files instead.

Describe the solution you'd like

Provide a sqlx prepare command that doesn't require being run through Cargo, possibly taking in a .rlib instead and using a solution akin to UniFFI's metadata macros: embed the generated queries within the generated binary or library, and extract it as part of the sqlx prepare command.

Describe alternatives you've considered

Another way to fix this issue would be to provide first-class Bazel support, but that would not scale well to other cargo-less setups.

alexkirsz avatar Oct 10 '24 08:10 alexkirsz

If I understand correctly, running rustc in "check" mode (the same way it's invoked by cargo check) with a few environment variables should be sufficient. cargo sqlx prepare invokes cargo check with SQLX_TMP, SQLX_OFFLINE set to false, and SQLX_OFFLINE_DIR points to the .sqlx folder.

So it should be possible to set up such a rule in Bazel to generate the .sqlx.

TheLortex avatar Oct 10 '24 09:10 TheLortex