diff --git a/.cargo/config.toml b/.cargo/config.toml index 13c456b5dd..fe681c554e 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,6 @@ [target.'cfg(target_os="macos")'] # Postgres symbols won't be available until runtime rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"] + +[env] +PGRX_EMBED = "../../embed.rs" diff --git a/Cargo.lock b/Cargo.lock index 50ce48778e..276e796f41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -361,9 +361,7 @@ dependencies = [ "eyre", "flate2", "jobslot", - "libloading 0.8.1", "nix", - "object", "once_cell", "owo-colors", "pgrx-pg-config", @@ -453,7 +451,7 @@ checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" dependencies = [ "glob", "libc", - "libloading 0.7.4", + "libloading", ] [[package]] @@ -1167,16 +1165,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "libloading" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - [[package]] name = "libm" version = "0.2.8" @@ -1389,9 +1377,7 @@ version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" dependencies = [ - "flate2", "memchr", - "ruzstd", ] [[package]] @@ -1786,9 +1772,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] @@ -2098,17 +2084,6 @@ dependencies = [ "wait-timeout", ] -[[package]] -name = "ruzstd" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3ffab8f9715a0d455df4bbb9d21e91135aab3cd3ca187af0cd0c3c3f868fdc" -dependencies = [ - "byteorder", - "thiserror-core", - "twox-hash", -] - [[package]] name = "ryu" version = "1.0.16" @@ -2401,12 +2376,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "stringprep" version = "0.1.4" @@ -2564,26 +2533,6 @@ dependencies = [ "thiserror-impl", ] -[[package]] -name = "thiserror-core" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c001ee18b7e5e3f62cbf58c7fe220119e68d902bb7443179c0c8aef30090e999" -dependencies = [ - "thiserror-core-impl", -] - -[[package]] -name = "thiserror-core-impl" -version = "1.0.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4c60d69f36615a077cc7663b9cb8e42275722d23e58a7fa3d2c7f2915d09d04" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.41", -] - [[package]] name = "thiserror-impl" version = "1.0.51" @@ -2844,16 +2793,6 @@ dependencies = [ "termcolor", ] -[[package]] -name = "twox-hash" -version = "1.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" -dependencies = [ - "cfg-if", - "static_assertions", -] - [[package]] name = "typenum" version = "1.17.0" diff --git a/README.md b/README.md index 9463d57aa5..aab17ae585 100644 --- a/README.md +++ b/README.md @@ -157,13 +157,6 @@ For more details on how to manage pgrx extensions see [Managing pgrx extensions] ## Upgrading -You can upgrade your current `cargo-pgrx` installation by passing the `--force` flag -to `cargo install`: - -```bash -cargo install --force --locked cargo-pgrx -``` - As new Postgres versions are supported by `pgrx`, you can re-run the `pgrx init` process to download and compile them: ```bash diff --git a/cargo-pgrx/Cargo.toml b/cargo-pgrx/Cargo.toml index d6270be154..babd177abb 100644 --- a/cargo-pgrx/Cargo.toml +++ b/cargo-pgrx/Cargo.toml @@ -35,7 +35,7 @@ env_proxy = "0.4.1" pgrx-pg-config = { path = "../pgrx-pg-config", version = "=0.11.2" } pgrx-sql-entity-graph = { path = "../pgrx-sql-entity-graph", version = "=0.11.2" } prettyplease = "0.2.15" -proc-macro2 = { version = "1.0.69", features = [ "span-locations" ] } +proc-macro2 = { version = "1.0.76" } quote = "1.0.33" regex = "1.10.0" ureq = { version = "2.8.0", default-features = false, features = [ "gzip" ] } @@ -43,10 +43,8 @@ url = "2.4.1" serde = { version = "1.0", features = [ "derive" ] } serde_derive = "1.0" serde-xml-rs = "0.6.0" -syn = { version = "2.0.18", features = [ "extra-traits", "full", "fold", "parsing" ] } +syn = { version = "2.0.18", features = ["extra-traits", "full", "fold", "parsing", "visit"] } unescape = "0.1.0" -libloading = "0.8.1" -object = "0.32.1" once_cell = "1.18.0" eyre = "0.6.8" color-eyre = "0.6.2" diff --git a/cargo-pgrx/README.md b/cargo-pgrx/README.md index 84cc16ce63..9f049c731d 100644 --- a/cargo-pgrx/README.md +++ b/cargo-pgrx/README.md @@ -14,7 +14,7 @@ Install via crates.io: $ cargo install --locked cargo-pgrx ``` -As new versions of `pgrx` are released, you'll want to make sure you run this command again to update it. You should also reinstall `cargo-pgrx` whenever you update `rustc` so that the same compiler is used to build `cargo-pgrx` and your Postgres extensions. You can force `cargo` to reinstall an existing crate by passing `--force`. +As new versions of `pgrx` are released, you'll want to make sure you run this command again to update it. ## Usage @@ -682,30 +682,3 @@ Postgres, so loading two versions of the shared library will cause trouble. These scenarios are: - when using shared memory - when using query planner hooks - -## Compiler Version Dependence - -The version of the Rust compiler and toolchain used to build `cargo-pgrx` must be -the same as the version used to build your extension. - -Several subcommands (including `cargo pgrx schema`, `cargo pgrx test`, `cargo pgrx -install`, ...) will produce an error message if these do not match. - -Although this may be relaxed in the future, currently schema generation involves -`dlopen`ing the extension and calling `extern "Rust"` functions on -`#[repr(Rust)]` types. Generally, the appropriate way to fix this is reinstall -`cargo-pgrx`, using a command like the following - -```console -$ cargo install --force --locked cargo-pgrx -``` - -Possibly with a explicit `--version`, if needed. - -If you are certain that in this case, it is fine, you may set -`PGRX_IGNORE_RUST_VERSIONS` in the environment (to any value other than `"0"`), -and the check will be bypassed. However, note that while the check is not -fool-proof, it tries to be fairly liberal in what it allows. - -See and -for further information. diff --git a/cargo-pgrx/src/command/install.rs b/cargo-pgrx/src/command/install.rs index d808d7320b..032b5fa53d 100644 --- a/cargo-pgrx/src/command/install.rs +++ b/cargo-pgrx/src/command/install.rs @@ -232,7 +232,6 @@ pub(crate) fn install_extension( features, &extdir, &base_directory, - true, &mut output_tracking, )?; @@ -370,7 +369,6 @@ fn copy_sql_files( features: &clap_cargo::Features, extdir: &PathBuf, base_directory: &PathBuf, - skip_build: bool, output_tracking: &mut Vec, ) -> eyre::Result<()> { let dest = get_target_sql_file(&package_manifest_path, extdir, base_directory)?; @@ -387,7 +385,6 @@ fn copy_sql_files( Some(&dest), Option::::None, None, - skip_build, output_tracking, )?; diff --git a/cargo-pgrx/src/command/new.rs b/cargo-pgrx/src/command/new.rs index 20c9b4e043..c3fc8ecc69 100644 --- a/cargo-pgrx/src/command/new.rs +++ b/cargo-pgrx/src/command/new.rs @@ -57,6 +57,8 @@ pub(crate) fn create_crate_template( create_dotcargo_config_toml(&path, name)?; create_lib_rs(&path, name, is_bgworker)?; create_git_ignore(&path, name)?; + create_embed_rs(&path, name)?; + create_pgrx_rs(&path, name)?; Ok(()) } @@ -67,13 +69,21 @@ fn create_directory_structure(path: &PathBuf) -> Result<(), std::io::Error> { src_dir.push("src"); std::fs::create_dir_all(&src_dir)?; + src_dir.push("bin"); + std::fs::create_dir_all(&src_dir)?; + src_dir.pop(); + src_dir.pop(); + src_dir.push(".cargo"); std::fs::create_dir_all(&src_dir)?; - src_dir.pop(); + src_dir.push("sql"); - std::fs::create_dir_all(&src_dir) + std::fs::create_dir_all(&src_dir)?; + src_dir.pop(); + + Ok(()) } fn create_control_file(path: &PathBuf, name: &str) -> Result<(), std::io::Error> { @@ -138,3 +148,21 @@ fn create_git_ignore(path: &PathBuf, _name: &str) -> Result<(), std::io::Error> Ok(()) } + +fn create_embed_rs(path: &PathBuf, _name: &str) -> Result<(), std::io::Error> { + let mut filename = path.clone(); + filename.push("embed.rs"); + let mut file = std::fs::File::create(filename)?; + file.write_all(include_bytes!("../templates/embed_rs"))?; + Ok(()) +} + +fn create_pgrx_rs(path: &PathBuf, _name: &str) -> Result<(), std::io::Error> { + let mut filename = path.clone(); + filename.push("src"); + filename.push("bin"); + filename.push("pgrx.rs"); + let mut file = std::fs::File::create(filename)?; + file.write_all(include_bytes!("../templates/pgrx_rs"))?; + Ok(()) +} diff --git a/cargo-pgrx/src/command/schema.rs b/cargo-pgrx/src/command/schema.rs index 481fd2bd05..f0d65aae13 100644 --- a/cargo-pgrx/src/command/schema.rs +++ b/cargo-pgrx/src/command/schema.rs @@ -9,33 +9,20 @@ //LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file. use crate::command::get::{find_control_file, get_property}; use crate::command::install::format_display_path; -use crate::pgrx_pg_sys_stub::PgrxPgSysStub; use crate::profile::CargoProfile; use crate::CommandExecute; use cargo_toml::Manifest; use eyre::{eyre, WrapErr}; -use object::read::macho::{FatArch, FatHeader}; -use object::{Architecture, FileKind, Object}; -use once_cell::sync::OnceCell; use owo_colors::OwoColorize; -use pgrx_pg_config::{cargo::PgrxManifestExt, get_target_dir, PgConfig, Pgrx}; -use std::collections::HashSet; -use std::hash::{Hash, Hasher}; +use pgrx_pg_config::cargo::PgrxManifestExt; +use pgrx_pg_config::{get_target_dir, PgConfig, Pgrx}; +use std::io::Write; use std::path::{Path, PathBuf}; use std::process::Stdio; // Since we support extensions with `#[no_std]` extern crate alloc; use crate::manifest::{get_package_manifest, pg_config_and_version}; use alloc::vec::Vec; -use std::env; - -// An apparent bug in `glibc` 2.17 prevents us from safely dropping this -// otherwise users find issues such as https://github.com/pgcentralfoundation/pgrx/issues/572 -static POSTMASTER_LIBRARY: OnceCell = OnceCell::new(); - -// An apparent bug in `glibc` 2.17 prevents us from safely dropping this -// otherwise users find issues such as https://github.com/pgcentralfoundation/pgrx/issues/572 -static EXTENSION_LIBRARY: OnceCell = OnceCell::new(); /// Generate extension schema files #[derive(clap::Args, Debug)] @@ -71,9 +58,6 @@ pub(crate) struct Schema { dot: Option, #[clap(from_global, action = ArgAction::Count)] verbose: u8, - /// Skip building a fresh extension shared object. - #[clap(long)] - skip_build: bool, } impl CommandExecute for Schema { @@ -120,56 +104,11 @@ impl CommandExecute for Schema { self.out.as_ref(), self.dot, log_level, - self.skip_build, &mut vec![], ) } } -/// Gets the current `cargo` version. -/// -/// This is a copy of the function in `build.rs`. -/// -/// [Environment variables Cargo sets for 3rd party subcommands](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-3rd-party-subcommands) -fn cargo_version() -> Option { - let cargo = std::env::var_os("CARGO").expect("`CARGO` env var wasn't set!"); - let output = std::process::Command::new(cargo).arg("--version").output().ok()?; - std::str::from_utf8(&output.stdout).map(|s| s.trim().to_string()).ok() -} - -/// Returns an error if the rust toolchain version used to build `cargo-pgrx` -/// doesn't match the active toolchain's version. -/// -/// This is an error because we `dlopen` rust code that we build, and call -/// `extern "Rust"` functions on `#[repr(Rust)]` types. This may be relaxed in -/// the future, but for now is a requirement. -/// -/// To waive this, you may set `PGRX_IGNORE_RUST_VERSIONS` in the environment -/// (to any value other than `"0"`). Also, note that this check is best-effort -/// only, and is expected to error only if there is a definite mismatch. -/// -/// It also cannot detect versions of `cargo-pgrx` and `pgrx` differing, which -/// could cause similar issues (in the future this may be detected). -fn check_rust_version() -> eyre::Result<()> { - const CARGO_VERSION_DURING_BUILD: &str = env!("CARGO_VERSION_DURING_BUILD"); - if matches!(std::env::var("PGRX_IGNORE_RUST_VERSIONS"), Ok(s) if s != "0") { - return Ok(()); - } - if let (Some(during_build), Some(during_run)) = - (Some(CARGO_VERSION_DURING_BUILD), cargo_version()) - { - if during_build != during_run { - eyre::bail!( - "Mismatched toolchain versions: \ - `cargo-pgrx` was built with `{during_build}`, \ - but `{during_run}` is currently in use. \ - Set `PGRX_IGNORE_RUST_VERSIONS=1` to override this safety check.", - ); - } - } - Ok(()) -} - #[tracing::instrument(level = "error", skip_all, fields( pg_version = %pg_config.version()?, profile = ?profile, @@ -189,11 +128,10 @@ pub(crate) fn generate_schema( path: Option>, dot: Option>, log_level: Option, - skip_build: bool, output_tracking: &mut Vec, ) -> eyre::Result<()> { - check_rust_version()?; let manifest = Manifest::from_path(&package_manifest_path)?; + let (control_file, _extname) = find_control_file(&package_manifest_path)?; if get_property(&package_manifest_path, "relocatable")? != Some("false".into()) { @@ -203,228 +141,45 @@ pub(crate) fn generate_schema( )); } - let versioned_so = get_property(&package_manifest_path, "module_pathname")?.is_none(); - - let flags = std::env::var("PGRX_BUILD_FLAGS").unwrap_or_default(); - let mut target_dir_with_profile = get_target_dir()?; target_dir_with_profile.push(profile.target_subdir()); - // First, build the SQL generator so we can get a look at the symbol table - if !skip_build { - let mut command = crate::env::cargo(); - command.stderr(Stdio::inherit()); - command.stdout(Stdio::inherit()); - if is_test { - command.arg("test"); - command.arg("--no-run"); - } else { - command.arg("build"); - } - - if let Some(user_package) = user_package { - command.arg("--package"); - command.arg(user_package); - } - - if let Some(user_manifest_path) = user_manifest_path { - command.arg("--manifest-path"); - command.arg(user_manifest_path.as_ref()); - } - - command.args(profile.cargo_args()); - - if let Some(log_level) = &log_level { - command.env("RUST_LOG", log_level); - } - - let features_arg = features.features.join(" "); - if !features_arg.trim().is_empty() { - command.arg("--features"); - command.arg(&features_arg); - } - - if features.no_default_features { - command.arg("--no-default-features"); - } - - if features.all_features { - command.arg("--all-features"); - } - - for arg in flags.split_ascii_whitespace() { - command.arg(arg); - } - - let command = command.stderr(Stdio::inherit()); - let command_str = format!("{:?}", command); - eprintln!( - "{} for SQL generation with features `{}`", - " Building".bold().green(), - features_arg, - ); - - tracing::debug!(command = %command_str, "Running"); - let cargo_output = - command.output().wrap_err_with(|| format!("failed to spawn cargo: {}", command_str))?; - tracing::trace!(status_code = %cargo_output.status, command = %command_str, "Finished"); - - if !cargo_output.status.success() { - // We explicitly do not want to return a spantraced error here. - std::process::exit(1) - } - }; - - // Create stubbed `pgrx_pg_sys` bindings for the generator to link with. - let mut postmaster_stub_dir = - Pgrx::postmaster_stub_dir().wrap_err("couldn't get postmaster stub dir env")?; - - postmaster_stub_dir.push( - pg_config - .postmaster_path() - .wrap_err("couldn't get postmaster path")? - .strip_prefix("/") - .wrap_err("couldn't make postmaster path relative")? - .parent() - .ok_or(eyre!("couldn't get postmaster parent dir"))?, - ); - - let postmaster_path = pg_config.postmaster_path().wrap_err("could not get postmaster path")?; - - // The next action may take a few seconds, we'd like the user to know we're thinking. - eprintln!("{} SQL entities", " Discovering".bold().green(),); - - let postmaster_stub_built = create_stub(postmaster_path, &postmaster_stub_dir)?; - - // Inspect the symbol table for a list of `__pgrx_internals` we should have the generator call - let mut lib_so = target_dir_with_profile.clone(); - - lib_so.push(manifest.lib_filename()?); - - let lib_so_data = std::fs::read(&lib_so).wrap_err("couldn't read extension shared object")?; - let lib_so_obj_file = - parse_object(&lib_so_data).wrap_err("couldn't parse extension shared object")?; - let lib_so_exports = - lib_so_obj_file.exports().wrap_err("couldn't get exports from extension shared object")?; - - // Some users reported experiencing duplicate entries if we don't ensure `fns_to_call` - // has unique entries. - let mut fns_to_call = HashSet::new(); - for export in lib_so_exports { - let name = std::str::from_utf8(export.name())?.to_string(); - #[cfg(target_os = "macos")] - let name = { - // Mac will prefix symbols with `_` automatically, so we remove it to avoid getting - // two. - let mut name = name; - let rename = name.split_off(1); - assert_eq!(name, "_"); - rename - }; - - if name.starts_with("__pgrx_internals") { - fns_to_call.insert(name); - } - } - let mut seen_schemas = Vec::new(); - let mut num_funcs = 0_usize; - let mut num_triggers = 0_usize; - let mut num_types = 0_usize; - let mut num_enums = 0_usize; - let mut num_sqls = 0_usize; - let mut num_ords = 0_usize; - let mut num_hashes = 0_usize; - let mut num_aggregates = 0_usize; - for func in &fns_to_call { - if func.starts_with("__pgrx_internals_schema_") { - let schema = - func.split('_').nth(5).expect("Schema extern name was not of expected format"); - seen_schemas.push(schema); - } else if func.starts_with("__pgrx_internals_fn_") { - num_funcs += 1; - } else if func.starts_with("__pgrx_internals_trigger_") { - num_triggers += 1; - } else if func.starts_with("__pgrx_internals_type_") { - num_types += 1; - } else if func.starts_with("__pgrx_internals_enum_") { - num_enums += 1; - } else if func.starts_with("__pgrx_internals_sql_") { - num_sqls += 1; - } else if func.starts_with("__pgrx_internals_ord_") { - num_ords += 1; - } else if func.starts_with("__pgrx_internals_hash_") { - num_hashes += 1; - } else if func.starts_with("__pgrx_internals_aggregate_") { - num_aggregates += 1; - } - } - + let features_arg = features.features.join(" "); eprintln!( - "{} {} SQL entities: {} schemas ({} unique), {} functions, {} types, {} enums, {} sqls, {} ords, {} hashes, {} aggregates, {} triggers", - " Discovered".bold().green(), - fns_to_call.len().to_string().bold().cyan(), - seen_schemas.len().to_string().bold().cyan(), - seen_schemas.iter().collect::>().len().to_string().bold().cyan(), - num_funcs.to_string().bold().cyan(), - num_types.to_string().bold().cyan(), - num_enums.to_string().bold().cyan(), - num_sqls.to_string().bold().cyan(), - num_ords.to_string().bold().cyan(), - num_hashes.to_string().bold().cyan(), - num_aggregates.to_string().bold().cyan(), - num_triggers.to_string().bold().cyan(), + "{} for SQL generation with features `{}`", + " Building".bold().green(), + features_arg, ); - tracing::debug!("Collecting {} SQL entities", fns_to_call.len()); - let mut entities = Vec::default(); - - #[rustfmt::skip] // explicit extern "Rust" is more clear here - unsafe { - // SAFETY: Calls foreign functions with the correct type signatures. - // Assumes that repr(Rust) enums are represented the same in this crate as in the external - // binary, which is the case in practice when the same compiler is used to compile the - // external crate. - - POSTMASTER_LIBRARY - .get_or_try_init(|| { - libloading::os::unix::Library::open( - Some(&postmaster_stub_built), - libloading::os::unix::RTLD_NOW | libloading::os::unix::RTLD_GLOBAL, - ) - }) - .wrap_err_with(|| format!("Couldn't libload {}", postmaster_stub_built.display()))?; - - let lib = EXTENSION_LIBRARY - .get_or_try_init(|| { - libloading::os::unix::Library::open(Some(&lib_so), libloading::os::unix::RTLD_LAZY) - }) - .wrap_err_with(|| format!("Couldn't libload {}", lib_so.display()))?; - - let symbol: libloading::os::unix::Symbol< - unsafe extern "Rust" fn(_: ()) -> pgrx_sql_entity_graph::ControlFile, - > = lib - .get("__pgrx_marker".as_bytes()) - .expect("Couldn't call __pgrx_marker"); - let control_file_entity = pgrx_sql_entity_graph::SqlGraphEntity::ExtensionRoot( - symbol(()), - ); - entities.push(control_file_entity); - - for symbol_to_call in fns_to_call { - let symbol: libloading::os::unix::Symbol pgrx_sql_entity_graph::SqlGraphEntity> = - lib.get(symbol_to_call.as_bytes()).unwrap_or_else(|_| - panic!("Couldn't call {:#?}", symbol_to_call)); - let entity = symbol(); - entities.push(entity); - } + let symbols = compute_symbols( + user_manifest_path.as_ref(), + user_package, + profile, + is_test, + features, + log_level.clone(), + &features_arg, + )?; + + let codegen = compute_codegen(package_manifest_path, &symbols, &manifest)?; + + let embed = { + let mut embed = tempfile::NamedTempFile::new()?; + embed.write_all(codegen.as_bytes())?; + embed.flush()?; + embed }; - let pgrx_sql = pgrx_sql_entity_graph::PgrxSql::build( - entities.into_iter(), - manifest.lib_name()?, - versioned_so, - ) - .wrap_err("SQL generation error")?; + let sql = compute_sql( + user_manifest_path.as_ref(), + user_package, + profile, + is_test, + features, + log_level, + &features_arg, + embed.path(), + )?; if let Some(out_path) = path { let out_path = out_path.as_ref(); @@ -438,202 +193,287 @@ pub(crate) fn generate_schema( if let Some(parent) = out_path.parent() { std::fs::create_dir_all(parent).wrap_err("Could not create parent directory")? } - pgrx_sql - .to_file(out_path) + std::fs::write(out_path, sql.as_bytes()) .wrap_err_with(|| eyre!("Could not write SQL to {}", out_path.display()))?; output_tracking.push(out_path.to_path_buf()); } else { + use std::io::Write; eprintln!("{} SQL entities to {}", " Writing".bold().green(), "/dev/stdout".cyan(),); - pgrx_sql - .write(&mut std::io::stdout()) + std::io::stdout() + .write_all(sql.as_bytes()) .wrap_err_with(|| eyre!("Could not write SQL to stdout"))?; } - if let Some(dot_path) = dot { - let dot_path = dot_path.as_ref(); - tracing::info!(dot = %dot_path.display(), "Writing Graphviz DOT"); - pgrx_sql.to_dot(dot_path)?; + if let Some(_dot_path) = dot { + return Err(eyre!("Could not write SQL to dot.")); } Ok(()) } -#[tracing::instrument(level = "error", skip_all, fields( - postmaster_path = %format_display_path(postmaster_path.as_ref())?, - postmaster_stub_dir = %format_display_path(postmaster_stub_dir.as_ref())?, -))] -fn create_stub( - postmaster_path: impl AsRef, - postmaster_stub_dir: impl AsRef, -) -> eyre::Result { - let postmaster_path = postmaster_path.as_ref(); - let postmaster_stub_dir = postmaster_stub_dir.as_ref(); +fn compute_symbols( + user_manifest_path: Option<&impl AsRef>, + user_package: Option<&String>, + profile: &CargoProfile, + is_test: bool, + features: &clap_cargo::Features, + log_level: Option, + features_arg: &str, +) -> eyre::Result> { + use syn::visit::Visit; + use syn::ItemFn; + use CargoProfile::*; + + let mut command = crate::env::cargo(); + command.stderr(Stdio::inherit()); + command.stdout(Stdio::piped()); + command.arg("rustc"); + command.arg("--lib"); + + if let Some(user_package) = user_package { + command.arg("--package"); + command.arg(user_package); + } - let mut postmaster_stub_file = postmaster_stub_dir.to_path_buf(); - postmaster_stub_file.push("postmaster_stub.rs"); + if let Some(user_manifest_path) = user_manifest_path.as_ref() { + command.arg("--manifest-path"); + command.arg(user_manifest_path.as_ref()); + } - let mut postmaster_hash_file = postmaster_stub_dir.to_path_buf(); - postmaster_hash_file.push("postmaster.hash"); + if is_test { + command.arg("--profile"); + match profile { + Dev => { + command.arg("test"); + } + Release => { + command.arg("bench"); + } + Profile(p) => { + command.arg(p); + } + } + } else { + command.args(profile.cargo_args()); + } - let mut postmaster_stub_built = postmaster_stub_dir.to_path_buf(); - postmaster_stub_built.push("postmaster_stub.so"); + if let Some(log_level) = &log_level { + command.env("RUST_LOG", log_level); + } - let postmaster_bin_data = - std::fs::read(postmaster_path).wrap_err("couldn't read postmaster")?; + if !features_arg.trim().is_empty() { + command.arg("--features"); + command.arg(&features_arg); + } - let mut hasher = std::collections::hash_map::DefaultHasher::new(); - postmaster_bin_data.hash(&mut hasher); - let postmaster_bin_hash = hasher.finish().to_string().into_bytes(); + if features.no_default_features { + command.arg("--no-default-features"); + } - let postmaster_hash_data = std::fs::read(&postmaster_hash_file).ok(); + if features.all_features { + command.arg("--all-features"); + } - // Determine if we already built this stub. - if let Some(postmaster_hash_data) = postmaster_hash_data { - if postmaster_hash_data == postmaster_bin_hash && postmaster_stub_built.exists() { - // We already built this and it's up to date. - tracing::debug!(stub = %postmaster_stub_built.display(), "Existing stub for postmaster"); - return Ok(postmaster_stub_built); - } + let flags = std::env::var("PGRX_BUILD_FLAGS").unwrap_or_default(); + for arg in flags.split_ascii_whitespace() { + command.arg(arg); } - let postmaster_obj_file = - parse_object(&postmaster_bin_data).wrap_err("couldn't parse postmaster")?; - let postmaster_exports = postmaster_obj_file - .exports() - .wrap_err("couldn't get exports from extension shared object")?; - - let mut symbols_to_stub = HashSet::new(); - for export in postmaster_exports { - let name = std::str::from_utf8(export.name())?.to_string(); - #[cfg(target_os = "macos")] - let name = { - // Mac will prefix symbols with `_` automatically, so we remove it to avoid getting - // two. - let mut name = name; - let rename = name.split_off(1); - assert_eq!(name, "_"); - rename - }; - symbols_to_stub.insert(name); + command.arg("--"); + command.arg("-Zunpretty=expanded"); + + // We use a wrapper to ensure that RUSTC_BOOTSTRAP is only enabled for the final crate. + // If we remove it, stable toolchain users will feel slow since dependencies need to be recompiled. + if needs_rustc_bootstrap() { + command.env("RUSTC_WORKSPACE_WRAPPER", std::env::current_exe()?); + command.env("CARGO_PGRX_BOOTSTRAP", "1"); } - tracing::debug!("Creating stub of appropriate PostgreSQL symbols"); - PgrxPgSysStub::from_symbols(&symbols_to_stub)?.write_to_file(&postmaster_stub_file)?; + let command_str = format!("{:?}", command); - let mut so_rustc_invocation = crate::env::rustc(); - so_rustc_invocation.stderr(Stdio::inherit()); + tracing::debug!(command = %command_str, "Running"); + let cargo_output = + command.output().wrap_err_with(|| format!("failed to spawn cargo: {}", command_str))?; + tracing::trace!(status_code = %cargo_output.status, command = %command_str, "Finished"); - if let Ok(rustc_flags_str) = std::env::var("RUSTFLAGS") { - let rustc_flags = rustc_flags_str.split_whitespace().collect::>(); - if !rustc_flags.is_empty() { - so_rustc_invocation.args(rustc_flags); - } + if !cargo_output.status.success() { + // We explicitly do not want to return a spantraced error here. + std::process::exit(1) } - so_rustc_invocation.args([ - "--crate-type", - "cdylib", - "-o", - postmaster_stub_built - .to_str() - .ok_or(eyre!("could not call postmaster_stub_built.to_str()"))?, - postmaster_stub_file - .to_str() - .ok_or(eyre!("could not call postmaster_stub_file.to_str()"))?, - ]); - - let so_rustc_invocation_str = format!("{:?}", so_rustc_invocation); - tracing::debug!(command = %so_rustc_invocation_str, "Running"); - let output = so_rustc_invocation.output().wrap_err_with(|| { - eyre!("could not invoke `rustc` on {}", &postmaster_stub_file.display()) + let expanded = String::from_utf8(cargo_output.stdout).unwrap(); + + let file = syn::parse_str::(&expanded).wrap_err_with(|| { + format!( + "Cannot parse expanded code. You should reinstall cargo-pgrx using an upgraded rustc." + ) })?; - let code = output.status.code().ok_or(eyre!("could not get status code of build"))?; - tracing::trace!(status_code = %code, command = %so_rustc_invocation_str, "Finished"); - if code != 0 { - return Err(eyre!("rustc exited with code {}", code)); + #[derive(Default)] + struct Visitor { + // fn() -> pgrx::pgrx_sql_entity_graph::SqlGraphEntity + internals: Vec, } - std::fs::write(&postmaster_hash_file, postmaster_bin_hash) - .wrap_err("could not write postmaster stub hash")?; + impl Visit<'_> for Visitor { + fn visit_item_fn(&mut self, i: &ItemFn) { + syn::visit::visit_item_fn(self, i); + let name = i.sig.ident.to_string(); + if name.starts_with("__pgrx_internals") { + self.internals.push(name); + } + } + } - Ok(postmaster_stub_built) + let mut visitor = Visitor::default(); + visitor.visit_file(&file); + Ok(visitor.internals) } -fn parse_object(data: &[u8]) -> object::Result { - let kind = object::FileKind::parse(data)?; - - match kind { - FileKind::MachOFat32 => { - let arch = env::consts::ARCH; +fn compute_codegen( + package_manifest_path: impl AsRef, + symbols: &[String], + manifest: &Manifest, +) -> eyre::Result { + use proc_macro2::{Ident, Span, TokenStream}; - match slice_arch32(data, arch) { - Some(slice) => parse_object(slice), - None => { - panic!("Failed to slice architecture '{arch}' from universal binary.") + let mut codegen = quote::quote! { + // This file is automatically @generated by cargo-pgrx. + }; + let extends = { + let mut out = TokenStream::new(); + for name in symbols.iter() { + let name_ident = Ident::new(name, Span::call_site()); + out.extend(quote::quote! { + extern "Rust" { + fn #name_ident() -> pgrx::pgrx_sql_entity_graph::SqlGraphEntity; } + let entity = unsafe { #name_ident() }; + entities.push(entity); + }); + } + out + }; + let lib_name = manifest.lib_name()?; + let lib_name_ident = Ident::new(&lib_name, Span::call_site()); + let versioned_so = get_property(&package_manifest_path, "module_pathname")?.is_none(); + codegen.extend(quote::quote! { + fn main() { + let mut entities = Vec::new(); + let control_file_entity = pgrx::pgrx_sql_entity_graph::SqlGraphEntity::ExtensionRoot(#lib_name_ident::__pgrx_marker()); + entities.push(control_file_entity); + #extends + let pgrx_sql = pgrx::pgrx_sql_entity_graph::PgrxSql::build( + entities.into_iter(), + #lib_name.to_string(), + #versioned_so, + ) + .expect("SQL generation error"); + pgrx_sql + .write(&mut std::io::stdout()) + .expect("SQL IO error"); + } + }); + Ok(codegen.to_string()) +} + +fn compute_sql( + user_manifest_path: Option<&impl AsRef>, + user_package: Option<&String>, + profile: &CargoProfile, + is_test: bool, + features: &clap_cargo::Features, + log_level: Option, + features_arg: &str, + embed_path: impl AsRef, +) -> eyre::Result { + use CargoProfile::*; + + let mut command = crate::env::cargo(); + command.stderr(Stdio::inherit()); + command.stdout(Stdio::piped()); + command.arg("run"); + command.arg("--bin"); + command.arg("pgrx"); + + if let Some(user_package) = user_package { + command.arg("--package"); + command.arg(user_package); + } + + if let Some(user_manifest_path) = user_manifest_path.as_ref() { + command.arg("--manifest-path"); + command.arg(user_manifest_path.as_ref()); + } + + if is_test { + command.arg("--profile"); + match profile { + Dev => { + command.arg("test"); + } + Release => { + command.arg("bench"); + } + Profile(p) => { + command.arg(p); } } - _ => object::File::parse(data), + } else { + command.args(profile.cargo_args()); } -} -fn slice_arch32<'a>(data: &'a [u8], arch: &str) -> Option<&'a [u8]> { - let target = match arch { - "x86" => Architecture::I386, - "x86_64" => Architecture::X86_64, - "arm" => Architecture::Arm, - "aarch64" => Architecture::Aarch64, - "mips" => Architecture::Mips, - "powerpc" => Architecture::PowerPc, - "powerpc64" => Architecture::PowerPc64, - _ => Architecture::Unknown, - }; + if let Some(log_level) = &log_level { + command.env("RUST_LOG", log_level); + } - let candidates = FatHeader::parse_arch32(data).ok()?; - let architecture = candidates.iter().find(|a| a.architecture() == target)?; + if !features_arg.trim().is_empty() { + command.arg("--features"); + command.arg(&features_arg); + } - architecture.data(data).ok() -} + if features.no_default_features { + command.arg("--no-default-features"); + } + + if features.all_features { + command.arg("--all-features"); + } -#[cfg(test)] -mod tests { - use crate::command::schema::*; - use pgrx_pg_config::PgConfigSelector; - - #[test] - fn test_parse_managed_postmasters() { - let pgrx = Pgrx::from_config().unwrap(); - let mut results = pgrx - .iter(PgConfigSelector::All) - .map(|pg_config| { - let fixture_path = pg_config.unwrap().postmaster_path().unwrap(); - let bin = std::fs::read(fixture_path).unwrap(); - - parse_object(&bin).is_ok() - }) - .peekable(); - - assert!(results.peek().is_some()); - assert!(results.all(|r| r)); + let flags = std::env::var("PGRX_BUILD_FLAGS").unwrap_or_default(); + for arg in flags.split_ascii_whitespace() { + command.arg(arg); } - #[test] - fn test_parse_universal_binary_slice() { - let root_path = env!("CARGO_MANIFEST_DIR"); - let fixture_path = format!("{root_path}/tests/fixtures/macos-universal-binary"); - let bin = std::fs::read(fixture_path).unwrap(); + command.env("PGRX_EMBED", embed_path.as_ref()); + + let command_str = format!("{:?}", command); + + tracing::debug!(command = %command_str, "Running"); + let cargo_output = + command.output().wrap_err_with(|| format!("failed to spawn cargo: {}", command_str))?; + tracing::trace!(status_code = %cargo_output.status, command = %command_str, "Finished"); - let slice = slice_arch32(&bin, "aarch64") - .expect("Failed to slice architecture 'aarch64' from universal binary."); - assert!(parse_object(slice).is_ok()); + if !cargo_output.status.success() { + // We explicitly do not want to return a spantraced error here. + std::process::exit(1) } - #[test] - fn test_slice_unknown_architecture() { - let root_path = env!("CARGO_MANIFEST_DIR"); - let fixture_path = format!("{root_path}/tests/fixtures/macos-universal-binary"); - let bin = std::fs::read(fixture_path).unwrap(); + Ok(String::from_utf8(cargo_output.stdout).unwrap()) +} - assert!(slice_arch32(&bin, "foo").is_none()); +fn needs_rustc_bootstrap() -> bool { + if std::env::var_os("RUSTC_BOOTSTRAP").is_some_and(|var| !var.is_empty()) { + return false; } + + let mut cmd = crate::env::rustc(); + cmd.arg("-Zunpretty=expanded"); + cmd.arg("-"); + cmd.stdin(Stdio::null()); + cmd.stdout(Stdio::null()); + cmd.stderr(Stdio::null()); + let Ok(status) = cmd.status() else { + return true; + }; + !status.success() } diff --git a/cargo-pgrx/src/main.rs b/cargo-pgrx/src/main.rs index 56b16b97f3..7c088233b8 100644 --- a/cargo-pgrx/src/main.rs +++ b/cargo-pgrx/src/main.rs @@ -13,7 +13,6 @@ mod command; mod manifest; mod metadata; -mod pgrx_pg_sys_stub; pub(crate) mod env; pub(crate) mod profile; @@ -61,6 +60,31 @@ impl CommandExecute for CargoSubcommands { } fn main() -> color_eyre::Result<()> { + if std::env::var("CARGO_PGRX_BOOTSTRAP").is_ok() { + use std::process::Stdio; + let args = std::env::args_os().collect::>(); + let needs_rustc_bootstrap = { + let mut needs_rustc_bootstrap = false; + for s in args.iter() { + if s == "-Zunpretty=expanded" { + needs_rustc_bootstrap = true; + } + } + needs_rustc_bootstrap + }; + let mut command = std::process::Command::new(&args[1]); + command.args(&args[2..]); + if needs_rustc_bootstrap { + command.env("RUSTC_BOOTSTRAP", "1"); + } + command.stdin(Stdio::inherit()); + command.stdout(Stdio::inherit()); + command.stderr(Stdio::inherit()); + if !command.spawn()?.wait()?.success() { + eyre::bail!("RUSTC exits unsuccessfully."); + } + return Ok(()); + } env::initialize(); color_eyre::config::HookBuilder::default() .theme(if !atty::is(Stream::Stderr) { diff --git a/cargo-pgrx/src/pgrx_pg_sys_stub.rs b/cargo-pgrx/src/pgrx_pg_sys_stub.rs deleted file mode 100644 index e841c5ae61..0000000000 --- a/cargo-pgrx/src/pgrx_pg_sys_stub.rs +++ /dev/null @@ -1,68 +0,0 @@ -//LICENSE Portions Copyright 2019-2021 ZomboDB, LLC. -//LICENSE -//LICENSE Portions Copyright 2021-2023 Technology Concepts & Design, Inc. -//LICENSE -//LICENSE Portions Copyright 2023-2023 PgCentral Foundation, Inc. -//LICENSE -//LICENSE All rights reserved. -//LICENSE -//LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file. -use std::collections::HashSet; -use std::fs::File; -use std::io::Write; -use std::path::Path; -use syn::{parse_quote, Ident, Item}; - -/// A utility structure which can generate 'stubs' of the bindings generated by `pgrx-pg-sys`'s build script. -/// -/// These stubs can be built. -/// -/// For example, this is used by `cargo-pgrx` and then `dlopen`'d before the extension for SQL generation. -pub struct PgrxPgSysStub { - stub_file: syn::File, -} - -const SYMBOL_SKIP_LIST: [&str; 2] = ["_fini", "_init"]; - -impl PgrxPgSysStub { - #[tracing::instrument(level = "error", skip_all, fields(symbols = %symbols.len()))] - pub fn from_symbols(symbols: &HashSet) -> eyre::Result { - let mut items = Vec::with_capacity(symbols.len()); - for symbol in symbols.iter().filter(|v| !SYMBOL_SKIP_LIST.contains(&v.as_ref())) { - match stub_for_symbol(symbol) { - Ok(stub) => items.push(stub), - Err(_e) => tracing::trace!(%symbol, "Skipping, not a valid Rust ident"), - } - } - - let stub_file = syn::File { shebang: None, attrs: Default::default(), items }; - - Ok(Self { stub_file }) - } - - #[tracing::instrument(level = "error", skip_all, fields(pgrx_pg_sys_stub = %pgrx_pg_sys_stub.as_ref().display()))] - pub fn write_to_file(&self, pgrx_pg_sys_stub: impl AsRef) -> eyre::Result<()> { - let pgrx_pg_sys_stub = pgrx_pg_sys_stub.as_ref(); - if let Some(parent) = pgrx_pg_sys_stub.parent() { - std::fs::create_dir_all(parent)?; - } - let mut output_file = File::create(pgrx_pg_sys_stub)?; - let content = prettyplease::unparse(&self.stub_file); - output_file.write_all(content.as_bytes())?; - Ok(()) - } -} - -#[tracing::instrument] -fn stub_for_symbol(name: &str) -> eyre::Result { - let ident = syn::parse_str::(name)?; - let item_fn: syn::ItemFn = parse_quote! { - #[allow(dead_code)] - #[allow(non_snake_case)] - #[no_mangle] - extern "C" fn #ident() { - unimplemented!(concat!(stringify!(#name), " is stubbed and cannot be used right now.")); - } - }; - Ok(Item::Fn(item_fn)) -} diff --git a/cargo-pgrx/src/templates/cargo_config_toml b/cargo-pgrx/src/templates/cargo_config_toml index 13c456b5dd..fe681c554e 100644 --- a/cargo-pgrx/src/templates/cargo_config_toml +++ b/cargo-pgrx/src/templates/cargo_config_toml @@ -1,3 +1,6 @@ [target.'cfg(target_os="macos")'] # Postgres symbols won't be available until runtime rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"] + +[env] +PGRX_EMBED = "../../embed.rs" diff --git a/cargo-pgrx/src/templates/cargo_toml b/cargo-pgrx/src/templates/cargo_toml index 5a83615f80..994357846b 100644 --- a/cargo-pgrx/src/templates/cargo_toml +++ b/cargo-pgrx/src/templates/cargo_toml @@ -4,7 +4,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/cargo-pgrx/src/templates/embed_rs b/cargo-pgrx/src/templates/embed_rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/cargo-pgrx/src/templates/embed_rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/cargo-pgrx/src/templates/pgrx_rs b/cargo-pgrx/src/templates/pgrx_rs new file mode 100644 index 0000000000..98d37f6ff6 --- /dev/null +++ b/cargo-pgrx/src/templates/pgrx_rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); \ No newline at end of file diff --git a/pgrx-examples/aggregate/Cargo.toml b/pgrx-examples/aggregate/Cargo.toml index 4262dd6257..4e6bcbd63e 100644 --- a/pgrx-examples/aggregate/Cargo.toml +++ b/pgrx-examples/aggregate/Cargo.toml @@ -14,7 +14,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/aggregate/embed.rs b/pgrx-examples/aggregate/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/aggregate/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/aggregate/src/bin/pgrx.rs b/pgrx-examples/aggregate/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/aggregate/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/arrays/Cargo.toml b/pgrx-examples/arrays/Cargo.toml index 0f96c09e97..8ee1e38720 100644 --- a/pgrx-examples/arrays/Cargo.toml +++ b/pgrx-examples/arrays/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/arrays/embed.rs b/pgrx-examples/arrays/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/arrays/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/arrays/src/bin/pgrx.rs b/pgrx-examples/arrays/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/arrays/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/bad_ideas/Cargo.toml b/pgrx-examples/bad_ideas/Cargo.toml index f126f8f48a..3b064f9e3d 100644 --- a/pgrx-examples/bad_ideas/Cargo.toml +++ b/pgrx-examples/bad_ideas/Cargo.toml @@ -14,7 +14,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/bad_ideas/embed.rs b/pgrx-examples/bad_ideas/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/bad_ideas/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/bad_ideas/src/bin/pgrx.rs b/pgrx-examples/bad_ideas/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/bad_ideas/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/bgworker/Cargo.toml b/pgrx-examples/bgworker/Cargo.toml index eccb770e29..2422f3ef88 100644 --- a/pgrx-examples/bgworker/Cargo.toml +++ b/pgrx-examples/bgworker/Cargo.toml @@ -14,7 +14,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/bgworker/embed.rs b/pgrx-examples/bgworker/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/bgworker/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/bgworker/src/bin/pgrx.rs b/pgrx-examples/bgworker/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/bgworker/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/bytea/Cargo.toml b/pgrx-examples/bytea/Cargo.toml index 8f1178e6d1..0fb53ead67 100644 --- a/pgrx-examples/bytea/Cargo.toml +++ b/pgrx-examples/bytea/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/bytea/embed.rs b/pgrx-examples/bytea/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/bytea/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/bytea/src/bin/pgrx.rs b/pgrx-examples/bytea/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/bytea/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/composite_type/Cargo.toml b/pgrx-examples/composite_type/Cargo.toml index f672fee846..df699ec151 100644 --- a/pgrx-examples/composite_type/Cargo.toml +++ b/pgrx-examples/composite_type/Cargo.toml @@ -14,7 +14,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/composite_type/embed.rs b/pgrx-examples/composite_type/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/composite_type/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/composite_type/src/bin/pgrx.rs b/pgrx-examples/composite_type/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/composite_type/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/custom_libname/Cargo.toml b/pgrx-examples/custom_libname/Cargo.toml index 8de2484940..f1cd3982a0 100644 --- a/pgrx-examples/custom_libname/Cargo.toml +++ b/pgrx-examples/custom_libname/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] name = "other_name" [features] diff --git a/pgrx-examples/custom_libname/embed.rs b/pgrx-examples/custom_libname/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/custom_libname/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/custom_libname/src/bin/pgrx.rs b/pgrx-examples/custom_libname/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/custom_libname/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/custom_sql/Cargo.toml b/pgrx-examples/custom_sql/Cargo.toml index b95402ce5b..ac7d0be1bf 100644 --- a/pgrx-examples/custom_sql/Cargo.toml +++ b/pgrx-examples/custom_sql/Cargo.toml @@ -14,7 +14,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/custom_sql/embed.rs b/pgrx-examples/custom_sql/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/custom_sql/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/custom_sql/src/bin/pgrx.rs b/pgrx-examples/custom_sql/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/custom_sql/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/custom_types/Cargo.toml b/pgrx-examples/custom_types/Cargo.toml index 01b9b808b5..cee54badba 100644 --- a/pgrx-examples/custom_types/Cargo.toml +++ b/pgrx-examples/custom_types/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/custom_types/embed.rs b/pgrx-examples/custom_types/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/custom_types/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/custom_types/src/bin/pgrx.rs b/pgrx-examples/custom_types/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/custom_types/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/datetime/Cargo.toml b/pgrx-examples/datetime/Cargo.toml index b97426187f..c302bdd100 100644 --- a/pgrx-examples/datetime/Cargo.toml +++ b/pgrx-examples/datetime/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/datetime/embed.rs b/pgrx-examples/datetime/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/datetime/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/datetime/src/bin/pgrx.rs b/pgrx-examples/datetime/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/datetime/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/errors/Cargo.toml b/pgrx-examples/errors/Cargo.toml index 0ee9707a9a..ccf5c3711d 100644 --- a/pgrx-examples/errors/Cargo.toml +++ b/pgrx-examples/errors/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/errors/embed.rs b/pgrx-examples/errors/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/errors/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/errors/src/bin/pgrx.rs b/pgrx-examples/errors/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/errors/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/nostd/Cargo.toml b/pgrx-examples/nostd/Cargo.toml index 317121c2af..eaa72dd0b8 100644 --- a/pgrx-examples/nostd/Cargo.toml +++ b/pgrx-examples/nostd/Cargo.toml @@ -14,7 +14,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/nostd/embed.rs b/pgrx-examples/nostd/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/nostd/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/nostd/src/bin/pgrx.rs b/pgrx-examples/nostd/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/nostd/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/numeric/Cargo.toml b/pgrx-examples/numeric/Cargo.toml index f90dad9c4e..3dea937036 100644 --- a/pgrx-examples/numeric/Cargo.toml +++ b/pgrx-examples/numeric/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" rust-version = "1.58" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/numeric/embed.rs b/pgrx-examples/numeric/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/numeric/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/numeric/src/bin/pgrx.rs b/pgrx-examples/numeric/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/numeric/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/operators/Cargo.toml b/pgrx-examples/operators/Cargo.toml index c2a2204f0a..579fdbe33a 100644 --- a/pgrx-examples/operators/Cargo.toml +++ b/pgrx-examples/operators/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/operators/embed.rs b/pgrx-examples/operators/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/operators/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/operators/src/bin/pgrx.rs b/pgrx-examples/operators/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/operators/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/pgtrybuilder/Cargo.toml b/pgrx-examples/pgtrybuilder/Cargo.toml index 8c8df3a80f..4353700366 100644 --- a/pgrx-examples/pgtrybuilder/Cargo.toml +++ b/pgrx-examples/pgtrybuilder/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/pgtrybuilder/embed.rs b/pgrx-examples/pgtrybuilder/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/pgtrybuilder/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/pgtrybuilder/src/bin/pgrx.rs b/pgrx-examples/pgtrybuilder/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/pgtrybuilder/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/range/Cargo.toml b/pgrx-examples/range/Cargo.toml index b0ca88b12f..8ce59cde01 100644 --- a/pgrx-examples/range/Cargo.toml +++ b/pgrx-examples/range/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/range/embed.rs b/pgrx-examples/range/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/range/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/range/src/bin/pgrx.rs b/pgrx-examples/range/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/range/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/schemas/Cargo.toml b/pgrx-examples/schemas/Cargo.toml index 38885390dc..8a22da8985 100644 --- a/pgrx-examples/schemas/Cargo.toml +++ b/pgrx-examples/schemas/Cargo.toml @@ -14,7 +14,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/schemas/embed.rs b/pgrx-examples/schemas/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/schemas/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/schemas/src/bin/pgrx.rs b/pgrx-examples/schemas/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/schemas/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/shmem/Cargo.toml b/pgrx-examples/shmem/Cargo.toml index 86ed554c62..60936dbfc0 100644 --- a/pgrx-examples/shmem/Cargo.toml +++ b/pgrx-examples/shmem/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/shmem/embed.rs b/pgrx-examples/shmem/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/shmem/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/shmem/src/bin/pgrx.rs b/pgrx-examples/shmem/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/shmem/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/spi/Cargo.toml b/pgrx-examples/spi/Cargo.toml index 204a18078f..4fa14d1edc 100644 --- a/pgrx-examples/spi/Cargo.toml +++ b/pgrx-examples/spi/Cargo.toml @@ -14,7 +14,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/spi/embed.rs b/pgrx-examples/spi/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/spi/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/spi/src/bin/pgrx.rs b/pgrx-examples/spi/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/spi/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/spi_srf/Cargo.toml b/pgrx-examples/spi_srf/Cargo.toml index 47a1da39ae..517c22dcad 100644 --- a/pgrx-examples/spi_srf/Cargo.toml +++ b/pgrx-examples/spi_srf/Cargo.toml @@ -15,7 +15,7 @@ edition = "2021" rust-version = "1.58" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/spi_srf/embed.rs b/pgrx-examples/spi_srf/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/spi_srf/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/spi_srf/src/bin/pgrx.rs b/pgrx-examples/spi_srf/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/spi_srf/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/srf/Cargo.toml b/pgrx-examples/srf/Cargo.toml index 40c3bce35e..d95e841852 100644 --- a/pgrx-examples/srf/Cargo.toml +++ b/pgrx-examples/srf/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/srf/embed.rs b/pgrx-examples/srf/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/srf/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/srf/src/bin/pgrx.rs b/pgrx-examples/srf/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/srf/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/strings/Cargo.toml b/pgrx-examples/strings/Cargo.toml index 473a6d56a2..c6072eb2f0 100644 --- a/pgrx-examples/strings/Cargo.toml +++ b/pgrx-examples/strings/Cargo.toml @@ -14,7 +14,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/strings/embed.rs b/pgrx-examples/strings/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/strings/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/strings/src/bin/pgrx.rs b/pgrx-examples/strings/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/strings/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/triggers/Cargo.toml b/pgrx-examples/triggers/Cargo.toml index c5fe05bcfb..c01cc13411 100644 --- a/pgrx-examples/triggers/Cargo.toml +++ b/pgrx-examples/triggers/Cargo.toml @@ -14,7 +14,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/triggers/embed.rs b/pgrx-examples/triggers/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/triggers/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/triggers/src/bin/pgrx.rs b/pgrx-examples/triggers/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/triggers/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/versioned_custom_libname_so/Cargo.toml b/pgrx-examples/versioned_custom_libname_so/Cargo.toml index 57ca246867..5d0c84d074 100644 --- a/pgrx-examples/versioned_custom_libname_so/Cargo.toml +++ b/pgrx-examples/versioned_custom_libname_so/Cargo.toml @@ -14,7 +14,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] name = "versioned_othername" [features] diff --git a/pgrx-examples/versioned_custom_libname_so/embed.rs b/pgrx-examples/versioned_custom_libname_so/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/versioned_custom_libname_so/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/versioned_custom_libname_so/src/bin/pgrx.rs b/pgrx-examples/versioned_custom_libname_so/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/versioned_custom_libname_so/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/versioned_so/Cargo.toml b/pgrx-examples/versioned_so/Cargo.toml index 36c2bff26a..228e9c1284 100644 --- a/pgrx-examples/versioned_so/Cargo.toml +++ b/pgrx-examples/versioned_so/Cargo.toml @@ -14,7 +14,7 @@ version = "0.0.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [features] default = ["pg13"] diff --git a/pgrx-examples/versioned_so/embed.rs b/pgrx-examples/versioned_so/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-examples/versioned_so/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-examples/versioned_so/src/bin/pgrx.rs b/pgrx-examples/versioned_so/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-examples/versioned_so/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx-sql-entity-graph/src/extension_sql/mod.rs b/pgrx-sql-entity-graph/src/extension_sql/mod.rs index 372a08e1e6..8f244fc76f 100644 --- a/pgrx-sql-entity-graph/src/extension_sql/mod.rs +++ b/pgrx-sql-entity-graph/src/extension_sql/mod.rs @@ -96,11 +96,12 @@ impl ToEntityGraphTokens for ExtensionSqlFile { let creates_iter = creates.iter(); let sql_graph_entity_fn_name = syn::Ident::new(&format!("__pgrx_internals_sql_{}", name.clone()), Span::call_site()); + quote! { #[no_mangle] #[doc(hidden)] #[allow(unknown_lints, clippy::no_mangle_with_rust_abi)] - pub extern "Rust" fn #sql_graph_entity_fn_name() -> ::pgrx::pgrx_sql_entity_graph::SqlGraphEntity { + pub extern "Rust" fn #sql_graph_entity_fn_name() -> ::pgrx::pgrx_sql_entity_graph::SqlGraphEntity { extern crate alloc; use alloc::vec::Vec; use alloc::vec; @@ -196,6 +197,7 @@ impl ToEntityGraphTokens for ExtensionSql { syn::Ident::new(&format!("__pgrx_internals_sql_{}", name.value()), Span::call_site()); quote! { #[no_mangle] + #[doc(hidden)] #[allow(unknown_lints, clippy::no_mangle_with_rust_abi)] pub extern "Rust" fn #sql_graph_entity_fn_name() -> ::pgrx::pgrx_sql_entity_graph::SqlGraphEntity { extern crate alloc; diff --git a/pgrx-sql-entity-graph/src/lib.rs b/pgrx-sql-entity-graph/src/lib.rs index a1b7b76792..fbf873d328 100644 --- a/pgrx-sql-entity-graph/src/lib.rs +++ b/pgrx-sql-entity-graph/src/lib.rs @@ -49,7 +49,6 @@ pub use schema::Schema; pub use to_sql::entity::ToSqlConfigEntity; pub use to_sql::{ToSql, ToSqlConfig}; pub use used_type::{UsedType, UsedTypeEntity}; - pub(crate) mod aggregate; pub(crate) mod composite_type; pub(crate) mod control_file; diff --git a/pgrx-sql-entity-graph/src/metadata/function_metadata.rs b/pgrx-sql-entity-graph/src/metadata/function_metadata.rs index 9d57ab5089..6ced26e989 100644 --- a/pgrx-sql-entity-graph/src/metadata/function_metadata.rs +++ b/pgrx-sql-entity-graph/src/metadata/function_metadata.rs @@ -16,8 +16,7 @@ to the `pgrx` framework and very subject to change between versions. While you m */ -use super::{FunctionMetadataEntity, PhantomDataExt, SqlTranslatable}; -use core::marker::PhantomData; +use super::{FunctionMetadataEntity, SqlTranslatable}; /** Provide SQL generation related information on functions @@ -27,8 +26,7 @@ use pgrx_sql_entity_graph::metadata::{FunctionMetadata, Returns, SqlMapping}; fn floof(i: i32) -> String { todo!() } type FunctionPointer = fn(i32) -> String; -let marker: FunctionPointer = floof; -let metadata = pgrx_sql_entity_graph::metadata::FunctionMetadata::entity(&marker); +let metadata = FunctionPointer::entity(); assert_eq!( metadata.retval.return_sql, Ok(Returns::One(SqlMapping::As("TEXT".to_string()))), @@ -36,24 +34,21 @@ assert_eq!( ``` */ pub trait FunctionMetadata { - fn path(&self) -> &'static str { + fn path() -> &'static str { core::any::type_name::() } - fn entity(&self) -> FunctionMetadataEntity; + fn entity() -> FunctionMetadataEntity; } impl FunctionMetadata<()> for fn() -> R where R: SqlTranslatable, { - fn entity(&self) -> FunctionMetadataEntity { + fn entity() -> FunctionMetadataEntity { FunctionMetadataEntity { arguments: vec![], - retval: { - let marker: PhantomData = PhantomData; - marker.entity() - }, - path: self.path(), + retval: R::entity(), + path: core::any::type_name::(), } } } @@ -62,14 +57,11 @@ impl FunctionMetadata<()> for unsafe fn() -> R where R: SqlTranslatable, { - fn entity(&self) -> FunctionMetadataEntity { + fn entity() -> FunctionMetadataEntity { FunctionMetadataEntity { arguments: vec![], - retval: { - let marker: PhantomData = PhantomData; - marker.entity() - }, - path: self.path(), + retval: R::entity(), + path: core::any::type_name::(), } } } @@ -77,20 +69,20 @@ where macro_rules! impl_fn { ($($T:ident),* $(,)?) => { impl<$($T: SqlTranslatable,)* R: SqlTranslatable> FunctionMetadata<($($T,)*)> for fn($($T,)*) -> R { - fn entity(&self) -> FunctionMetadataEntity { + fn entity() -> FunctionMetadataEntity { FunctionMetadataEntity { - arguments: vec![$(PhantomData::<$T>.entity()),+], - retval: PhantomData::.entity(), - path: self.path(), + arguments: vec![$(<$T>::entity()),+], + retval: R::entity(), + path: core::any::type_name::(), } } } impl<$($T: SqlTranslatable,)* R: SqlTranslatable> FunctionMetadata<($($T,)*)> for unsafe fn($($T,)*) -> R { - fn entity(&self) -> FunctionMetadataEntity { + fn entity() -> FunctionMetadataEntity { FunctionMetadataEntity { - arguments: vec![$(PhantomData::<$T>.entity()),+], - retval: PhantomData::.entity(), - path: self.path(), + arguments: vec![$(<$T>::entity()),+], + retval: R::entity(), + path: core::any::type_name::(), } } } diff --git a/pgrx-sql-entity-graph/src/pg_extern/mod.rs b/pgrx-sql-entity-graph/src/pg_extern/mod.rs index f0bc022759..0fd08970e7 100644 --- a/pgrx-sql-entity-graph/src/pg_extern/mod.rs +++ b/pgrx-sql-entity-graph/src/pg_extern/mod.rs @@ -298,13 +298,12 @@ impl PgExtern { #[allow(unused_imports)] use alloc::{vec, vec::Vec}; type FunctionPointer = #unsafety fn(#( #input_types ),*) #return_type; - let metadata: FunctionPointer = #ident; let submission = ::pgrx::pgrx_sql_entity_graph::PgExternEntity { name: #name, unaliased_name: stringify!(#ident), module_path: core::module_path!(), full_path: concat!(core::module_path!(), "::", stringify!(#ident)), - metadata: ::pgrx::pgrx_sql_entity_graph::metadata::FunctionMetadata::entity(&metadata), + metadata: >::entity(), fn_args: vec![#(#inputs_iter),*], fn_return: #returns, #[allow(clippy::or_fun_call)] diff --git a/pgrx-sql-entity-graph/src/used_type.rs b/pgrx-sql-entity-graph/src/used_type.rs index 0da7e095b3..f571d69189 100644 --- a/pgrx-sql-entity-graph/src/used_type.rs +++ b/pgrx-sql-entity-graph/src/used_type.rs @@ -339,9 +339,8 @@ impl UsedType { /// Set via the type being an `Option`. optional: #optional, metadata: { - use ::pgrx::pgrx_sql_entity_graph::metadata::PhantomDataExt; - let marker: core::marker::PhantomData<#resolved_ty> = core::marker::PhantomData; - marker.entity() + use ::pgrx::pgrx_sql_entity_graph::metadata::SqlTranslatable; + <#resolved_ty>::entity() }, } } diff --git a/pgrx-tests/embed.rs b/pgrx-tests/embed.rs new file mode 100644 index 0000000000..f00fe5bc00 --- /dev/null +++ b/pgrx-tests/embed.rs @@ -0,0 +1,3 @@ +fn main() { + panic!("PGRX_EMBED is not override."); +} \ No newline at end of file diff --git a/pgrx-tests/src/bin/pgrx.rs b/pgrx-tests/src/bin/pgrx.rs new file mode 100644 index 0000000000..c982b59128 --- /dev/null +++ b/pgrx-tests/src/bin/pgrx.rs @@ -0,0 +1 @@ +include!(env!("PGRX_EMBED")); diff --git a/pgrx/Cargo.toml b/pgrx/Cargo.toml index 65be5d9215..637138cf2b 100644 --- a/pgrx/Cargo.toml +++ b/pgrx/Cargo.toml @@ -66,4 +66,3 @@ seahash = "4.1.0" # derive(PostgresHash) serde = { version = "1.0", features = [ "derive" ] } # impls on pub types serde_cbor = "0.11.2" # derive(PostgresType) serde_json = "1.0" # everything JSON - diff --git a/pgrx/src/lib.rs b/pgrx/src/lib.rs index 6f74fd548d..bc9901600d 100644 --- a/pgrx/src/lib.rs +++ b/pgrx/src/lib.rs @@ -274,12 +274,9 @@ macro_rules! pg_magic_func { macro_rules! pg_sql_graph_magic { () => { // A marker which must exist in the root of the extension. -#[no_mangle] #[doc(hidden)] - #[rustfmt::skip] // explicit extern "Rust" is more clear here - pub extern "Rust" fn __pgrx_marker( - _: (), - ) -> $crate::pgrx_sql_entity_graph::ControlFile { + #[allow(unused)] + pub fn __pgrx_marker() -> $crate::pgrx_sql_entity_graph::ControlFile { use ::core::convert::TryFrom; let package_version = env!("CARGO_PKG_VERSION"); let context = include_str!(concat!(