-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,17 @@ keywords = ["arrow", "query", "sql"] | |
edition = "2021" | ||
rust-version = "1.62" | ||
|
||
[package.metadata.docs.rs] | ||
features = [ "docsrs" ] # https://github.com/rust-lang/docs.rs/issues/147 | ||
|
||
[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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think so |
||
|
||
[dependencies] | ||
arrow = "23.0.0" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ fn build() -> Result<(), String> { | |
use std::io::Write; | ||
|
||
let out = std::path::PathBuf::from( | ||
std::env::var("OUT_DIR").expect("Cannot find OUT_DIR environment vairable"), | ||
std::env::var("OUT_DIR").expect("Cannot find OUT_DIR environment variable"), | ||
); | ||
let descriptor_path = out.join("proto_descriptor.bin"); | ||
|
||
|
@@ -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 commentThe 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_json.rs") | ||
.open("src/generated/datafusion.rs") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
.unwrap(); | ||
file.write(proto.as_str().as_ref()).unwrap(); | ||
file.write(json.as_str().as_ref()).unwrap(); | ||
|
@@ -72,8 +73,24 @@ fn build() -> Result<(), String> { | |
|
||
#[cfg(not(feature = "json"))] | ||
fn build() -> Result<(), String> { | ||
use std::io::Write; | ||
|
||
let out = std::path::PathBuf::from( | ||
std::env::var("OUT_DIR").expect("Cannot find OUT_DIR environment variable"), | ||
); | ||
|
||
prost_build::Config::new() | ||
.out_dir("src/generated") | ||
.compile_protos(&["proto/datafusion.proto"], &["proto"]) | ||
.map_err(|e| format!("protobuf compilation failed: {}", e)) | ||
.map_err(|e| format!("protobuf compilation failed: {}", e))?; | ||
|
||
let proto = std::fs::read_to_string(out.join("datafusion.rs")).unwrap(); | ||
let mut file = std::fs::OpenOptions::new() | ||
.write(true) | ||
.truncate(true) | ||
.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 commentThe reason will be displayed to describe this comment to others. Learn more. Generate code the same way no matter which feature is selected. |
||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,16 @@ | |
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// include the generated protobuf source as a submodule | ||
#[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 commentThe reason will be displayed to describe this comment to others. Learn more. When we have a writable source folder, generate into that. |
||
pub mod datafusion; | ||
|
||
#[cfg(docsrs)] | ||
#[allow(clippy::all)] | ||
#[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 commentThe reason will be displayed to describe this comment to others. Learn more. When not writable, pull from OUT_DIR. |
||
include!(concat!(env!("OUT_DIR"), "/datafusion.rs")); | ||
|
||
#[cfg(feature = "json")] | ||
include!(concat!(env!("OUT_DIR"), "/datafusion.serde.rs")); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Now the module name is always the same! :D |
||
#[cfg(feature = "json")] | ||
pub use generated::datafusion_json as protobuf; | ||
|
||
#[cfg(doctest)] | ||
doc_comment::doctest!("../README.md", readme_example_test); | ||
|
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.