sqlx
sqlx copied to clipboard
Extra arguments message with sqlx prepare
I'm getting an error message when running cargo sqlx prepare saying extra arguments to rustc can only be passed to one target. Create database and migrate both work with Postgres, but I can't passed the error when running prepare.
Any ideas on what is causing the error?
$ cargo sqlx prepare
error: extra arguments to rustc
can only be passed to one target, consider filtering
the package by passing, e.g., --lib
or --bin NAME
to specify a single target
error: cargo check
failed with status: exit code: 101
Are you using rustup
? cargo sqlx prepare
was coded with that assumption.
I'm using rustup to keep rustc (stable) up to date. Is there something else I need to be doing with it?
It depends on if you're using rustup's symlinks in ~/.cargo/bin
or directly invoking the installed cargo/rustc.
"which rustc" shows: ~/.cargo/bin/rustc
Also: "~/.cargo/bin/cargo sqlx prepare" gives me the same error about extra arguments.
What's your default toolchain for the folder you're trying to run it in?
stable-x86_64-unknown-linux-gnu (default)
What Rust release is that?
rustc 1.45.2 (d3fb005a3 2020-07-31)
I have both main.rs and lib.rs in my src directory. If I remove main.rs the cargo error goes away.
@eweb101 yeah sorry, I had a brainfart before but I just ran into this in a work project. The problem is that cargo rustc
won't build both the library and the binary together; if you don't have any macro invocations in main.rs
then do cargo sqlx prepare -- --lib
.
We could fix this on our side by running cargo rustc --lib
then one for each binary target we find in cargo metadata
.
We could fix this on our side by running cargo rustc --lib then one for each binary target we find in cargo metadata.
In the meantime, is there a way to do this manually? Running cargo rustc --bin my_bin
deletes the existing file.
The hack I came up with was to use
cargo sqlx prepare -- --lib
mv sqlx-data.json sqlx-data.lib.json
cargo sqlx prepare --bin
cat sql-data.lib.json sql-data.json | sponge sql-data.json
and then hand-edit the file to get rid of the duplicate db
. It would be nice to have it supported natively, though.
I still have this issue with sqlx-cli 0.5.5
. Any update about this?
Can reproduce with either a normal manifest with two binaries or a workspace manifest.
https://github.com/launchbadge/sqlx/issues/637#issuecomment-699535916 above is indeed a valid workaround, though it's quite annoying to have to copy/paste stuff around.
Also still have this issue
I have this issue with my integration tests. I have tests in the top level tests/
directory which run sqlx query!
s. I can't currently prepare an offline sqlx-data.json
which covers both the library queries and the test queries.
@jmaargh same here :(