You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[sqlx-cli] prepare unable to find queries if cargo target-dir is set in config.toml #1706
I generally use the following ~/.cargo/config.toml
[build]
target-dir = "/home/sedrik/.cargo/target"
But having this setup and a lib crate with binaries in it caused cargo sqlx prepare -- --lib --all-features to fail to find any new queries even if I did a cargo clean and removed the target directory. I also noted that sqlx's outputs files into the projects target directory but removing those as well did not help.
Removing the config for target-dir made prepare work again.
I've previously run into this as well. This would require a call to cargo metadata to be able to find the actual location (output contains a target_dir field), but requiring that for non-workspaces would be a breaking change for non-cargo build systems (unless they set CARGO_TARGET_DIR), see #1415.
Hm yeah, doing it when cargo is available sounds like a good idea. Then the repeated cargo metadata calls that #1415 introduced can be removed again too. I don't think I have time to work on it myself, but I can write up some instructions if you're interested in writing the PR.
Change let cargo = env("CARGO").expect("CARGO must be set"); to an if let Ok(cargo) = env("CARGO") {} or similar and make the workspace_root field optional for this to work
Add target_dir next to workspace_root and initialize it the same way
Make use of target_dir whereever {workspace_root}/target is being used right now (maybe the workspace root doesn't even need to be queried then?)
I did an attempt at fixing this but it seems to me that it boils down to an issue in the rustc cli (I can't set out-dir in our specific case).
I did ask about it on zulip but haven't received a response yet.
Created a draft PR here with a, in my opinion, quite ugly workaround. Namely moving the files. I did verify that on Linux it works with and without a custom target directory.
Activity
jplatte commentedon Feb 15, 2022
I've previously run into this as well. This would require a call to
cargo metadatato be able to find the actual location (output contains atarget_dirfield), but requiring that for non-workspaces would be a breaking change for non-cargo build systems (unless they setCARGO_TARGET_DIR), see #1415.sedrik commentedon Feb 15, 2022
Hmm, it would be nice to handle it if cargo is available though, or at least give a better error indicating what is wrong.
jplatte commentedon Feb 15, 2022
Hm yeah, doing it when cargo is available sounds like a good idea. Then the repeated
cargo metadatacalls that #1415 introduced can be removed again too. I don't think I have time to work on it myself, but I can write up some instructions if you're interested in writing the PR.sedrik commentedon Feb 15, 2022
I can't say when/if I will have time to pick it up but if you write some instructions I will try to find some time for it 👍
jplatte commentedon Mar 1, 2022
Okay so what I would do:
let cargo = env("CARGO").expect("CARGOmust be set");to anif let Ok(cargo) = env("CARGO") {}or similar and make theworkspace_rootfield optional for this to worktarget_dirnext toworkspace_rootand initialize it the same waytarget_dirwhereever{workspace_root}/targetis being used right now (maybe the workspace root doesn't even need to be queried then?)sedrik commentedon Jun 16, 2022
I did an attempt at fixing this but it seems to me that it boils down to an issue in the rustc cli (I can't set out-dir in our specific case).
I did ask about it on zulip but haven't received a response yet.
Created a draft PR here with a, in my opinion, quite ugly workaround. Namely moving the files. I did verify that on Linux it works with and without a custom target directory.
#1910
sedrik commentedon Jun 16, 2022
Here is an example of the error from my debugging session.