From 03a2876dd0ee53409a0269f98b5bd7f8d6d4d2a7 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 25 Jul 2022 12:05:40 -0700 Subject: [PATCH 1/4] Explain postgrestd in README --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index cff865c8..db719423 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,23 @@ Option | Description [github-fpm]: https://github.com/jordansissel/fpm [docs-rs-tracing-directive]: https://docs.rs/tracing-subscriber/0.3.11/tracing_subscriber/filter/struct.EnvFilter.html +# Using PL/Rust with Postgrestd +PL/Rust currently supports being used with an experimental fork of Rust's std entitled `postgrestd` which supports an +`x86_64-unknown-linux-postgres` target. This is built via the `build` script, which pulls in `postgrestd`. +Doing so places a copy of the necessary libraries used by Rust for `std` into the appropriate "sysroot", +which is the location that rustc will look for building those libraries. + +Further usage requires setting the `PLRUST_TARGET` to the appropriate tuple, as this is still an experimental feature, +and so is not currently set by default. + +This initial build process requires a normal installation of Rust via [`rustup`](https://rustup.rs) +and for the relevant location to be writeable on the building host. + +```bash +cd plrust +./build +PLRUST_TARGET="x86_64-unknown-linux-postgres" cargo build +``` # Installation From caa3f6aa7cca59bb3ad524aa4a35ae1fe4f57c35 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Mon, 25 Jul 2022 18:03:31 -0700 Subject: [PATCH 2/4] Automatically enable postgrestd --- Cargo.toml | 2 +- README.md | 5 +++-- src/user_crate/target.rs | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c7689b90..27a52f66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/zombodb/plrust/" crate-type = ["cdylib"] [features] -default = ["pg14"] +default = ["pg14", "target_postgrestd"] pg10 = ["pgx/pg10", "pgx-tests/pg10"] pg11 = ["pgx/pg11", "pgx-tests/pg11"] pg12 = ["pgx/pg12", "pgx-tests/pg12"] diff --git a/README.md b/README.md index db719423..08479dee 100644 --- a/README.md +++ b/README.md @@ -39,13 +39,14 @@ Option | Description [docs-rs-tracing-directive]: https://docs.rs/tracing-subscriber/0.3.11/tracing_subscriber/filter/struct.EnvFilter.html # Using PL/Rust with Postgrestd + PL/Rust currently supports being used with an experimental fork of Rust's std entitled `postgrestd` which supports an `x86_64-unknown-linux-postgres` target. This is built via the `build` script, which pulls in `postgrestd`. Doing so places a copy of the necessary libraries used by Rust for `std` into the appropriate "sysroot", which is the location that rustc will look for building those libraries. -Further usage requires setting the `PLRUST_TARGET` to the appropriate tuple, as this is still an experimental feature, -and so is not currently set by default. +For further usage, `PLRUST_TARGET` can be set to an appropriate target tuple to override the default selected target, +which may become necessary if e.g. the host tuple does not have an analogous supported `postgrestd` target tuple. This initial build process requires a normal installation of Rust via [`rustup`](https://rustup.rs) and for the relevant location to be writeable on the building host. diff --git a/src/user_crate/target.rs b/src/user_crate/target.rs index b1b7975b..28ed072f 100644 --- a/src/user_crate/target.rs +++ b/src/user_crate/target.rs @@ -48,8 +48,10 @@ fn stringify_tuple(tuple: [&str; 4]) -> String { #[derive(thiserror::Error, Debug)] #[allow(dead_code)] // Such is the life of cfg code pub(crate) enum TargetErr { - #[error("unsupported target tuple")] - Unsupported, + #[error("current target {} does not support PL/Rust with postgrestd\n\ + you may override the target selection by setting the PLRUST_TARGET environment variable", + .0)] + Unsupported(String), #[error("non-UTF-8 target tuple specifiers are invalid: {}", .0.to_string_lossy())] InvalidSpec(OsString), } @@ -59,10 +61,10 @@ pub(crate) fn tuple() -> Result { Ok(v) => Ok(v), Err(env::VarError::NotPresent) => { cfg_if::cfg_if! { - if #[cfg(all(feature = "target_postgrestd", target_arch = "x86_64", target_os = "linux"))] { + if #[cfg(all(feature = "target_postgrestd", target_arch = "x86_64", target_os = "linux", target_env = "gnu"))] { Ok("x86_64-unknown-linux-postgres".to_string()) } else if #[cfg(feature = "target_postgrestd")] { - Err(TargetErr::Unsupported) + Err(TargetErr::Unsupported(host::target_tuple())) } else { Ok(host::target_tuple()) } From 5264be9cd9b4691c92255b082fef6042f8940782 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 26 Jul 2022 15:21:04 -0700 Subject: [PATCH 3/4] Revert "Automatically enable postgrestd" This reverts commit caa3f6aa7cca59bb3ad524aa4a35ae1fe4f57c35. --- Cargo.toml | 2 +- README.md | 5 ++--- src/user_crate/target.rs | 10 ++++------ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 27a52f66..c7689b90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/zombodb/plrust/" crate-type = ["cdylib"] [features] -default = ["pg14", "target_postgrestd"] +default = ["pg14"] pg10 = ["pgx/pg10", "pgx-tests/pg10"] pg11 = ["pgx/pg11", "pgx-tests/pg11"] pg12 = ["pgx/pg12", "pgx-tests/pg12"] diff --git a/README.md b/README.md index 08479dee..db719423 100644 --- a/README.md +++ b/README.md @@ -39,14 +39,13 @@ Option | Description [docs-rs-tracing-directive]: https://docs.rs/tracing-subscriber/0.3.11/tracing_subscriber/filter/struct.EnvFilter.html # Using PL/Rust with Postgrestd - PL/Rust currently supports being used with an experimental fork of Rust's std entitled `postgrestd` which supports an `x86_64-unknown-linux-postgres` target. This is built via the `build` script, which pulls in `postgrestd`. Doing so places a copy of the necessary libraries used by Rust for `std` into the appropriate "sysroot", which is the location that rustc will look for building those libraries. -For further usage, `PLRUST_TARGET` can be set to an appropriate target tuple to override the default selected target, -which may become necessary if e.g. the host tuple does not have an analogous supported `postgrestd` target tuple. +Further usage requires setting the `PLRUST_TARGET` to the appropriate tuple, as this is still an experimental feature, +and so is not currently set by default. This initial build process requires a normal installation of Rust via [`rustup`](https://rustup.rs) and for the relevant location to be writeable on the building host. diff --git a/src/user_crate/target.rs b/src/user_crate/target.rs index 28ed072f..b1b7975b 100644 --- a/src/user_crate/target.rs +++ b/src/user_crate/target.rs @@ -48,10 +48,8 @@ fn stringify_tuple(tuple: [&str; 4]) -> String { #[derive(thiserror::Error, Debug)] #[allow(dead_code)] // Such is the life of cfg code pub(crate) enum TargetErr { - #[error("current target {} does not support PL/Rust with postgrestd\n\ - you may override the target selection by setting the PLRUST_TARGET environment variable", - .0)] - Unsupported(String), + #[error("unsupported target tuple")] + Unsupported, #[error("non-UTF-8 target tuple specifiers are invalid: {}", .0.to_string_lossy())] InvalidSpec(OsString), } @@ -61,10 +59,10 @@ pub(crate) fn tuple() -> Result { Ok(v) => Ok(v), Err(env::VarError::NotPresent) => { cfg_if::cfg_if! { - if #[cfg(all(feature = "target_postgrestd", target_arch = "x86_64", target_os = "linux", target_env = "gnu"))] { + if #[cfg(all(feature = "target_postgrestd", target_arch = "x86_64", target_os = "linux"))] { Ok("x86_64-unknown-linux-postgres".to_string()) } else if #[cfg(feature = "target_postgrestd")] { - Err(TargetErr::Unsupported(host::target_tuple())) + Err(TargetErr::Unsupported) } else { Ok(host::target_tuple()) } From f5684c245d7abe4a46f73e6e0bc096afb3ecd537 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 26 Jul 2022 15:23:22 -0700 Subject: [PATCH 4/4] Note target_postgrestd in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db719423..8538f638 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Doing so places a copy of the necessary libraries used by Rust for `std` into th which is the location that rustc will look for building those libraries. Further usage requires setting the `PLRUST_TARGET` to the appropriate tuple, as this is still an experimental feature, -and so is not currently set by default. +and so is not currently set by default. Passing `--features target_postgrestd` to `cargo` also works. This initial build process requires a normal installation of Rust via [`rustup`](https://rustup.rs) and for the relevant location to be writeable on the building host.