Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,31 @@ jobs:
run: docker buildx build --build-arg PG_MAJOR=${{ matrix.postgres }} -t test .
- name: Test
run: docker run test cargo pgrx test pg${{ matrix.postgres }}

test_next:
name: Test builds on the next version of Postgres
strategy:
fail-fast: false
matrix:
postgres: [18beta1]
runner:
- ubuntu-22.04
- ubuntu-22.04-arm
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build
run: docker buildx build --build-arg PG_MAJOR=${{ matrix.postgres }} --build-arg NEXT=true -t test .
- name: Test
run: docker run test cargo pgrx test pg${{ matrix.postgres }}

lint:
name: Linting (fmt + clippy)
runs-on: ubuntu-latest
steps:
- name: Install rust
uses: dtolnay/rust-toolchain@1.81.0
uses: dtolnay/rust-toolchain@1.85.0
with:
components: rustfmt, clippy
- name: Checkout
Expand All @@ -52,6 +71,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Install rust
uses: dtolnay/rust-toolchain@1.81.0
uses: dtolnay/rust-toolchain@1.85.0
- name: Lockfile check
run: cargo update -w --locked
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Install rust
uses: dtolnay/rust-toolchain@1.81.0
uses: dtolnay/rust-toolchain@1.85.0
- name: Install dependencies
run: |
# Add postgres package repo
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ publish = false
version = "0.2.0"

edition = "2021"
rust-version = "1.81.0"
rust-version = "1.82.0"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be 85 or 82?


[lib]
crate-type = ["cdylib", "lib"]
Expand Down
27 changes: 24 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ARG PG_MAJOR
ARG NEXT

FROM postgres:${PG_MAJOR}

Expand All @@ -25,20 +26,40 @@ RUN chown postgres:postgres /home/postgres
USER postgres

RUN \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain 1.81.0 && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain 1.85.0 && \
rustup --version && \
rustc --version && \
cargo --version

# pgrx
RUN cargo install cargo-pgrx --version 0.12.7 --locked
ARG NEXT
RUN if [ "$NEXT" = "true" ] ; then \
echo "Installing pgrx from GitHub repository" && \
cargo install --git https://github.com/pgcentralfoundation/pgrx --branch develop cargo-pgrx --locked ; \
else \
echo "Installing pgrx from crates.io" && \
cargo install cargo-pgrx --version 0.12.7 --locked ; \
fi

RUN cargo pgrx init --pg${PG_MAJOR} $(which pg_config)

USER root

COPY . .

RUN if [ "$NEXT" = "true" ] ; then \
# update Rust edition from what exists in Cargo.toml
sed -i 's/edition[[:space:]]*=[[:space:]]*"[^"]*"/edition = "2024"/g' Cargo.toml && \
# update Rust version from what exists in Cargo.toml
sed -i 's/rust-version[[:space:]]*=[[:space:]]*"[^"]*"/rust-version = "1.85.0"/g' Cargo.toml && \
# update pgrx versions from what exists in Cargo.toml
sed -i 's/pgrx[[:space:]]*=[[:space:]]*"[^"]*"/pgrx = "0.15.0"/g' Cargo.toml && \
sed -i 's/pgrx-tests[[:space:]]*=[[:space:]]*"[^"]*"/pgrx-tests = "0.15.0"/g' Cargo.toml && \
# add required features for next PG
sed -i '/pg17[[:space:]]*=[[:space:]]*\[.*\]/a pg18 = ["pgrx-tests/pg18", "pgrx/pg18"]' Cargo.toml && \
echo "=== Updated Cargo.toml contents ===" && \
cat Cargo.toml ; \
fi

RUN cargo pgrx install

RUN chown -R postgres:postgres /home/postgres
Expand Down
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ use pg_sys::Datum as SysDatum;
use pgrx::callconv::{ArgAbi, BoxRet};
use pgrx::datum::Datum;
use pgrx::{
pg_shmem_init, pg_sys::Oid, prelude::*, rust_regtypein, shmem::*, PgLwLock, StringInfo, Uuid,
pg_shmem_init, pg_sys::Oid, prelude::*, rust_regtypein, PgLwLock, PgSharedMemoryInitialization,
StringInfo, Uuid,
};
use std::time::{Duration, SystemTime};

::pgrx::pg_module_magic!();

static SHARED_ULID: PgLwLock<u128> = PgLwLock::new();
static SHARED_ULID: PgLwLock<u128> = PgLwLock::new(c"pgx_ulid_shared");

#[pg_guard]
pub extern "C" fn _PG_init() {
pub extern "C-unwind" fn _PG_init() {
pg_shmem_init!(SHARED_ULID);
}

Expand Down Expand Up @@ -69,7 +70,7 @@ impl FromDatum for ulid {
where
Self: Sized,
{
let bytes: &[u8] = FromDatum::from_polymorphic_datum(datum, is_null, typoid)?;
let bytes: &[u8] = unsafe { FromDatum::from_polymorphic_datum(datum, is_null, typoid)? };

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What made this unsafe?


let mut len_bytes = [0u8; 16];
len_bytes.copy_from_slice(bytes);
Expand Down