Skip to content

Commit

Permalink
Merge #408
Browse files Browse the repository at this point in the history
408: Upgrade to pgx 0.4.5 r=rtwalker a=rtwalker

### Upgrading to the latest pgx
Closes #387 

Went from 0.2.4 -> 0.3.0 -> 0.4.0 -> 0.4.3, editing the Cargo.toml, building, and testing, and the experience was largely unremarkable.

Most of the changes come from followng the "Upgrading" section of the [0.4.0](https://github.com/tcdi/pgx/releases/tag/v0.4.0) release notes.

Only thing to note is that I ran into a *lot* of occurrences of the following error:
```
 error[E0053]: method `input` has an incompatible type for trait
    --> extension/src/type_builder.rs:261:29
     |
 261 |             fn input(input: &std::ffi::CStr) -> $name<'input>
     |                             ^^^^^^^^^^^^^^^
     |                             |
     |                             expected struct `pgx::cstr_core::CStr`, found struct `std::ffi::CStr`
     |                             help: change the parameter type to match the trait: `&pgx::cstr_core::CStr`
```

However, just blindly swapping in the `pgx::cstr_core` `CStr(ing)`s for the `std::ffi` ones made Rust much happier. 
Please yell at me if that's too irresponsible.

### macOS support on Apple M1 Macs
I think we should be OK to close #401 as well. 

`pgx` claims M1 support, and by virtue of being able to do 
```
$ cargo pgx run pg14
    Stopping Postgres v14
building extension with features `pg14`
"cargo" "build" "--features" "pg14" "--no-default-features" "--message-format=json-render-diagnostics"
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s

installing extension
     Copying control file to /Users/rwalker/.pgx/14.2/pgx-install/share/postgresql/extension/timescaledb_toolkit.control
     Copying shared library to /Users/rwalker/.pgx/14.2/pgx-install/lib/postgresql/timescaledb_toolkit.so
 Discovering SQL entities
  Discovered 655 SQL entities: 9 schemas (1 unique), 521 functions, 71 types, 0 enums, 54 sqls, 0 ords, 0 hashes, 0 aggregates
     Writing SQL entities to /Users/rwalker/.pgx/14.2/pgx-install/share/postgresql/extension/timescaledb_toolkit--1.7.0-dev.sql
    Finished installing timescaledb_toolkit
    Starting Postgres v14 on port 28814
    Re-using existing database timescaledb_toolkit
psql (14.2)
Type "help" for help.

timescaledb_toolkit=# 
```
and
```
$ cargo pgx test pg14
"cargo" "test" "--features" "pg14 pg_test" "--no-default-features"
    Finished test [unoptimized + debuginfo] target(s) in 0.07s
     Running unittests (/Users/rwalker/timescale/timescaledb-toolkit/target/debug/deps/timescaledb_toolkit-66d8cc098ff75a32)

running 131 tests
building extension with features `pg14 pg_test`
"cargo" "build" "--features" "pg14 pg_test" "--no-default-features" "--message-format=json-render-diagnostics"
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s

installing extension
     Copying control file to /Users/rwalker/.pgx/14.2/pgx-install/share/postgresql/extension/timescaledb_toolkit.control
     Copying shared library to /Users/rwalker/.pgx/14.2/pgx-install/lib/postgresql/timescaledb_toolkit.so
 Discovering SQL entities
  Discovered 837 SQL entities: 39 schemas (2 unique), 668 functions, 72 types, 0 enums, 58 sqls, 0 ords, 0 hashes, 0 aggregates
     Writing SQL entities to /Users/rwalker/.pgx/14.2/pgx-install/share/postgresql/extension/timescaledb_toolkit--1.7.0-dev.sql
    Finished installing timescaledb_toolkit

 ** eliding the list of 131 tests **

test result: ok. 131 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 8.87s

Stopping Postgres

```
where I have
```
$ uname -om
arm64 Darwin
```
I think we can claim M1 support too.

Co-authored-by: Ryan Walker <rwalker@timescale.com>
Co-authored-by: Eric Gillespie <epg@timescale.com>
  • Loading branch information
3 people authored May 26, 2022
2 parents 5b30f5f + 73d1a7e commit 4e6eed2
Show file tree
Hide file tree
Showing 13 changed files with 375 additions and 308 deletions.
603 changes: 348 additions & 255 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ For Ubuntu you can follow the [postgres install instructions](https://www.postgr
```bash
sudo apt-get install make gcc pkg-config clang postgresql-server-dev-13 libssl-dev
```
and finally, [pgx](https://github.com/zombodb/pgx), which can be installed with
and finally, [pgx](https://github.com/tcdi/pgx), which can be installed with
```bash
cargo install --version '=0.2.4' cargo-pgx && cargo pgx init --pg13 pg_config
cargo install --version '=0.4.5' cargo-pgx && cargo pgx init --pg13 pg_config
```

Installing from source is also available on macOS and requires the same set of prerequisites and set up commands listed above.

### 💾 Building and Installing the extension ###

Download or clone this repository, and switch to the `extension` subdirectory, e.g.
Expand Down Expand Up @@ -71,8 +73,7 @@ hop on the [Discussions forum](https://github.com/timescale/timescaledb-toolkit/

See above for prerequisites and installation instructions.

You can run tests against a postgres version
`pg12`, or `pg13` using
You can run tests against a postgres version `pg12`, `pg13`, or `pg14` using

```
cargo pgx test ${postgres_version}
Expand Down
1 change: 1 addition & 0 deletions docker/ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ USER postgres
RUN cargo install cargo-pgx --version '=0.2.4' --root /home/postgres/pgx/0.2 \
&& cargo install cargo-pgx --version '=0.4.5' --root /home/postgres/pgx/0.4

# TODO After we upgrade to 0.4 change this to 0.4 and remove the hack in tools/build .
ENV PATH "/home/postgres/pgx/0.2/bin/:${PATH}"

RUN set -ex \
Expand Down
19 changes: 3 additions & 16 deletions extension/.cargo/config
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# Auto-generated by pgx. You may edit this, or delete it to have a new one created.

[target.x86_64-unknown-linux-gnu]
linker = "./.cargo/pgx-linker-script.sh"

[target.aarch64-unknown-linux-gnu]
linker = "./.cargo/pgx-linker-script.sh"

[target.x86_64-apple-darwin]
linker = "./.cargo/pgx-linker-script.sh"

[target.aarch64-apple-darwin]
linker = "./.cargo/pgx-linker-script.sh"

[target.x86_64-unknown-freebsd]
linker = "./.cargo/pgx-linker-script.sh"
[build]
# Postgres symbols won't be available until runtime
rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]
19 changes: 0 additions & 19 deletions extension/.cargo/pgx-linker-script.sh

This file was deleted.

8 changes: 4 additions & 4 deletions extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.3.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]
crate-type = ["cdylib"]

[features]
default = []
Expand All @@ -18,8 +18,8 @@ pg_test = ["approx"]
[dependencies]
# Keep synchronized with `cargo install --version N.N.N cargo-pgx` in Readme.md and docker/ci/Dockerfile
# Also `pgx-tests` down below in `dev-dependencies`.
pgx = "=0.2.4"
pgx-macros = "=0.2.4"
pgx = "=0.4.5"
pgx-macros = "=0.4.5"
encodings = {path="../crates/encodings"}
flat_serialize = {path="../crates/flat_serialize/flat_serialize"}
flat_serialize_macro = {path="../crates/flat_serialize/flat_serialize_macro"}
Expand Down Expand Up @@ -51,5 +51,5 @@ spfunc = "0.1.0"
statrs = "0.15.0"

[dev-dependencies]
pgx-tests = "=0.2.4"
pgx-tests = "=0.4.5"
approx = "0.4.0"
2 changes: 0 additions & 2 deletions extension/src/bin/sql-generator.rs

This file was deleted.

4 changes: 2 additions & 2 deletions extension/src/datum_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl DatumFromSerializedTextReader {
}

pub fn read_datum(&mut self, datum_str: &str) -> Datum {
let cstr = std::ffi::CString::new(datum_str).unwrap(); // TODO: error handling
let cstr = pgx::cstr_core::CString::new(datum_str).unwrap(); // TODO: error handling
let cstr_ptr = cstr.as_ptr() as *mut std::os::raw::c_char;
unsafe { pg_sys::InputFunctionCall(&mut self.flinfo, cstr_ptr, self.typ_io_param, -1) }
}
Expand All @@ -90,7 +90,7 @@ impl Serialize for TextSerializeableDatum {
S: serde::Serializer,
{
let chars = unsafe { pg_sys::OutputFunctionCall(self.1, self.0) };
let cstr = unsafe { std::ffi::CStr::from_ptr(chars) };
let cstr = unsafe { pgx::cstr_core::CStr::from_ptr(chars) };
serializer.serialize_str(cstr.to_str().unwrap())
}
}
Expand Down
9 changes: 6 additions & 3 deletions extension/src/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

use std::{convert::TryInto, ffi::CStr, os::raw::{c_char, c_int}};
pub use self::types::{PgTypId, ShortTypeId};
pub use self::collations::PgCollationId;
pub use self::functions::PgProcId;
pub use self::types::{PgTypId, ShortTypeId};
use std::{
convert::TryInto,
os::raw::{c_char, c_int},
};

use pgx::cstr_core::CStr;
use pgx::pg_sys;

mod functions;
Expand Down
2 changes: 1 addition & 1 deletion extension/src/time_vector/pipeline/lambda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'input> InOutFuncs for Lambda<'input> {
}
}

fn input(input: &std::ffi::CStr) -> Self
fn input(input: &pgx::cstr_core::CStr) -> Self
where
Self: Sized,
{
Expand Down
2 changes: 1 addition & 1 deletion extension/src/type_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ macro_rules! ron_inout_funcs {
}
}

fn input(input: &std::ffi::CStr) -> $name<'input>
fn input(input: &pgx::cstr_core::CStr) -> $name<'input>
where
Self: Sized,
{
Expand Down
2 changes: 1 addition & 1 deletion extension/src/uddsketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl<'input> InOutFuncs for UddSketch<'input> {
}
}

fn input(input: &std::ffi::CStr) -> Self
fn input(input: &pgx::cstr_core::CStr) -> Self
where
Self: Sized,
{
Expand Down
3 changes: 3 additions & 0 deletions tools/build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set -ex

# TODO After we upgrade to 0.4 make this change in docker/ci/Dockerfile and then remove this line.
export PATH=/home/postgres/pgx/0.4/bin:$PATH

print() {
printf '%s\n' "$*"
}
Expand Down

0 comments on commit 4e6eed2

Please sign in to comment.