Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
submodules: recursive

- name: Cache cargo registry
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
shell: bash

- name: Cache cargo registry
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
Expand Down
57 changes: 17 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ repository = "https://github.com/pganalyze/pg_query.rs"

[dependencies]
itertools = "0.10.3"
prost = "0.10.4"
prost = "0.13.5"
serde = { version = "1.0.139", features = ["derive"] }
serde_json = "1.0.82"
thiserror = "1.0.31"

[build-dependencies]
bindgen = "0.66.1"
clippy = { version = "0.0.302", optional = true }
prost-build = "0.10.4"
prost-build = "0.13.5"
fs_extra = "1.2.0"
cc = "1.0.83"
glob = "0.3.1"
Expand Down
22 changes: 20 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ use fs_extra::dir::CopyOptions;
use glob::glob;
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;

static SOURCE_DIRECTORY: &str = "libpg_query";
static LIBRARY_NAME: &str = "pg_query";

fn main() -> Result<(), Box<dyn std::error::Error>> {
// return if proto file changes
println!("cargo:rerun-if-changed=libpg_query/protobuf/pg_query.proto");

let out_dir = PathBuf::from(env::var("OUT_DIR")?);
let build_path = Path::new(".").join(SOURCE_DIRECTORY);
let out_header_path = out_dir.join(LIBRARY_NAME).with_extension("h");
Expand Down Expand Up @@ -64,8 +68,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.map_err(|_| "Unable to generate bindings")?
.write_to_file(out_dir.join("bindings.rs"))?;

// Generate the protobuf definition
prost_build::compile_protos(&[&out_protobuf_path.join(LIBRARY_NAME).with_extension("proto")], &[&out_protobuf_path])?;
let protoc_exists = Command::new("protoc").arg("--version").status().is_ok();
if env::var("REGENERATE_PROTOBUF").is_ok() || protoc_exists {
println!("generating protobuf bindings");
// HACK: Set OUT_DIR to src/ so that the generated protobuf file is copied to src/protobuf.rs
let src_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?).join("src");
env::set_var("OUT_DIR", &src_dir);

prost_build::compile_protos(&[&out_protobuf_path.join(LIBRARY_NAME).with_extension("proto")], &[&out_protobuf_path])?;

std::fs::rename(src_dir.join("pg_query.rs"), src_dir.join("protobuf.rs"))?;
Copy link
Member

Choose a reason for hiding this comment

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

It seems like this line broke the docs.rs build https://docs.rs/crate/pg_query/6.1.0/builds/1945029

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should detect the DOCS_RS envvar like polywrap/rust-wrap-client#245 does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pr with the fix is up: #56


// Reset OUT_DIR to the original value
env::set_var("OUT_DIR", &out_dir);
} else {
println!("skipping protobuf generation");
}

Ok(())
}
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ mod node_mut;
mod node_ref;
mod node_structs;
mod parse_result;
pub mod protobuf;
mod query;
mod truncate;

Expand All @@ -56,10 +57,6 @@ pub use parse_result::*;
pub use query::*;
pub use truncate::*;

pub mod protobuf {
include!(concat!(env!("OUT_DIR"), "/pg_query.rs"));
}

pub use protobuf::Node;

// From Postgres source: src/include/storage/lockdefs.h
Expand Down
Loading