Skip to content
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

Merged
merged 6 commits into from
Sep 23, 2022
Merged

Fix docs.rs #3580

merged 6 commits into from
Sep 23, 2022

Conversation

avantgardnerio
Copy link
Contributor

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.

@avantgardnerio
Copy link
Contributor Author

@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]
Copy link
Contributor Author

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.

[lib]
name = "datafusion_proto"
path = "src/lib.rs"

[features]
default = []
json = ["pbjson", "pbjson-build", "serde", "serde_json"]
docsrs = []
Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so

.create(true)
.open("src/generated/datafusion_json.rs")
.open("src/generated/datafusion.rs")
Copy link
Contributor Author

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.

@@ -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)
Copy link
Contributor Author

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.

.create(true)
.open("src/generated/datafusion.rs")
.unwrap();
file.write(proto.as_str().as_ref()).unwrap();
Copy link
Contributor Author

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))]
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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;
Copy link
Contributor Author

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

@avantgardnerio
Copy link
Contributor Author

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";
Copy link
Contributor Author

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.

@avantgardnerio
Copy link
Contributor Author

Not ready for merge

Okay, ready.

@codecov-commenter
Copy link

codecov-commenter commented Sep 21, 2022

Codecov Report

Merging #3580 (c7fcac2) into master (0a2b0a7) will increase coverage by 0.13%.
The diff coverage is 100.00%.

@@            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     
Impacted Files Coverage Δ
datafusion/proto/src/lib.rs 94.35% <ø> (+0.07%) ⬆️
.../src/physical_plan/file_format/delimited_stream.rs 91.75% <100.00%> (ø)
datafusion/core/src/physical_plan/hash_join.rs 95.03% <100.00%> (ø)
datafusion/expr/src/logical_plan/plan.rs 77.10% <0.00%> (-1.16%) ⬇️
datafusion/core/src/physical_plan/sorts/sort.rs 93.86% <0.00%> (-0.60%) ⬇️
...e/src/physical_plan/sorts/sort_preserving_merge.rs 93.49% <0.00%> (-0.36%) ⬇️
datafusion/expr/src/binary_rule.rs 84.31% <0.00%> (-0.29%) ⬇️
datafusion/core/tests/sql/decimal.rs 100.00% <0.00%> (ø)
datafusion/core/src/execution/context.rs 79.33% <0.00%> (ø)
datafusion/physical-expr/src/expressions/binary.rs 97.63% <0.00%> (ø)
... and 22 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@andygrove andygrove left a 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.

@tustvold
Copy link
Contributor

tustvold commented Sep 22, 2022

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) 😭

@avantgardnerio
Copy link
Contributor Author

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.

@tustvold
Copy link
Contributor

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

@andygrove
Copy link
Member

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.

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:

  • Delete .idea folder
  • Open project in CLion
  • Build in CLion
  • Refresh Cargo Projects

Am I missing a step perhaps?

@avantgardnerio
Copy link
Contributor Author

avantgardnerio commented Sep 22, 2022

To get CLion to work

From what I can tell, there are two potential issues:

  1. The fact that code is generated into the target/ folder, which is marked as "excluded" (for good reasons)
  2. the usage of the import! macro is confusing CLion

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 target/myfolder/generated and mark it as a "generated sources root" overriding the "exclude" on the parent folder. With Cargo, this isn't so easy as everything under the target/ folder all gets random hash looking identifiers that change periodically making it not possible to re-include them continuously.

@github-actions github-actions bot added the core Core DataFusion crate label Sep 22, 2022
@alamb alamb merged commit 49b9c67 into apache:master Sep 23, 2022
@ursabot
Copy link

ursabot commented Sep 23, 2022

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.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@avantgardnerio avantgardnerio deleted the bg_fix_docs branch September 23, 2022 14:44
@tustvold
Copy link
Contributor

tustvold commented Sep 23, 2022

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.

I just did this and it worked correctly, although I note that the generated code it is finding is in src/generated.

To test this out I created a very basic project with the following code.

main.rs

include!(concat!(env!("OUT_DIR"), "/test.rs"));

fn main() {
    Foo {};
    println!("Hello, world!");
}

build.rs

use std::fs::File;
use std::io::Write;
use std::path::PathBuf;

fn main() {
    let path = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()).join("test.rs");
    let mut file = File::create(path).unwrap();
    writeln!(file, "struct Foo {{}}").unwrap();
}

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:

  • Open Help > Find Action (CTRL + SHIFT + A)
  • Enter "Experimental" and select "Experimental Features"
  • Scroll down to "org.rust.cargo.evaluate.build.scripts" and enable it
  • File > Invalidate Caches

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

@avantgardnerio
Copy link
Contributor Author

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

@Undin
Copy link

Undin commented Sep 26, 2022

File > Invalidate Caches

@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 Refresh Cargo Projects in Cargo tool window

Screenshot 2022-09-26 at 11 22 38

@tustvold
Copy link
Contributor

tustvold commented Oct 25, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs.rs cannot build datafusion-proto crate
7 participants