Skip to content

Commit d1ccd21

Browse files
Split out pgrx-bindgen crate (pgcentralfoundation#1802)
One last essentially-administrative change, and part of the reason that I did all the mucking-about in pgcentralfoundation#1796. We have a lot of code in pgrx-pg-sys's build.rs, and it's high time that we actually split out the real crate that it is. Currently this *just* moves that around, rather than doing any refactoring, to make the git blame trackable. The packaging test generates a sufficiently large cache that it cannot be done for every version of pgrx in the combinatoric fashion that we usually do, thus, we don't anymore! We simply run it for one version.
1 parent 0eb979a commit d1ccd21

File tree

12 files changed

+124
-33
lines changed

12 files changed

+124
-33
lines changed

.github/workflows/package-test.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: verify package can build
2+
3+
on:
4+
push:
5+
branches: [develop]
6+
pull_request:
7+
branches: [develop]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
RUST_BACKTRACE: 1
12+
TOOL_DIR: ./tools
13+
PG_VER: 14
14+
15+
jobs:
16+
ubuntu:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
- uses: Swatinem/rust-cache@v2
22+
with:
23+
prefix-key: "v1-pgrx--package-test"
24+
25+
- name: Install Postgres deps
26+
run: |
27+
sudo apt-get update -y -qq --fix-missing
28+
sudo apt-get install -y postgresql-server-dev-$PG_VER
29+
30+
- name: Rustup
31+
run: $TOOL_DIR/rustup.sh nightly
32+
33+
- name: Install cargo pgrx
34+
run: cargo +nightly install --path cargo-pgrx --debug
35+
36+
- name: cargo pgrx init
37+
run: cargo +nightly pgrx init "--pg$PG_VER=$(which pg_config)"
38+
39+
- name: Test pgrx can be packaged as a new version
40+
run: |
41+
./update-versions.sh 0.0.999-rc.999 && \
42+
cargo +nightly package \
43+
--workspace -Zpackage-workspace \
44+
--allow-dirty \
45+
--features "pg$PG_VER"

.github/workflows/tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,6 @@ jobs:
343343
- name: Run `cargo pgrx schema` against the versioned_custom_libname_so example
344344
run: cd pgrx-examples/versioned_custom_libname_so && cargo pgrx schema pg$PG_VER
345345

346-
- name: Test that version bumps work
347-
run: ./update-versions.sh 0.0.999-rc.999 && cargo +nightly package --workspace -Zpackage-workspace --allow-dirty --features "pg$PG_VER"
348-
349346
# Attempt to make the cache payload slightly smaller.
350347
- name: Clean up built PGRX files
351348
run: |

Cargo.lock

Lines changed: 16 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ members = [
1818
"pgrx-pg-sys",
1919
"pgrx-sql-entity-graph",
2020
"pgrx-tests",
21+
"pgrx-bindgen",
2122
]
2223
exclude = [
2324
# "pgrx-examples/*",
@@ -57,6 +58,7 @@ pgrx-macros = { path = "./pgrx-macros", version = "=0.12.0-beta.3" }
5758
pgrx-pg-sys = { path = "./pgrx-pg-sys", version = "=0.12.0-beta.3" }
5859
pgrx-sql-entity-graph = { path = "./pgrx-sql-entity-graph", version = "=0.12.0-beta.3" }
5960
pgrx-pg-config = { path = "./pgrx-pg-config", version = "=0.12.0-beta.3" }
61+
pgrx-bindgen = { path = "./pgrx-bindgen", version = "0.1" }
6062

6163
cargo_metadata = "0.18.0"
6264
cargo-edit = "0.12.2" # format-preserving edits to cargo.toml

pgrx-bindgen/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "pgrx-bindgen"
3+
description = "additional bindgen support for pgrx"
4+
version = "0.1.0"
5+
edition = "2021"
6+
license = "MIT"
7+
homepage = "https://github.com/pgcentralfoundation/pgrx"
8+
repository = "https://github.com/pgcentralfoundation/pgrx"
9+
docs = "https://docs.rs/pgrx-bindgen"
10+
11+
[dependencies]
12+
pgrx-pg-config.workspace = true
13+
14+
eyre.workspace = true
15+
proc-macro2.workspace = true
16+
syn.workspace = true
17+
walkdir.workspace = true
18+
19+
bindgen = { version = "0.69", default-features = false, features = ["runtime"] }
20+
clang-sys = { version = "1", features = ["clang_6_0", "runtime"] }
21+
quote = "1.0.33"
22+
shlex = "1.3" # shell lexing, also used by many of our deps

pgrx-pg-sys/build.rs renamed to pgrx-bindgen/src/build.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ use syn::{ForeignItem, Item, ItemConst};
2626

2727
const BLOCKLISTED_TYPES: [&str; 3] = ["Datum", "NullableDatum", "Oid"];
2828

29-
mod build {
30-
pub(super) mod clang;
31-
pub(super) mod sym_blocklist;
32-
}
29+
pub(super) mod clang;
30+
pub(super) mod sym_blocklist;
3331

3432
#[derive(Debug)]
3533
struct BindingOverride {
@@ -138,7 +136,7 @@ impl bindgen::callbacks::ParseCallbacks for BindingOverride {
138136
}
139137
}
140138

141-
fn main() -> eyre::Result<()> {
139+
pub fn main() -> eyre::Result<()> {
142140
if env_tracked("DOCS_RS").as_deref() == Some("1") {
143141
return Ok(());
144142
}
@@ -756,7 +754,7 @@ fn run_bindgen(
756754
let configure = pg_config.configure()?;
757755
let preferred_clang: Option<&std::path::Path> = configure.get("CLANG").map(|s| s.as_ref());
758756
eprintln!("pg_config --configure CLANG = {preferred_clang:?}");
759-
let (autodetect, includes) = build::clang::detect_include_paths_for(preferred_clang);
757+
let (autodetect, includes) = clang::detect_include_paths_for(preferred_clang);
760758
let mut binder = bindgen::Builder::default();
761759
binder = add_blocklists(binder);
762760
binder = add_derives(binder);
@@ -1110,7 +1108,7 @@ fn is_blocklisted_item(item: &ForeignItem) -> bool {
11101108
_ => return false,
11111109
};
11121110
BLOCKLISTED
1113-
.get_or_init(|| build::sym_blocklist::SYMBOLS.iter().copied().collect::<BTreeSet<&str>>())
1111+
.get_or_init(|| sym_blocklist::SYMBOLS.iter().copied().collect::<BTreeSet<&str>>())
11141112
.contains(sym_name.to_string().as_str())
11151113
}
11161114

pgrx-pg-sys/build/clang.rs renamed to pgrx-bindgen/src/build/clang.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::target_env_tracked;
1+
use super::target_env_tracked;
22
use bindgen::ClangVersion;
33
use clang_sys::support::Clang as ClangSys;
44
use std::{ffi::OsStr, path::PathBuf};

pgrx-pg-sys/build/sym_blocklist.rs renamed to pgrx-bindgen/src/build/sym_blocklist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
///
3838
/// A future version of pgrx will achieve this effect in a more complete and less
3939
/// hacky manner. Effort should be spent there rather than updating this list.
40-
pub(crate) const SYMBOLS: &[&str] = &[
40+
pub const SYMBOLS: &[&str] = &[
4141
"a64l",
4242
"abort",
4343
"__abort_msg",

pgrx-bindgen/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod build;

pgrx-pg-sys/Cargo.toml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ repository = "https://github.com/pgcentralfoundation/pgrx/"
1919
documentation = "https://docs.rs/pgrx-pg-sys"
2020
readme = "README.md"
2121
edition = "2021"
22-
include = ["src/**/*", "README.md", "include/*", "cshim/*", "build.rs", "build/*"]
22+
include = ["src/**/*", "README.md", "include/*", "cshim/*", "bindgen.rs"]
23+
build = "bindgen.rs"
2324

2425
[features]
2526
default = []
@@ -53,17 +54,7 @@ sptr = "0.3"
5354
cee-scape = "0.2"
5455

5556
[build-dependencies]
56-
pgrx-pg-config.workspace = true
57-
58-
eyre.workspace = true
59-
proc-macro2.workspace = true
60-
syn.workspace = true
61-
walkdir.workspace = true
62-
63-
bindgen = { version = "0.69", default-features = false, features = ["runtime"] }
64-
clang-sys = { version = "1", features = ["clang_6_0", "runtime"] }
65-
quote = "1.0.33"
66-
shlex = "1.3" # shell lexing, also used by many of our deps
57+
pgrx-bindgen.workspace = true
6758

6859
[lints]
6960
# we allow improper_ctypes just to eliminate these warnings:

pgrx-pg-sys/bindgen.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// not a build.rs so that it doesn't inherit the git history of the build.rs
2+
3+
// little-known Rust quirk: you can import main from wherever
4+
use pgrx_bindgen::build::main;

publish.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,31 @@
1313
DIR=`pwd`
1414
set -x
1515

16+
# dependency graph, from roots to facades
17+
#
18+
# pgrx-pg-config
19+
# ├── cargo-pgrx
20+
# ├── pgrx-bindgen
21+
# │ [build-dependencies]
22+
# │ └── pgrx-pg-sys
23+
# │ └── pgrx
24+
# │ └── pgrx-tests
25+
# └── pgrx-tests
26+
#
27+
# pgrx-sql-entity-graph
28+
# ├── cargo-pgrx
29+
# ├── pgrx
30+
# │ └── pgrx-tests
31+
# ├── pgrx-macros
32+
# │ ├── pgrx
33+
# │ ├── pgrx-pg-sys
34+
# │ │ └── pgrx
35+
# │ └── pgrx-tests
36+
# └── pgrx-pg-sys
37+
38+
1639
cd $DIR/pgrx-pg-config && cargo publish
40+
cd $DIR/pgrx-bindgen && cargo publish
1741
cd $DIR/pgrx-sql-entity-graph && cargo publish
1842
cd $DIR/pgrx-macros && cargo publish
1943
cd $DIR/pgrx-pg-sys && cargo publish --no-verify

0 commit comments

Comments
 (0)