Repository navigation
Conversation
…kend Draft/RFC. A `pgrust` feature beside pg13..pg19 that replaces the C-ABI boundary layer (bindgen bindings, sigsetjmp barrier, CurrentMemoryContext global, dlopen/dlsym) with a backend module written over pgrust's crates, while everything above it (#[pg_extern], Spi, datum conversions, SRFs, aggregates, composite types, GUCs, the SQL entity graph) stays unchanged. Ten extensions run from unchanged source under the target: the examples strings, arrays, srf, json, spi, aggregate, composite_type, plus pg_jsonschema, pg_graphql and a GUC/_PG_init test extension. The feature's host path deps resolve only inside the pgrust tree; CI with the feature off is unaffected. See docs/pgrust/pgrx-target.md. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
pgrust target that runs pgrx extensions inside a Rust Postgres backendpgrust target that runs pgrx extensions inside a Rust Postgres backend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft / RFC, not for merging as is. This branch shows what it takes to run unchanged pgrx extensions inside a Postgres backend that is not the C one: it adds a
pgrusttarget feature besidepg13..pg19, where pgrust is an in-progress Rust reimplementation of the PostgreSQL backend (thread-per-backend,Result-based errors, explicit memory contexts, no C ABI). Ten extensions run from unchanged source: the pgrx-examplesstrings,arrays,srf,json,spi,aggregate,composite_type, pluspg_jsonschema,pg_graphql(introspection, queries, mutations) and a custom-GUC/_PG_inittest extension.The feature does not build in this repository on its own:
pgrx-pg-sys's backend module is written over the host's crates, declared here as path dependencies that resolve only inside the pgrust tree (this repo is vendored there undercrates/pgrx). Everything else, including CI with the feature off, is unaffected. The point of the PR is the code and the shape, and to ask whether a non-C target is something pgrx would want to carry.What changes
Everything above the boundary layer is untouched:
#[pg_extern],Spi,JsonB,Array,PgHeapTuple, aggregates, GUCs, the SQL entity graph. Below it, under#[cfg(feature = "pgrust")]:pgrx-pg-sys/src/pgrust/replaces the bindgen bindings. C-layout types are harvested from the PG18 bindings (types.rs, generated byharvest-bindings.py; on-datum layouts are identical in the host). Every function pgrx calls is hand-written over a host crate: memory (mem.rs), errors (error.rs), the C-shaped call frame built around the host's native frame (fmgr.rs), SQL-callable builtins with the Cfn(FunctionCallInfo) -> Datumshape (bridge.rs), tuple descriptors and heap tuples (tuples.rs), custom GUCs (guc.rs), SRFs (srf.rs), and the registry (registry.rs).finfo_v1_extern_cemits the host's native wrapper signature and alinkmeregistry entry instead of a#[no_mangle]symbol pluspg_finfo_*.__pgrx_schema_entry!also adds each entity payload to a registry slice, so the host generates the extension SQL at startup withPgrxSql::build().to_sql()(no object file to read a section from).pg_module_magic!emits an extension descriptor and aninit_seams()instead ofPg_magic_func.#[pg_guard] fn _PG_initjoins a slice the host runs on first load.CurrentMemoryContextreads go through one accessor (a per-thread cell on the host);SetOfIterator/TableIteratormaterialize instead of value-per-call;Spigets a second implementation (pgrx/src/spi_pgrust/) over the host's SPI handles;GucSetting::get()reads the host's store; the thread check and thesigsetjmpFFI boundary are compiled out; modules that need C-shaped backend state (bgworkers, shmem, lwlock, hooks, triggers, rel, nodes, list, fn_call, syscache) are gated out for now.Err(PgError)panics with a payload thatdowncast_panic_payloadmaps toCaughtError::PostgresError(original error kept), soPgTryBuilderworks unchanged; the wrapper's singlecatch_unwindturns any payload back into the host'sErr.docs/pgrust/pgrx-target.mdhas the full contract, costs, and gaps.pgrust-e2e/is the SQL suite the ten extensions were verified with.Not in this branch
The host-side changes (an embedded-extension registry so
CREATE EXTENSIONreads the generated script from the crate, runtime custom-GUC definition), the ten extension crates, and the harness that builds and links them. Not done anywhere yet: enum GUCs and GUC hooks, range types, background workers, shared memory, hooks, triggers,cargo pgrx test.Questions for maintainers
cfg-isolated?pgrx-pg-sys) to show the surface first. Which shape would you want?🤖 Generated with Claude Code