tcdi / plrust

A Rust procedural language handler for PostgreSQL
PostgreSQL License
1.12k stars 33 forks source link

Verification failure - No such file or directory #366

Closed olirice closed 1 year ago

olirice commented 1 year ago

After following the install process I'm getting a panic on every attempt to create a function (backtrace below)

Screenshot 2023-07-31 at 1 29 52 PM

I can see the functions being written in the work dir

Screenshot 2023-07-31 at 1 31 25 PM

and can cargo build them as the postgres user

System:

Any ideas what might be going on here? Happy to run any tests that would provide more info. Thanks!

eeeebbbbrrrr commented 1 year ago

@olirice, I think that's saying the process can't find cargo.

And "the process" would be the connected Postgres backend. PL/Rust will expect Rust to be installed by the postgres user (or whomever the postgres server runs as) and will look in ~/.cargo/bin.

The ubuntu systemd scripts for Postgres completely sanitize the environment before starting Postgres -- there's not even a PATH.

The logic for figuring this out is:

/// `cargo` needs a PATH in order to find its tools and we have some rules about setting that up...
///
/// If the `plrust.PATH_override` GUC is set, we just blindly use it.  Otherwise, if PATH is set,
/// we'll use that.  Otherwise we'll create one of `~/.cargo/bin:/usr/bin` and hope it's good enough.
fn configure_path(command: &mut Command) -> eyre::Result<()> {
    if let Some(path) = PLRUST_PATH_OVERRIDE.get() {
        // we were configured with an explicit $PATH to use
        command.env("PATH", path);
    } else {
        let is_empty = match std::env::var("PATH") {
            Ok(s) if s.trim().is_empty() => true,
            Ok(_) => false,
            Err(VarError::NotPresent) => true,
            Err(e) => return Err(eyre::eyre!(e)),
        };

        if is_empty {
            // the environment has no $PATH, so lets try and make a good one based on where
            // we'd expect 'cargo' to be installed
            if let Ok(path) = home::cargo_home() {
                let path = path.join("bin");
                command.env(
                    "PATH",
                    std::env::join_paths(vec![path.as_path(), std::path::Path::new("/usr/bin")])?,
                );
            } else {
                // we don't have a home directory... where could cargo be?  Ubuntu installed cargo
                // at least puts it in /usr/bin
                command.env("PATH", "/usr/bin");
            }
        }
    }
    Ok(())
}

EDIT: That comes from https://github.com/tcdi/plrust/blob/29b7643ee3f2c5534b25d667fee824619a6fc9f6/plrust/src/user_crate/cargo.rs#L43

olirice commented 1 year ago

it was a path issue. After setting the path manually its passing that point

thanks for the help!