-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support workspaces for offline feature #506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits, also while I don't disagree with the goal of this PR I'm not sure everyone using cargo sqlx prepare
will want a single merged sqlx-data.json
at the workspace root so I think there's room for a more flexible solution. Maybe we should put this behavior under a --merged
flag?
sqlx-macros/src/query/mod.rs
Outdated
@@ -40,7 +53,7 @@ pub fn expand_input(input: QueryMacroInput) -> crate::Result<TokenStream> { | |||
|
|||
#[cfg(feature = "offline")] | |||
None => { | |||
let data_file_path = std::path::Path::new(&manifest_dir).join("sqlx-data.json"); | |||
let data_file_path = CRATE_ROOT.join("sqlx-data.json"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get the behavior you want, all you actually have to do is save sqlx-data.json
to the current working directory (so not even joining it with any path); that will always be the workspace root in the case of proc macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I think we maybe want to distinguish between cases where the user wants a single merged sqlx-data.json
file at the workspace root and where the user wants an individual sqlx-data.json
file per crate.
@mehcode any opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my testing CARGO_MANIFEST_DIR
is the crate root, not the workspace root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ref: rust-lang/cargo#3946
+1 for something like a |
I'll update to use a |
We prefer not to merge |
I'll rebase once I have updates to push, for now I'll move into draft |
cb019ca
to
7ed185a
Compare
We can merge this once its updated to use a |
This patch enables having a top-level `sqlx-data.json` file within a workspace. It does this by using a full clean / check instead of `cargo rustc` which fails on a workspace. A `--merged` flag is introduced to switch to the workspace behavior Fixes launchbadge#353. Signed-off-by: Joe Grund <[email protected]>
3aca4f9
to
83d3f8c
Compare
This looks good to me. Thank you @jgrund for hanging in there. |
@mehcode Thanks, can you release a new version of |
This patch enables having a top-level
sqlx-data.json
file within aworkspace.
It does this by using a full clean / check instead of
cargo rustc
which fails on a workspace.
It also uses the
cargo_metadata
package to find theworkspace_root
(which should be the same as
CARGO_MANIFEST_DIR
in a non workspace).Note:
cargo_metadata
pulls in serde / serde_json. I wasn't sure if Ishould remove the features for those with this change.
Fixes #353.
Signed-off-by: Joe Grund [email protected]