sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

Extra arguments message with sqlx prepare

Open eweb101 opened this issue 4 years ago • 18 comments

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

eweb101 avatar Aug 16 '20 12:08 eweb101

Are you using rustup? cargo sqlx prepare was coded with that assumption.

abonander avatar Aug 16 '20 12:08 abonander

I'm using rustup to keep rustc (stable) up to date. Is there something else I need to be doing with it?

eweb101 avatar Aug 16 '20 12:08 eweb101

It depends on if you're using rustup's symlinks in ~/.cargo/bin or directly invoking the installed cargo/rustc.

abonander avatar Aug 16 '20 12:08 abonander

"which rustc" shows: ~/.cargo/bin/rustc

Also: "~/.cargo/bin/cargo sqlx prepare" gives me the same error about extra arguments.

eweb101 avatar Aug 16 '20 13:08 eweb101

What's your default toolchain for the folder you're trying to run it in?

abonander avatar Aug 16 '20 13:08 abonander

stable-x86_64-unknown-linux-gnu (default)

eweb101 avatar Aug 16 '20 13:08 eweb101

What Rust release is that?

abonander avatar Aug 16 '20 13:08 abonander

rustc 1.45.2 (d3fb005a3 2020-07-31)

eweb101 avatar Aug 16 '20 13:08 eweb101

I have both main.rs and lib.rs in my src directory. If I remove main.rs the cargo error goes away.

eweb101 avatar Aug 16 '20 19:08 eweb101

@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.

abonander avatar Aug 28 '20 01:08 abonander

We could fix this on our side by running cargo rustc --lib then one for each binary target we find in cargo metadata.

abonander avatar Aug 28 '20 01:08 abonander

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.

jyn514 avatar Sep 26 '20 19:09 jyn514

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.

jyn514 avatar Sep 26 '20 19:09 jyn514

I still have this issue with sqlx-cli 0.5.5. Any update about this?

azzamsa avatar Jun 08 '21 13:06 azzamsa

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.

zopieux avatar Sep 16 '21 01:09 zopieux

Also still have this issue

longfellowone avatar Feb 24 '22 03:02 longfellowone

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 avatar Mar 13 '22 16:03 jmaargh

@jmaargh same here :(

penso avatar Apr 29 '22 01:04 penso