mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-07 13:32:57 +00:00
* Add submodule postgres-15 * Support pg_15 in pgxn/neon * Renamed zenith -> neon in Makefile * fix name of codestyle check * Refactor build system to prepare for building multiple Postgres versions. Rename "vendor/postgres" to "vendor/postgres-v14" Change Postgres build and install directory paths to be version-specific: - tmp_install/build -> pg_install/build/14 - tmp_install/* -> pg_install/14/* And Makefile targets: - "make postgres" -> "make postgres-v14" - "make postgres-headers" -> "make postgres-v14-headers" - etc. Add Makefile aliases: - "make postgres" to build "postgres-v14" and in future, "postgres-v15" - similarly for "make postgres-headers" Fix POSTGRES_DISTRIB_DIR path in pytest scripts * Make postgres version a variable in codestyle workflow * Support vendor/postgres-v15 in codestyle check workflow * Support postgres-v15 building in Makefile * fix pg version in Dockerfile.compute-node * fix kaniko path * Build neon extensions in version-specific directories * fix obsolete mentions of vendor/postgres * use vendor/postgres-v14 in Dockerfile.compute-node.legacy * Use PG_VERSION_NUM to gate dependencies in inmem_smgr.c * Use versioned ECR repositories and image names for compute-node. The image name format is compute-node-vXX, where XX is postgres major version number. For now only v14 is supported. Old format unversioned name (compute-node) is left, because cloud repo depends on it. * update vendor/postgres submodule url (zenith->neondatabase rename) * Fix postgres path in python tests after rebase * fix path in regress test * Use separate dockerfiles to build compute-node: Dockerfile.compute-node-v15 should be identical to Dockerfile.compute-node-v14 except for the version number. This is a hack, because Kaniko doesn't support build ARGs properly * bump vendor/postgres-v14 and vendor/postgres-v15 * Don't use Kaniko cache for v14 and v15 compute-node images * Build compute-node images for different versions in different jobs Co-authored-by: Heikki Linnakangas <heikki@neon.tech>
138 lines
4.8 KiB
Rust
138 lines
4.8 KiB
Rust
extern crate bindgen;
|
|
|
|
use std::env;
|
|
use std::path::PathBuf;
|
|
use std::process::Command;
|
|
|
|
use bindgen::callbacks::ParseCallbacks;
|
|
|
|
#[derive(Debug)]
|
|
struct PostgresFfiCallbacks;
|
|
|
|
impl ParseCallbacks for PostgresFfiCallbacks {
|
|
fn include_file(&self, filename: &str) {
|
|
// This does the equivalent of passing bindgen::CargoCallbacks
|
|
// to the builder .parse_callbacks() method.
|
|
let cargo_callbacks = bindgen::CargoCallbacks;
|
|
cargo_callbacks.include_file(filename)
|
|
}
|
|
|
|
// Add any custom #[derive] attributes to the data structures that bindgen
|
|
// creates.
|
|
fn add_derives(&self, name: &str) -> Vec<String> {
|
|
// This is the list of data structures that we want to serialize/deserialize.
|
|
let serde_list = [
|
|
"XLogRecord",
|
|
"XLogPageHeaderData",
|
|
"XLogLongPageHeaderData",
|
|
"CheckPoint",
|
|
"FullTransactionId",
|
|
"ControlFileData",
|
|
];
|
|
|
|
if serde_list.contains(&name) {
|
|
vec![
|
|
"Default".into(), // Default allows us to easily fill the padding fields with 0.
|
|
"Serialize".into(),
|
|
"Deserialize".into(),
|
|
]
|
|
} else {
|
|
vec![]
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
// Tell cargo to invalidate the built crate whenever the wrapper changes
|
|
println!("cargo:rerun-if-changed=bindgen_deps.h");
|
|
|
|
// Finding the location of C headers for the Postgres server:
|
|
// - if POSTGRES_INSTALL_DIR is set look into it, otherwise look into `<project_root>/pg_install`
|
|
// - if there's a `bin/pg_config` file use it for getting include server, otherwise use `<project_root>/pg_install/v14/include/postgresql/server`
|
|
let mut pg_install_dir = if let Some(postgres_install_dir) = env::var_os("POSTGRES_INSTALL_DIR")
|
|
{
|
|
postgres_install_dir.into()
|
|
} else {
|
|
PathBuf::from("pg_install")
|
|
};
|
|
// Currently, we only expect to find PostgreSQL v14 sources, in "pg_install/v14". In the
|
|
// future, we will run this for all supported PostgreSQL versions.
|
|
pg_install_dir.push("v14");
|
|
|
|
if pg_install_dir.is_relative() {
|
|
let cwd = env::current_dir().unwrap();
|
|
pg_install_dir = cwd.join("..").join("..").join(pg_install_dir);
|
|
}
|
|
|
|
let pg_config_bin = pg_install_dir.join("bin").join("pg_config");
|
|
let inc_server_path: String = if pg_config_bin.exists() {
|
|
let output = Command::new(pg_config_bin)
|
|
.arg("--includedir-server")
|
|
.output()
|
|
.expect("failed to execute `pg_config --includedir-server`");
|
|
|
|
if !output.status.success() {
|
|
panic!("`pg_config --includedir-server` failed")
|
|
}
|
|
|
|
String::from_utf8(output.stdout).unwrap().trim_end().into()
|
|
} else {
|
|
pg_install_dir
|
|
.join("include")
|
|
.join("postgresql")
|
|
.join("server")
|
|
.into_os_string()
|
|
.into_string()
|
|
.unwrap()
|
|
};
|
|
|
|
// The bindgen::Builder is the main entry point
|
|
// to bindgen, and lets you build up options for
|
|
// the resulting bindings.
|
|
let bindings = bindgen::Builder::default()
|
|
//
|
|
// All the needed PostgreSQL headers are included from 'bindgen_deps.h'
|
|
//
|
|
.header("bindgen_deps.h")
|
|
//
|
|
// Tell cargo to invalidate the built crate whenever any of the
|
|
// included header files changed.
|
|
//
|
|
.parse_callbacks(Box::new(PostgresFfiCallbacks))
|
|
//
|
|
// These are the types and constants that we want to generate bindings for
|
|
//
|
|
.allowlist_type("BlockNumber")
|
|
.allowlist_type("OffsetNumber")
|
|
.allowlist_type("MultiXactId")
|
|
.allowlist_type("MultiXactOffset")
|
|
.allowlist_type("MultiXactStatus")
|
|
.allowlist_type("ControlFileData")
|
|
.allowlist_type("CheckPoint")
|
|
.allowlist_type("FullTransactionId")
|
|
.allowlist_type("XLogRecord")
|
|
.allowlist_type("XLogPageHeaderData")
|
|
.allowlist_type("XLogLongPageHeaderData")
|
|
.allowlist_var("XLOG_PAGE_MAGIC")
|
|
.allowlist_var("PG_CONTROL_FILE_SIZE")
|
|
.allowlist_var("PG_CONTROLFILEDATA_OFFSETOF_CRC")
|
|
.allowlist_type("PageHeaderData")
|
|
.allowlist_type("DBState")
|
|
// Because structs are used for serialization, tell bindgen to emit
|
|
// explicit padding fields.
|
|
.explicit_padding(true)
|
|
//
|
|
.clang_arg(format!("-I{inc_server_path}"))
|
|
//
|
|
// Finish the builder and generate the bindings.
|
|
//
|
|
.generate()
|
|
.expect("Unable to generate bindings");
|
|
|
|
// Write the bindings to the $OUT_DIR/bindings.rs file.
|
|
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
|
bindings
|
|
.write_to_file(out_path.join("bindings.rs"))
|
|
.expect("Couldn't write bindings!");
|
|
}
|