Skip to content

Commit

Permalink
remove dlopen hack
Browse files Browse the repository at this point in the history
Signed-off-by: usamoi <[email protected]>
  • Loading branch information
usamoi committed Jan 10, 2024
1 parent a562516 commit 11255f3
Show file tree
Hide file tree
Showing 98 changed files with 496 additions and 671 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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"
67 changes: 3 additions & 64 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions cargo-pgrx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,16 @@ 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" ] }
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"
Expand Down
29 changes: 1 addition & 28 deletions cargo-pgrx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 <https://github.com/pgcentralfoundation/pgrx/issues/774> and <https://github.com/pgcentralfoundation/pgrx/pull/873>
for further information.
3 changes: 0 additions & 3 deletions cargo-pgrx/src/command/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ pub(crate) fn install_extension(
features,
&extdir,
&base_directory,
true,
&mut output_tracking,
)?;

Expand Down Expand Up @@ -370,7 +369,6 @@ fn copy_sql_files(
features: &clap_cargo::Features,
extdir: &PathBuf,
base_directory: &PathBuf,
skip_build: bool,
output_tracking: &mut Vec<PathBuf>,
) -> eyre::Result<()> {
let dest = get_target_sql_file(&package_manifest_path, extdir, base_directory)?;
Expand All @@ -387,7 +385,6 @@ fn copy_sql_files(
Some(&dest),
Option::<String>::None,
None,
skip_build,
output_tracking,
)?;

Expand Down
32 changes: 30 additions & 2 deletions cargo-pgrx/src/command/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand All @@ -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> {
Expand Down Expand Up @@ -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(())
}
Loading

0 comments on commit 11255f3

Please sign in to comment.