Skip to content

Commit

Permalink
take a slightly different approach with the code
Browse files Browse the repository at this point in the history
  • Loading branch information
eeeebbbbrrrr committed Nov 22, 2024
1 parent a70b33c commit 082c3d7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
35 changes: 19 additions & 16 deletions pgrx-bindgen/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bindgen::callbacks::{DeriveTrait, EnumVariantValue, ImplementsTrait, MacroPa
use bindgen::NonCopyUnionStyle;
use eyre::{eyre, WrapErr};
use pgrx_pg_config::{
is_supported_major_version, PgConfig, PgConfigSelector, PgMinorVersion, Pgrx,
is_supported_major_version, PgConfig, PgConfigSelector, PgMinorVersion, PgVersion, Pgrx,
SUPPORTED_VERSIONS,
};
use quote::{quote, ToTokens};
Expand All @@ -28,16 +28,16 @@ const BLOCKLISTED_TYPES: [&str; 3] = ["Datum", "NullableDatum", "Oid"];

// These postgres versions were effectively "yanked" by the community, even tho they still exist
// in the wild. pgrx will refuse to compile against them
const YANKED_POSTGRES_VERSIONS: &[(u16, u16)] = &[
const YANKED_POSTGRES_VERSIONS: &[PgVersion] = &[
// this set of releases introduced an ABI break in the [`pg_sys::ResultRelInfo`] struct
// and was replaced by the community on 2024-11-21
// https://www.postgresql.org/about/news/postgresql-172-166-1510-1415-1318-and-1222-released-2965/
(17, 1),
(16, 5),
(15, 9),
(14, 14),
(13, 17),
(12, 21),
PgVersion::new(17, PgMinorVersion::Release(1), None),
PgVersion::new(16, PgMinorVersion::Release(5), None),
PgVersion::new(15, PgMinorVersion::Release(9), None),
PgVersion::new(14, PgMinorVersion::Release(14), None),
PgVersion::new(13, PgMinorVersion::Release(17), None),
PgVersion::new(12, PgMinorVersion::Release(21), None),
];

pub(super) mod clang;
Expand Down Expand Up @@ -227,14 +227,6 @@ pub fn main() -> eyre::Result<()> {
if let Ok(pg_config) = PgConfig::from_env() {
let major_version = pg_config.major_version()?;

if let PgMinorVersion::Release(minor_version_number) = pg_config.minor_version()? {
if YANKED_POSTGRES_VERSIONS.contains(&(major_version, minor_version_number)) {
panic!("Postgres v{major_version}.{minor_version_number} is incompatible with \
other versions in this major series and is not supported by pgrx. Please upgrade \
to the latest version in the v{major_version} series.");
}
}

if major_version != found_major {
panic!("Feature flag `pg{found_major}` does not match version from the environment-described PgConfig (`{major_version}`)")
}
Expand All @@ -244,6 +236,17 @@ pub fn main() -> eyre::Result<()> {
vec![(found_ver.major, specific)]
}
};

// make sure we're not trying to build any of the yanked postgres versions
for (_, pg_config) in &pg_configs {
let version = pg_config.get_version()?;
if YANKED_POSTGRES_VERSIONS.contains(&version) {
panic!("Postgres v{}{} is incompatible with \
other versions in this major series and is not supported by pgrx. Please upgrade \
to the latest version in the v{} series.", version.major, version.minor, version.major);
}
}

std::thread::scope(|scope| {
// This is pretty much either always 1 (normally) or 5 (for releases),
// but in the future if we ever have way more, we should consider
Expand Down
13 changes: 7 additions & 6 deletions pgrx-pg-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl PgMinorVersion {
}
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PgVersion {
pub major: u16,
pub minor: PgMinorVersion,
Expand Down Expand Up @@ -269,22 +269,23 @@ impl PgConfig {
Ok((major, minor))
}

fn get_version(&self) -> eyre::Result<(u16, PgMinorVersion)> {
pub fn get_version(&self) -> eyre::Result<PgVersion> {
let version_string = self.run("--version")?;
Self::parse_version_str(&version_string)
let (major, minor) = Self::parse_version_str(&version_string)?;
Ok(PgVersion::new(major, minor, None))
}

pub fn major_version(&self) -> eyre::Result<u16> {
match &self.version {
Some(version) => Ok(version.major),
None => Ok(self.get_version()?.0),
None => Ok(self.get_version()?.major),
}
}

pub fn minor_version(&self) -> eyre::Result<PgMinorVersion> {
fn minor_version(&self) -> eyre::Result<PgMinorVersion> {
match &self.version {
Some(version) => Ok(version.minor),
None => Ok(self.get_version()?.1),
None => Ok(self.get_version()?.minor),
}
}

Expand Down

0 comments on commit 082c3d7

Please sign in to comment.