Skip to content

Commit 13c1abe

Browse files
committed
workaround for bindgen bug
1 parent 4b0d2fd commit 13c1abe

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ regex = "1.11" # used for build/test
7474
serde = { version = "1.0", features = ["derive"] }
7575
serde_json = "1.0"
7676
shlex = "1.3" # shell lexing, also used by many of our deps
77-
syn = { version = "2", features = ["extra-traits", "full", "parsing"] }
77+
syn = { version = "2", features = ["extra-traits", "full", "parsing", "visit-mut"] }
7878
toml = "0.8" # our config files
7979
toml_edit = "0.22.24" # format-preserving edits to toml files, used with cargo-edit
8080
thiserror = "2"

pgrx-bindgen/src/build.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ fn generate_bindings(
331331
.wrap_err_with(|| format!("bindgen failed for pg{major_version}"))?;
332332

333333
let oids = extract_oids(&bindgen_output);
334-
let rewritten_items = rewrite_items(&bindgen_output, &oids)
334+
let rewritten_items = rewrite_items(bindgen_output, &oids)
335335
.wrap_err_with(|| format!("failed to rewrite items for pg{major_version}"))?;
336336
let oids = format_builtin_oid_impl(oids);
337337

@@ -438,9 +438,10 @@ fn write_rs_file(
438438
/// Given a token stream representing a file, apply a series of transformations to munge
439439
/// the bindgen generated code with some postgres specific enhancements
440440
fn rewrite_items(
441-
file: &syn::File,
441+
mut file: syn::File,
442442
oids: &BTreeMap<syn::Ident, Box<syn::Expr>>,
443443
) -> eyre::Result<proc_macro2::TokenStream> {
444+
rewrite_abi(&mut file);
444445
let items_vec = rewrite_oid_consts(&file.items, oids);
445446
let mut items = apply_pg_guard(&items_vec)?;
446447
let pgnode_impls = impl_pg_node(&items_vec)?;
@@ -829,7 +830,6 @@ fn run_bindgen(
829830
.wrap_static_fns(enable_cshim)
830831
.wrap_static_fns_path(out_path.join("pgrx-cshim-static"))
831832
.wrap_static_fns_suffix("__pgrx_cshim")
832-
.override_abi(bindgen::Abi::CUnwind, ".*")
833833
.generate()
834834
.wrap_err_with(|| format!("Unable to generate bindings for pg{major_version}"))?;
835835
let mut binding_str = bindings.to_string();
@@ -1176,6 +1176,23 @@ fn apply_pg_guard(items: &Vec<syn::Item>) -> eyre::Result<proc_macro2::TokenStre
11761176
Ok(out)
11771177
}
11781178

1179+
fn rewrite_abi(file: &mut syn::File) {
1180+
use proc_macro2::Span;
1181+
use syn::visit_mut::VisitMut;
1182+
use syn::LitStr;
1183+
pub struct Visitor {}
1184+
impl VisitMut for Visitor {
1185+
fn visit_abi_mut(&mut self, abi: &mut syn::Abi) {
1186+
if let Some(name) = &mut abi.name {
1187+
if name.value() == "C" {
1188+
*name = LitStr::new("C-unwind", Span::call_site());
1189+
}
1190+
}
1191+
}
1192+
}
1193+
Visitor {}.visit_file_mut(file);
1194+
}
1195+
11791196
fn rust_fmt(path: &Path) -> eyre::Result<()> {
11801197
// We shouldn't hit this path in a case where we care about it, but... just
11811198
// in case we probably should respect RUSTFMT.

0 commit comments

Comments
 (0)