feat: hecitc C: add hectic-config

This commit is contained in:
2025-04-19 22:05:56 +00:00
parent 2229cf072b
commit 0c58befc43
4 changed files with 56 additions and 9 deletions

View File

@@ -430,7 +430,7 @@
pname = "http"; pname = "http";
inherit version; inherit version;
src = prev.fetchFromGitHub { owner = "pramsey"; repo = "pgsql-http"; rev = "v${version}"; hash = "sha256-C8eqi0q1dnshUAZjIsZFwa5FTYc7vmATF3vv2CReWPM="; }; nativeBuildInputs = with prev; [pkg-config curl]; }; src = prev.fetchFromGitHub { owner = "pramsey"; repo = "pgsql-http"; rev = "v${version}"; hash = "sha256-C8eqi0q1dnshUAZjIsZFwa5FTYc7vmATF3vv2CReWPM="; }; nativeBuildInputs = with prev; [pkg-config curl]; };
buildHelloExt = versionSuffix: let buildHelExt = versionSuffix: let
postgresql = prev."postgresql_${versionSuffix}"; postgresql = prev."postgresql_${versionSuffix}";
in buildPostgresqlExtension { in buildPostgresqlExtension {
inherit postgresql; inherit postgresql;
@@ -447,25 +447,25 @@
http = buildHttpExt "17"; http = buildHttpExt "17";
pg_smtp_client = buildSmtpExt "17"; pg_smtp_client = buildSmtpExt "17";
plhaskell = buildPlHaskellExt "17"; plhaskell = buildPlHaskellExt "17";
hel = buildHelloExt "17"; hel = buildHelExt "17";
};}; };};
postgresql_16 = prev.postgresql_16 // {pkgs = prev.postgresql_16.pkgs // { postgresql_16 = prev.postgresql_16 // {pkgs = prev.postgresql_16.pkgs // {
http = buildHttpExt "16"; http = buildHttpExt "16";
pg_smtp_client = buildSmtpExt "16"; pg_smtp_client = buildSmtpExt "16";
plhaskell = buildPlHaskellExt "16"; plhaskell = buildPlHaskellExt "16";
hel = buildHelloExt "16"; hel = buildHelExt "16";
};}; };};
postgresql_15 = prev.postgresql_15 // {pkgs = prev.postgresql_15.pkgs // { postgresql_15 = prev.postgresql_15 // {pkgs = prev.postgresql_15.pkgs // {
http = buildHttpExt "15"; http = buildHttpExt "15";
pg_smtp_client = buildSmtpExt "15"; pg_smtp_client = buildSmtpExt "15";
plhaskell = buildPlHaskellExt "15"; plhaskell = buildPlHaskellExt "15";
hel = buildHelloExt "15"; hel = buildHelExt "15";
};}; };};
postgresql_14 = prev.postgresql_14 // {pkgs = prev.postgresql_14.pkgs // { postgresql_14 = prev.postgresql_14 // {pkgs = prev.postgresql_14.pkgs // {
http = buildHttpExt "14"; http = buildHttpExt "14";
pg_smtp_client = buildSmtpExt "14"; pg_smtp_client = buildSmtpExt "14";
plhaskell = buildPlHaskellExt "14"; plhaskell = buildPlHaskellExt "14";
hel = buildHelloExt "14"; hel = buildHelExt "14";
};}; };};
writers = let writers = let
writeC = writeC =

View File

@@ -18,9 +18,46 @@ stdenv.mkDerivation {
''; '';
installPhase = '' installPhase = ''
mkdir -p $out/lib $out/include mkdir -p $out/lib $out/include $out/bin
cp target/libhectic.a $out/lib/ cp target/libhectic.a $out/lib/
cp hectic.h $out/include/ cp hectic.h $out/include/
# Create hectic-config script
cat > $out/bin/hectic-config <<EOF
#!/bin/sh
usage() {
echo "Usage: hectic-config [--cflags] [--libs]"
echo " --cflags Print the compiler flags"
echo " --libs Print the linker flags"
echo " --help Display this help message"
exit \$1
}
if [ \$# -eq 0 ]; then
usage 1
fi
while [ \$# -gt 0 ]; do
case "\$1" in
--cflags)
echo "-I$out/include"
;;
--libs)
echo "-L$out/lib -lhectic"
;;
--help)
usage 0
;;
*)
usage 1
;;
esac
shift
done
EOF
chmod +x $out/bin/hectic-config
''; '';
meta = { meta = {

View File

@@ -7,7 +7,11 @@ PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs) PGXS := $(shell $(PG_CONFIG) --pgxs)
# Add hectic library path HECTIC_CONFIG = hectic-config
CFLAGS += -I -lhectic
CFLAGS += $(shell $(HECTIC_CONFIG) --cflags)
LDFLAGS += $(shell $(HECTIC_CONFIG) --libs)
SHLIB_LINK := $(LIBS)
include $(PGXS) include $(PGXS)

View File

@@ -86,8 +86,14 @@ case "$MODE" in
build) build)
mkdir -p target mkdir -p target
echo "# Building PostgreSQL extension" echo "# Building PostgreSQL extension"
# Get hectic library paths from nix
HECTIC_PATH=$(nix build --print-out-paths -f ../../../. c-hectic)
HECTIC_INCLUDE="$HECTIC_PATH/include"
HECTIC_LIB="$HECTIC_PATH/lib"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
gcc $CFLAGS $OPTFLAGS -I$PG_INCLUDE -shared -o target/hel.so hel.c gcc $CFLAGS $OPTFLAGS -I$PG_INCLUDE -I$HECTIC_INCLUDE -shared -o target/hel.so hel.c -L$HECTIC_LIB -lhectic
# Copy extension files to target directory # Copy extension files to target directory
cp hel.control target/ cp hel.control target/