testing/postgresql-pg_graphql: new aport

This commit is contained in:
Jakub Jirutka 2023-12-18 20:33:01 +01:00
parent 7cdea84144
commit 58df6bd647
2 changed files with 137 additions and 0 deletions

View File

@ -0,0 +1,71 @@
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=postgresql-pg_graphql
_projname=pg_graphql
pkgver=1.4.2
pkgrel=0
pkgdesc="GraphQL support for PostgreSQL"
url="https://supabase.github.io/pg_graphql/"
# ppc64le,riscv64,s390x: fails to build due to ring crate (https://github.com/pgcentralfoundation/pgrx/pull/1442)
arch="all !ppc64le !riscv64 !s390x"
license="Apache-2.0"
makedepends="
cargo
chrpath
jq
openssl-dev
postgresql
postgresql-dev
rustfmt
"
source="https://github.com/supabase/pg_graphql/archive/v$pkgver/$_projname-$pkgver.tar.gz
remove-regex.patch
"
builddir="$srcdir/$_projname-$pkgver"
# check: tests tries to write to /usr/lib/...
# net: fetches crates in build phase
options="!check net"
export PGRX_HOME="$srcdir/.pgrx"
prepare() {
default_prepare
cargo fetch --target="$CTARGET" --locked
}
build() {
local pgver="$(pg_config --major-version)"
# We must install it this way because cargo-pgrx and pgrx dependency
# versions in the project must be identical. :(
local pgrx_ver; pgrx_ver="$(cargo metadata --locked --format-version 1 \
| jq -r '.packages[] | select(.name == "pgrx") | .version')"
# Use dev profile to speed-up compilation.
cargo install --locked --profile dev --bins --root target/tools "cargo-pgrx@$pgrx_ver"
export PATH="$PWD/target/tools/bin:$PATH"
cargo pgrx init --pg$pgver="$(which pg_config)"
# TODO: Remove after >0.11.2 is released (https://github.com/pgcentralfoundation/pgrx/pull/1441).
[ -n "$RUSTFLAGS" ] && export RUSTFLAGS="$(echo $RUSTFLAGS)" || unset RUSTFLAGS
cargo pgrx package --verbose --out-dir="target/release/dist"
# Remove RPATH.
# NOTE: CARGO_PROFILE_RELEASE_RPATH=false doesn't work here.
chrpath -d target/release/dist/usr/lib/postgresql*/*.so
}
package() {
depends="postgresql$(pg_config --major-version)"
mkdir -p "$pkgdir"
cp -r target/release/dist/* "$pkgdir"/
}
sha512sums="
d1d0612b39916062b85b855975948376aae47066028532c118ee404808c245fc7617fd0a39a410397572601194f38f7a04a69a99b8aa71f43a79cc8710223cb4 pg_graphql-1.4.2.tar.gz
dc517bfb9813a1c807c01146d7f81dbfc14b004fb5be915794092bf7a2cdfa84edcdfe221094f8e196cf169980c02cdfcf339d80fd16114c040a03a3d765b416 remove-regex.patch
"

View File

@ -0,0 +1,66 @@
Patch-Source: https://github.com/supabase/pg_graphql/pull/473
--
From bd6d3c4af27e7961e0c3d4632289d155336e399e Mon Sep 17 00:00:00 2001
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Mon, 18 Dec 2023 19:20:43 +0100
Subject: [PATCH] replace regex with std alternative
regex is a big dependency (adds over 1 MiB to the binary size) and it's
unnecessary for such a simple check.
---
Cargo.lock | 1 -
Cargo.toml | 1 -
src/graphql.rs | 10 +++-------
3 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index bcd2ab8d..16ef67c8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1105,7 +1105,6 @@ dependencies = [
"pgrx",
"pgrx-tests",
"rand",
- "regex",
"serde",
"serde_json",
"uuid",
diff --git a/Cargo.toml b/Cargo.toml
index 88d0995d..610767b3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,7 +22,6 @@ itertools = "0.10.3"
cached = "0.34.0"
rand = "0.8"
uuid = "1"
-regex = "1"
base64 = "0.13"
lazy_static = "1"
bimap = { version = "0.6.3", features = ["serde"] }
diff --git a/src/graphql.rs b/src/graphql.rs
index 602153b3..f2a4e394 100644
--- a/src/graphql.rs
+++ b/src/graphql.rs
@@ -2,19 +2,15 @@ use crate::sql_types::*;
use cached::proc_macro::cached;
use cached::SizedCache;
use itertools::Itertools;
-use lazy_static::lazy_static;
-use regex::Regex;
use serde::Serialize;
use std::collections::{HashMap, HashSet};
use std::ops::Deref;
use std::sync::Arc;
-lazy_static! {
- static ref GRAPHQL_NAME_RE: Regex = Regex::new("^[_A-Za-z][_0-9A-Za-z]*$").unwrap();
-}
-
fn is_valid_graphql_name(name: &str) -> bool {
- GRAPHQL_NAME_RE.is_match(name)
+ !name.is_empty()
+ && name.starts_with(|c: char| c == '_' || c.is_ascii_alphabetic())
+ && name.chars().all(|c| c == '_' || c.is_ascii_alphanumeric())
}
fn to_base_type_name(name: &str, name_override: &Option<String>, inflect_names: bool) -> String {