-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix docs.rs #3580
Fix docs.rs #3580
Conversation
@andygrove please review and let me know if you know how to test. |
@@ -28,13 +28,17 @@ keywords = ["arrow", "query", "sql"] | |||
edition = "2021" | |||
rust-version = "1.62" | |||
|
|||
[package.metadata.docs.rs] |
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.
docs.rs will set this, according to their docs.
datafusion/proto/Cargo.toml
Outdated
[lib] | ||
name = "datafusion_proto" | ||
path = "src/lib.rs" | ||
|
||
[features] | ||
default = [] | ||
json = ["pbjson", "pbjson-build", "serde", "serde_json"] | ||
docsrs = [] |
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.
Did I do this correctly? Does this declare a new feature but say it has no affect on dependencies?
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.
Yes, I think so
datafusion/proto/build.rs
Outdated
.create(true) | ||
.open("src/generated/datafusion_json.rs") | ||
.open("src/generated/datafusion.rs") |
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.
I was generating to two different files because it seemed like it was smooshing the code together when I switched feature sets. Now I realize I had to call .truncate(true)
below.
datafusion/proto/build.rs
Outdated
@@ -61,8 +61,9 @@ fn build() -> Result<(), String> { | |||
let json = std::fs::read_to_string(out.join("datafusion.serde.rs")).unwrap(); | |||
let mut file = std::fs::OpenOptions::new() | |||
.write(true) | |||
.truncate(true) |
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.
This was key to use just one output file for either feature set and avoid combinatorial explosions.
datafusion/proto/build.rs
Outdated
.create(true) | ||
.open("src/generated/datafusion.rs") | ||
.unwrap(); | ||
file.write(proto.as_str().as_ref()).unwrap(); |
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.
Generate code the same way no matter which feature is selected.
#[allow(clippy::all)] | ||
#[rustfmt::skip] | ||
#[cfg(not(feature = "json"))] | ||
#[cfg(not(docsrs))] |
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.
When we have a writable source folder, generate into that.
#[rustfmt::skip] | ||
#[cfg(feature = "json")] | ||
pub mod datafusion_json; | ||
pub mod datafusion { |
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.
When not writable, pull from OUT_DIR.
@@ -25,10 +25,7 @@ pub mod generated; | |||
pub mod logical_plan; | |||
pub mod to_proto; | |||
|
|||
#[cfg(not(feature = "json"))] | |||
pub use generated::datafusion as protobuf; |
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.
Now the module name is always the same! :D
Not ready for merge... one minute. |
#[cfg(feature = "docsrs")] | ||
let path = out.join("datafusion.rs"); | ||
#[cfg(not(feature = "docsrs"))] | ||
let path = "src/generated/datafusion.rs"; |
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.
Change generated path to src or out_dir as appropriate.
Okay, ready. |
Codecov Report
@@ Coverage Diff @@
## master #3580 +/- ##
==========================================
+ Coverage 85.92% 86.05% +0.13%
==========================================
Files 301 300 -1
Lines 56249 56328 +79
==========================================
+ Hits 48330 48475 +145
+ Misses 7919 7853 -66
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
The changes look reasonable to me, but I am not familiar with the json feature or docs.rs mechanics, unfortunately.
According to rust-lang/docs.rs#147 (comment) we can use an environment variable instead of a feature flag, perhaps in combination with a cfg key, which would avoid this leaking into the crates public interface. FWIW I'm not sure if any IDEs need this source hack, it was fixed for CLion a year ago (intellij-rust/intellij-rust#1908), and so perhaps we might just revisit this decision? I'm not sure if rust-analyser has issues though? Edit: apparently rust-analyser doesn't understand (rust-lang/rust-analyzer#3767) 😭 |
Thanks @tustvold for the links. I'll investigate further today. It would clearly be best if we didn't have to hack our build to work-around IDE limitations. It sounds like you have no problem with "go to definition" on protobuf generated code in CLion? I'm definitely using the latest version and it was not working for me. I assume @andygrove is in the same boat. I'll investigate further today and document how to make it work if I figure it out. Otherwise, how would a config setting (vs feature) sound to you? I don't think an environment variable is sufficient in and of itself as we need to flip this switch at compile time. |
To get CLion to work you need to run a full build so that the files exist, and then "Refresh Cargo Projects". It then finds the files. There is also an experimental option "evaluate build scripts" but I haven't had a need for this. A config flag seems fine to me, ofc better if we didn't need to, but provided it isn't externally visible, nobody needs to know 😅 I am somewhat curious what happens when consuming the crate from crates.io, does the build script generate files in the cargo "checkout"? That feels like it might cause issues |
I wasn't aware of this action. I just updated to CLion 2022.2.3 and tried this out with the Ballista project but I still cannot "go to definition" for the generated code. My steps were:
Am I missing a step perhaps? |
From what I can tell, there are two potential issues:
I haven't done a test to figure out which is the issue, but given the fix listed above, I'm inclined to think it is #1. With Java, the solution is to go find the |
Benchmark runs are scheduled for baseline = b02753c and contender = 49b9c67. 49b9c67 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
I just did this and it worked correctly, although I note that the generated code it is finding is in To test this out I created a very basic project with the following code. main.rs
build.rs
I then compiled and ran the binary, code completion was not working at this point. Running "Refresh Cargo Projects" also didn't work, nor did "Invalidate Caches and Restart". Fortunately the fix is relatively straightforward:
On restart everything should be working. I used to have this turned on, I turned it off at some point and left it off because everything continued to work, but I suspect this was the result of some caching shenanigans. Either way I think the above should work, let me know. Either way until rust-analyser fixes support for this, I suspect we will need to continue to work around it, but perhaps framing it as a rust-analyser limitation might encourage some movement towards fixing it. Edit: I also created intellij-rust/intellij-rust#9402 to potentially get some feedback from the plugin maintainers |
@tustvold awesome work, thank you! It's great to have a resolution for why you saw different results than myself and @andygrove . As you note, probably for dev-x reasons we should work around it for now, but at least there's an issue to track so we know when to un-hack this. (I'm linking to it in a comment in my other PR). |
@tustvold users shouldn't invalidate caches to make build script evaluation work. You just need to reload the project model after turning the feature on via |
This doesn't appear to have worked with datafusion 13.0.0, the docs build is still broken, I'm getting a PR up to just check in the code like we do for arrow-rs. |
Which issue does this PR close?
Closes #3538 maybe.
Rationale for this change
Fix docs.rs build.
What changes are included in this PR?
Try to fix docs.rs, but no idea how to test.
Are there any user-facing changes?
Docs should work again.