diff --git a/.cargo/config.toml b/.cargo/config.toml index fe681c554e..13c456b5dd 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,6 +1,3 @@ [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 276e796f41..3f134d0813 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -362,6 +362,7 @@ dependencies = [ "flate2", "jobslot", "nix", + "object", "once_cell", "owo-colors", "pgrx-pg-config", @@ -699,6 +700,17 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "digest" version = "0.10.7" @@ -1373,11 +1385,13 @@ dependencies = [ [[package]] name = "object" -version = "0.32.1" +version = "0.32.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" dependencies = [ + "flate2", "memchr", + "ruzstd", ] [[package]] @@ -2084,6 +2098,17 @@ dependencies = [ "wait-timeout", ] +[[package]] +name = "ruzstd" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58c4eb8a81997cf040a091d1f7e1938aeab6749d3a0dfa73af43cdc32393483d" +dependencies = [ + "byteorder", + "derive_more", + "twox-hash", +] + [[package]] name = "ryu" version = "1.0.16" @@ -2376,6 +2401,12 @@ 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" @@ -2793,6 +2824,16 @@ 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/cargo-pgrx/Cargo.toml b/cargo-pgrx/Cargo.toml index babd177abb..22ab3c9222 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.76" } +proc-macro2 = { version = "1.0.69", features = [ "span-locations" ] } quote = "1.0.33" regex = "1.10.0" ureq = { version = "2.8.0", default-features = false, features = [ "gzip" ] } @@ -43,8 +43,9 @@ 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", "visit"] } +syn = { version = "2.0.18", features = [ "extra-traits", "full", "fold", "parsing" ] } unescape = "0.1.0" +object = "0.32.1" once_cell = "1.18.0" eyre = "0.6.8" color-eyre = "0.6.2" diff --git a/cargo-pgrx/src/command/install.rs b/cargo-pgrx/src/command/install.rs index 032b5fa53d..d808d7320b 100644 --- a/cargo-pgrx/src/command/install.rs +++ b/cargo-pgrx/src/command/install.rs @@ -232,6 +232,7 @@ pub(crate) fn install_extension( features, &extdir, &base_directory, + true, &mut output_tracking, )?; @@ -369,6 +370,7 @@ 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)?; @@ -385,6 +387,7 @@ 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 c3fc8ecc69..f0f6f6f16c 100644 --- a/cargo-pgrx/src/command/new.rs +++ b/cargo-pgrx/src/command/new.rs @@ -57,7 +57,6 @@ 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(()) @@ -149,20 +148,12 @@ 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"))?; + file.write_all(include_bytes!("../templates/pgrx_embed_rs"))?; Ok(()) } diff --git a/cargo-pgrx/src/command/schema.rs b/cargo-pgrx/src/command/schema.rs index f0d65aae13..6955d3af64 100644 --- a/cargo-pgrx/src/command/schema.rs +++ b/cargo-pgrx/src/command/schema.rs @@ -8,7 +8,6 @@ //LICENSE //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::profile::CargoProfile; use crate::CommandExecute; use cargo_toml::Manifest; @@ -58,6 +57,9 @@ 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 { @@ -104,6 +106,7 @@ impl CommandExecute for Schema { self.out.as_ref(), self.dot, log_level, + self.skip_build, &mut vec![], ) } @@ -128,10 +131,10 @@ pub(crate) fn generate_schema( path: Option>, dot: Option>, log_level: Option, + skip_build: bool, output_tracking: &mut Vec, ) -> eyre::Result<()> { 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()) { @@ -141,27 +144,42 @@ pub(crate) fn generate_schema( )); } + 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()); let features_arg = features.features.join(" "); - eprintln!( - "{} for SQL generation with features `{}`", - " Building".bold().green(), - features_arg, - ); - let symbols = compute_symbols( - user_manifest_path.as_ref(), - user_package, - profile, - is_test, - features, - log_level.clone(), - &features_arg, - )?; + // First, build the SQL generator so we can get a look at the symbol table + if !skip_build { + first_build( + user_manifest_path.as_ref(), + user_package, + profile, + is_test, + features, + log_level.clone(), + &features_arg, + &flags, + )?; + }; + + let symbols = compute_symbols(profile, &manifest)?; - let codegen = compute_codegen(package_manifest_path, &symbols, &manifest)?; + let mut out_path = None; + if let Some(path) = path.as_ref() { + let x = path.as_ref().to_str().expect("`path` is not a valid UTF8 string."); + out_path = Some(x.to_string()); + } + + let mut out_dot = None; + if let Some(dot) = dot.as_ref() { + let x = dot.as_ref().to_str().expect("`dot` is not a valid UTF8 string."); + out_dot = Some(x.to_string()); + }; + + let codegen = compute_codegen(package_manifest_path, &symbols, &manifest, out_path, out_dot)?; let embed = { let mut embed = tempfile::NamedTempFile::new()?; @@ -170,47 +188,123 @@ pub(crate) fn generate_schema( embed }; - let sql = compute_sql( + if let Some(out_path) = path.as_ref() { + if let Some(parent) = out_path.as_ref().parent() { + std::fs::create_dir_all(parent).wrap_err("Could not create parent directory")?; + } + output_tracking.push(out_path.as_ref().to_path_buf()); + } + + if let Some(dot_path) = dot.as_ref() { + tracing::info!(dot = %dot_path.as_ref().display(), "Writing Graphviz DOT"); + } + + second_build( user_manifest_path.as_ref(), user_package, profile, is_test, features, - log_level, + log_level.clone(), &features_arg, + &flags, embed.path(), )?; - if let Some(out_path) = path { - let out_path = out_path.as_ref(); + compute_sql(profile)?; - eprintln!( - "{} SQL entities to {}", - " Writing".bold().green(), - format_display_path(out_path)?.cyan() - ); + Ok(()) +} - if let Some(parent) = out_path.parent() { - std::fs::create_dir_all(parent).wrap_err("Could not create parent directory")? +fn compute_symbols(profile: &CargoProfile, manifest: &Manifest) -> eyre::Result> { + use object::Object; + use std::collections::HashSet; + + // Inspect the symbol table for a list of `__pgrx_internals` we should have the generator call + let mut lib_so = get_target_dir()?; + lib_so.push(profile.target_subdir()); + 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); } - 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(),); - std::io::stdout() - .write_all(sql.as_bytes()) - .wrap_err_with(|| eyre!("Could not write SQL to stdout"))?; } - - if let Some(_dot_path) = dot { - return Err(eyre!("Could not write SQL to dot.")); + 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; + } } - Ok(()) + + 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(), + ); + + tracing::debug!("Collecting {} SQL entities", fns_to_call.len()); + + Ok(fns_to_call.into_iter().collect()) } -fn compute_symbols( +fn first_build( user_manifest_path: Option<&impl AsRef>, user_package: Option<&String>, profile: &CargoProfile, @@ -218,16 +312,18 @@ fn compute_symbols( features: &clap_cargo::Features, log_level: Option, features_arg: &str, -) -> eyre::Result> { - use syn::visit::Visit; - use syn::ItemFn; - use CargoProfile::*; - + flags: &str, +) -> eyre::Result<()> { let mut command = crate::env::cargo(); + command.stdin(Stdio::null()); + command.stdout(Stdio::null()); command.stderr(Stdio::inherit()); - command.stdout(Stdio::piped()); - command.arg("rustc"); - command.arg("--lib"); + if is_test { + command.arg("test"); + command.arg("--no-run"); + } else { + command.arg("build"); + } if let Some(user_package) = user_package { command.arg("--package"); @@ -239,22 +335,7 @@ fn compute_symbols( 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); - } - } - } else { - command.args(profile.cargo_args()); - } + command.args(profile.cargo_args()); if let Some(log_level) = &log_level { command.env("RUST_LOG", log_level); @@ -273,22 +354,16 @@ fn compute_symbols( command.arg("--all-features"); } - let flags = std::env::var("PGRX_BUILD_FLAGS").unwrap_or_default(); for arg in flags.split_ascii_whitespace() { command.arg(arg); } - 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"); - } - 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 = @@ -300,47 +375,26 @@ fn compute_symbols( std::process::exit(1) } - 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." - ) - })?; - - #[derive(Default)] - struct Visitor { - // fn() -> pgrx::pgrx_sql_entity_graph::SqlGraphEntity - internals: Vec, - } - - 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); - } - } - } - - let mut visitor = Visitor::default(); - visitor.visit_file(&file); - Ok(visitor.internals) + Ok(()) } fn compute_codegen( package_manifest_path: impl AsRef, symbols: &[String], manifest: &Manifest, + path: Option, + dot: Option, ) -> eyre::Result { use proc_macro2::{Ident, Span, TokenStream}; + let lib_name = manifest.lib_name()?; + let lib_name_ident = Ident::new(&lib_name, Span::call_site()); - let mut codegen = quote::quote! { - // This file is automatically @generated by cargo-pgrx. - }; - let extends = { - let mut out = TokenStream::new(); + let inputs = { + let mut out = quote::quote! { + 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); + }; for name in symbols.iter() { let name_ident = Ident::new(name, Span::call_site()); out.extend(quote::quote! { @@ -353,30 +407,54 @@ fn compute_codegen( } 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 build = { + let versioned_so = get_property(&package_manifest_path, "module_pathname")?.is_none(); + quote::quote! { 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()) + }; + let outputs = { + let mut out = TokenStream::new(); + if let Some(path) = path { + out.extend(quote::quote! { + eprintln!("{} SQL entities to {}", " Writing", #path); + pgrx_sql + .to_file(#path) + .expect(&format!("Could not write SQL to {}", #path)); + }); + } else { + out.extend(quote::quote! { + eprintln!("{} SQL entities to {}", " Writing", "/dev/stdout",); + pgrx_sql + .write(&mut std::io::stdout()) + .expect("Could not write SQL to stdout"); + }); + } + if let Some(dot) = dot { + out.extend(quote::quote! { + pgrx_sql + .to_dot(#dot) + .expect("Could not write Graphviz DOT"); + }); + } + out + }; + Ok(quote::quote! { + fn main() { + #inputs + #build + #outputs + } + } + .to_string()) } -fn compute_sql( +fn second_build( user_manifest_path: Option<&impl AsRef>, user_package: Option<&String>, profile: &CargoProfile, @@ -384,16 +462,19 @@ fn compute_sql( features: &clap_cargo::Features, log_level: Option, features_arg: &str, + flags: &str, embed_path: impl AsRef, -) -> eyre::Result { +) -> eyre::Result<()> { use CargoProfile::*; let mut command = crate::env::cargo(); + command.stdin(Stdio::null()); + command.stdout(Stdio::null()); command.stderr(Stdio::inherit()); - command.stdout(Stdio::piped()); - command.arg("run"); + + command.arg("rustc"); command.arg("--bin"); - command.arg("pgrx"); + command.arg("pgrx_embed"); if let Some(user_package) = user_package { command.arg("--package"); @@ -439,14 +520,22 @@ fn compute_sql( command.arg("--all-features"); } - let flags = std::env::var("PGRX_BUILD_FLAGS").unwrap_or_default(); for arg in flags.split_ascii_whitespace() { command.arg(arg); } + command.arg("--"); + + command.args(["--cfg", "pgrx_embed"]); + command.env("PGRX_EMBED", embed_path.as_ref()); let command_str = format!("{:?}", command); + eprintln!( + "{} for SQL generation with features `{}`", + " Rebuilding".bold().green(), + features_arg, + ); tracing::debug!(command = %command_str, "Running"); let cargo_output = @@ -458,22 +547,112 @@ fn compute_sql( std::process::exit(1) } - Ok(String::from_utf8(cargo_output.stdout).unwrap()) + Ok(()) } -fn needs_rustc_bootstrap() -> bool { - if std::env::var_os("RUSTC_BOOTSTRAP").is_some_and(|var| !var.is_empty()) { - return false; +fn compute_sql(profile: &CargoProfile) -> eyre::Result<()> { + let mut bin = get_target_dir()?; + bin.push(profile.target_subdir()); + bin.push("pgrx_embed"); + + let mut command = std::process::Command::new(bin); + command.stdin(Stdio::inherit()); + command.stdout(Stdio::inherit()); + command.stderr(Stdio::inherit()); + + let command_str = format!("{:?}", command); + tracing::debug!(command = %command_str, "Running"); + let embed_output = command + .output() + .wrap_err_with(|| format!("failed to spawn pgrx_embed: {}", command_str))?; + tracing::trace!(status_code = %embed_output.status, command = %command_str, "Finished"); + + if !embed_output.status.success() { + // We explicitly do not want to return a spantraced error here. + std::process::exit(1) } - 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; + Ok(()) +} + +fn parse_object(data: &[u8]) -> object::Result { + let kind = object::FileKind::parse(data)?; + + match kind { + object::FileKind::MachOFat32 => { + let arch = std::env::consts::ARCH; + + match slice_arch32(data, arch) { + Some(slice) => parse_object(slice), + None => { + panic!("Failed to slice architecture '{arch}' from universal binary.") + } + } + } + _ => object::File::parse(data), + } +} + +fn slice_arch32<'a>(data: &'a [u8], arch: &str) -> Option<&'a [u8]> { + use object::macho::FatHeader; + use object::read::macho::FatArch; + use object::Architecture; + 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, }; - !status.success() + + let candidates = FatHeader::parse_arch32(data).ok()?; + let architecture = candidates.iter().find(|a| a.architecture() == target)?; + + architecture.data(data).ok() +} + +#[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)); + } + + #[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(); + + let slice = slice_arch32(&bin, "aarch64") + .expect("Failed to slice architecture 'aarch64' from universal binary."); + assert!(parse_object(slice).is_ok()); + } + + #[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(); + + assert!(slice_arch32(&bin, "foo").is_none()); + } } diff --git a/cargo-pgrx/src/env.rs b/cargo-pgrx/src/env.rs index ea08b1f5a4..ae03d7b69c 100644 --- a/cargo-pgrx/src/env.rs +++ b/cargo-pgrx/src/env.rs @@ -12,11 +12,6 @@ pub(crate) fn cargo() -> std::process::Command { std::process::Command::new(cargo) } -pub(crate) fn rustc() -> std::process::Command { - let rustc = std::env::var_os("RUSTC").unwrap_or_else(|| "rustc".into()); - std::process::Command::new(rustc) -} - /// Set some environment variables for use downstream (in `pgrx-test` for /// example). Does nothing if already set. pub(crate) fn initialize() { diff --git a/cargo-pgrx/src/main.rs b/cargo-pgrx/src/main.rs index 7c088233b8..d4e67dd42f 100644 --- a/cargo-pgrx/src/main.rs +++ b/cargo-pgrx/src/main.rs @@ -60,31 +60,6 @@ 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/templates/cargo_config_toml b/cargo-pgrx/src/templates/cargo_config_toml index fe681c554e..13c456b5dd 100644 --- a/cargo-pgrx/src/templates/cargo_config_toml +++ b/cargo-pgrx/src/templates/cargo_config_toml @@ -1,6 +1,3 @@ [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/embed_rs b/cargo-pgrx/src/templates/embed_rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/cargo-pgrx/src/templates/embed_rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - panic!("PGRX_EMBED is not override."); -} \ No newline at end of file diff --git a/cargo-pgrx/src/templates/pgrx_embed_rs b/cargo-pgrx/src/templates/pgrx_embed_rs new file mode 100644 index 0000000000..2216cee64b --- /dev/null +++ b/cargo-pgrx/src/templates/pgrx_embed_rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); \ No newline at end of file diff --git a/cargo-pgrx/src/templates/pgrx_rs b/cargo-pgrx/src/templates/pgrx_rs deleted file mode 100644 index 98d37f6ff6..0000000000 --- a/cargo-pgrx/src/templates/pgrx_rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); \ No newline at end of file diff --git a/pgrx-examples/aggregate/embed.rs b/pgrx-examples/aggregate/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/aggregate/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/aggregate/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/aggregate/src/bin/pgrx_embed.rs b/pgrx-examples/aggregate/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/aggregate/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/arrays/embed.rs b/pgrx-examples/arrays/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/arrays/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/arrays/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/arrays/src/bin/pgrx_embed.rs b/pgrx-examples/arrays/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/arrays/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/bad_ideas/embed.rs b/pgrx-examples/bad_ideas/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/bad_ideas/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/bad_ideas/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/bad_ideas/src/bin/pgrx_embed.rs b/pgrx-examples/bad_ideas/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/bad_ideas/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/bgworker/embed.rs b/pgrx-examples/bgworker/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/bgworker/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/bgworker/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/bgworker/src/bin/pgrx_embed.rs b/pgrx-examples/bgworker/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/bgworker/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/bytea/embed.rs b/pgrx-examples/bytea/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/bytea/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/bytea/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/bytea/src/bin/pgrx_embed.rs b/pgrx-examples/bytea/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/bytea/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/composite_type/embed.rs b/pgrx-examples/composite_type/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/composite_type/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/composite_type/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/composite_type/src/bin/pgrx_embed.rs b/pgrx-examples/composite_type/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/composite_type/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/custom_libname/embed.rs b/pgrx-examples/custom_libname/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/custom_libname/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/custom_libname/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/custom_libname/src/bin/pgrx_embed.rs b/pgrx-examples/custom_libname/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/custom_libname/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/custom_sql/embed.rs b/pgrx-examples/custom_sql/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/custom_sql/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/custom_sql/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/custom_sql/src/bin/pgrx_embed.rs b/pgrx-examples/custom_sql/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/custom_sql/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/custom_types/embed.rs b/pgrx-examples/custom_types/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/custom_types/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/custom_types/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/custom_types/src/bin/pgrx_embed.rs b/pgrx-examples/custom_types/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/custom_types/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/datetime/embed.rs b/pgrx-examples/datetime/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/datetime/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/datetime/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/datetime/src/bin/pgrx_embed.rs b/pgrx-examples/datetime/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/datetime/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/errors/embed.rs b/pgrx-examples/errors/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/errors/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/errors/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/errors/src/bin/pgrx_embed.rs b/pgrx-examples/errors/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/errors/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/nostd/embed.rs b/pgrx-examples/nostd/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/nostd/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/nostd/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/nostd/src/bin/pgrx_embed.rs b/pgrx-examples/nostd/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/nostd/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/numeric/embed.rs b/pgrx-examples/numeric/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/numeric/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/numeric/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/numeric/src/bin/pgrx_embed.rs b/pgrx-examples/numeric/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/numeric/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/operators/embed.rs b/pgrx-examples/operators/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/operators/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/operators/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/operators/src/bin/pgrx_embed.rs b/pgrx-examples/operators/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/operators/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/pgtrybuilder/embed.rs b/pgrx-examples/pgtrybuilder/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/pgtrybuilder/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/pgtrybuilder/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/pgtrybuilder/src/bin/pgrx_embed.rs b/pgrx-examples/pgtrybuilder/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/pgtrybuilder/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/range/embed.rs b/pgrx-examples/range/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/range/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/range/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/range/src/bin/pgrx_embed.rs b/pgrx-examples/range/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/range/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/schemas/embed.rs b/pgrx-examples/schemas/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/schemas/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/schemas/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/schemas/src/bin/pgrx_embed.rs b/pgrx-examples/schemas/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/schemas/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/shmem/embed.rs b/pgrx-examples/shmem/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/shmem/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/shmem/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/shmem/src/bin/pgrx_embed.rs b/pgrx-examples/shmem/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/shmem/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/spi/embed.rs b/pgrx-examples/spi/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/spi/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/spi/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/spi/src/bin/pgrx_embed.rs b/pgrx-examples/spi/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/spi/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/spi_srf/embed.rs b/pgrx-examples/spi_srf/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/spi_srf/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/spi_srf/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/spi_srf/src/bin/pgrx_embed.rs b/pgrx-examples/spi_srf/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/spi_srf/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/srf/embed.rs b/pgrx-examples/srf/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/srf/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/srf/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/srf/src/bin/pgrx_embed.rs b/pgrx-examples/srf/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/srf/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/strings/embed.rs b/pgrx-examples/strings/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/strings/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/strings/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/strings/src/bin/pgrx_embed.rs b/pgrx-examples/strings/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/strings/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/triggers/embed.rs b/pgrx-examples/triggers/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/triggers/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/triggers/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/triggers/src/bin/pgrx_embed.rs b/pgrx-examples/triggers/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/triggers/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/versioned_custom_libname_so/embed.rs b/pgrx-examples/versioned_custom_libname_so/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/versioned_custom_libname_so/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/versioned_custom_libname_so/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/versioned_custom_libname_so/src/bin/pgrx_embed.rs b/pgrx-examples/versioned_custom_libname_so/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/versioned_custom_libname_so/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-examples/versioned_so/embed.rs b/pgrx-examples/versioned_so/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-examples/versioned_so/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-examples/versioned_so/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-examples/versioned_so/src/bin/pgrx_embed.rs b/pgrx-examples/versioned_so/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-examples/versioned_so/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx-tests/embed.rs b/pgrx-tests/embed.rs deleted file mode 100644 index f00fe5bc00..0000000000 --- a/pgrx-tests/embed.rs +++ /dev/null @@ -1,3 +0,0 @@ -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 deleted file mode 100644 index c982b59128..0000000000 --- a/pgrx-tests/src/bin/pgrx.rs +++ /dev/null @@ -1 +0,0 @@ -include!(env!("PGRX_EMBED")); diff --git a/pgrx-tests/src/bin/pgrx_embed.rs b/pgrx-tests/src/bin/pgrx_embed.rs new file mode 100644 index 0000000000..4fa809de0e --- /dev/null +++ b/pgrx-tests/src/bin/pgrx_embed.rs @@ -0,0 +1 @@ +pgrx::pgrx_embed!(); diff --git a/pgrx/src/lib.rs b/pgrx/src/lib.rs index bc9901600d..12578e03b3 100644 --- a/pgrx/src/lib.rs +++ b/pgrx/src/lib.rs @@ -275,7 +275,6 @@ macro_rules! pg_sql_graph_magic { () => { // A marker which must exist in the root of the extension. #[doc(hidden)] - #[allow(unused)] pub fn __pgrx_marker() -> $crate::pgrx_sql_entity_graph::ControlFile { use ::core::convert::TryFrom; let package_version = env!("CARGO_PKG_VERSION"); @@ -324,3 +323,16 @@ pub(crate) enum Utf8Compat { /// An "extended ASCII" encoding, so we're fine if we only touch ASCII Ascii, } + +#[doc(hidden)] +#[macro_export] +macro_rules! pgrx_embed { + () => { + #[cfg(not(pgrx_embed))] + fn main() { + panic!("PGRX_EMBED was not set."); + } + #[cfg(pgrx_embed)] + include!(env!("PGRX_EMBED")); + }; +}