Skip to content

Commit 49b9c67

Browse files
author
Brent Gardner
authored
Fix docs.rs (#3580)
* I think this will fix docs.rs but no idea how to test * Generate to correct location * Clippy * Alphabetize * Feature -> cfg * New clippy is more demanding
1 parent b02753c commit 49b9c67

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

datafusion/proto/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ keywords = ["arrow", "query", "sql"]
2828
edition = "2021"
2929
rust-version = "1.62"
3030

31+
[package.metadata.docs.rs]
32+
rustc-args = ["--cfg", "docsrs"]
33+
3134
[lib]
3235
name = "datafusion_proto"
3336
path = "src/lib.rs"

datafusion/proto/build.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ fn main() -> Result<(), String> {
2828
Ok(())
2929
}
3030

31-
#[cfg(feature = "json")]
3231
fn build() -> Result<(), String> {
3332
use std::io::Write;
3433

3534
let out = std::path::PathBuf::from(
36-
std::env::var("OUT_DIR").expect("Cannot find OUT_DIR environment vairable"),
35+
std::env::var("OUT_DIR").expect("Cannot find OUT_DIR environment variable"),
3736
);
3837
let descriptor_path = out.join("proto_descriptor.bin");
3938

@@ -44,9 +43,11 @@ fn build() -> Result<(), String> {
4443
.compile_protos(&["proto/datafusion.proto"], &["proto"])
4544
.map_err(|e| format!("protobuf compilation failed: {}", e))?;
4645

46+
#[cfg(feature = "json")]
4747
let descriptor_set = std::fs::read(&descriptor_path)
4848
.expect(&*format!("Cannot read {:?}", &descriptor_path));
4949

50+
#[cfg(feature = "json")]
5051
pbjson_build::Builder::new()
5152
.register_descriptors(&descriptor_set)
5253
.expect(&*format!(
@@ -58,22 +59,25 @@ fn build() -> Result<(), String> {
5859

5960
// .serde.rs is not a valid package name, so append to datafusion.rs so we can treat it normally
6061
let proto = std::fs::read_to_string(out.join("datafusion.rs")).unwrap();
62+
63+
#[cfg(feature = "json")]
6164
let json = std::fs::read_to_string(out.join("datafusion.serde.rs")).unwrap();
65+
66+
#[cfg(feature = "docsrs")]
67+
let path = out.join("datafusion.rs");
68+
#[cfg(not(feature = "docsrs"))]
69+
let path = "src/generated/datafusion.rs";
70+
6271
let mut file = std::fs::OpenOptions::new()
6372
.write(true)
73+
.truncate(true)
6474
.create(true)
65-
.open("src/generated/datafusion_json.rs")
75+
.open(path)
6676
.unwrap();
67-
file.write(proto.as_str().as_ref()).unwrap();
68-
file.write(json.as_str().as_ref()).unwrap();
77+
file.write_all(proto.as_str().as_ref()).unwrap();
6978

70-
Ok(())
71-
}
79+
#[cfg(feature = "json")]
80+
file.write_all(json.as_str().as_ref()).unwrap();
7281

73-
#[cfg(not(feature = "json"))]
74-
fn build() -> Result<(), String> {
75-
prost_build::Config::new()
76-
.out_dir("src/generated")
77-
.compile_protos(&["proto/datafusion.proto"], &["proto"])
78-
.map_err(|e| format!("protobuf compilation failed: {}", e))
82+
Ok(())
7983
}

datafusion/proto/src/generated/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
// include the generated protobuf source as a submodule
1918
#[allow(clippy::all)]
2019
#[rustfmt::skip]
21-
#[cfg(not(feature = "json"))]
20+
#[cfg(not(docsrs))]
2221
pub mod datafusion;
2322

23+
#[cfg(docsrs)]
2424
#[allow(clippy::all)]
25-
#[rustfmt::skip]
26-
#[cfg(feature = "json")]
27-
pub mod datafusion_json;
25+
pub mod datafusion {
26+
include!(concat!(env!("OUT_DIR"), "/datafusion.rs"));
27+
28+
#[cfg(feature = "json")]
29+
include!(concat!(env!("OUT_DIR"), "/datafusion.serde.rs"));
30+
}

datafusion/proto/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ pub mod generated;
2525
pub mod logical_plan;
2626
pub mod to_proto;
2727

28-
#[cfg(not(feature = "json"))]
2928
pub use generated::datafusion as protobuf;
30-
#[cfg(feature = "json")]
31-
pub use generated::datafusion_json as protobuf;
3229

3330
#[cfg(doctest)]
3431
doc_comment::doctest!("../README.md", readme_example_test);

0 commit comments

Comments
 (0)