Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for PostgreSQL 16 #3

Merged
merged 1 commit into from
Mar 11, 2024
Merged
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
156 changes: 156 additions & 0 deletions Formula/postgis@16.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
class PostgisAT16 < Formula
desc "Adds support for geographic objects to PostgreSQL"
homepage "https://postgis.net/"
url "https://download.osgeo.org/postgis/source/postgis-3.3.6.tar.gz"
sha256 "7e898063a9f50f21f42277bfb687bbb9bf5cb6f61ce160031c825403a66911b5"
license "GPL-2.0-or-later"
revision 1

livecheck do
url "https://download.osgeo.org/postgis/source/"
regex(/href=.*?postgis[._-]v?(\d+(?:\.\d+)+)\.t/i)
end

head do
url "https://git.osgeo.org/gitea/postgis/postgis.git", branch: "master"

depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "libtool" => :build
end

depends_on "gpp" => :build
depends_on "pkg-config" => :build
depends_on "gdal" # for GeoJSON and raster handling
depends_on "geos"
depends_on "icu4c"
depends_on "json-c" # for GeoJSON and raster handling
depends_on "ozeias/postgresql/postgresql@16"
depends_on "pcre2"
depends_on "proj"
depends_on "protobuf-c" # for MVT (map vector tiles) support
depends_on "sfcgal" # for advanced 2D/3D functions

fails_with gcc: "5" # C++17

def postgresql
Formula["ozeias/postgresql/postgresql@16"]
end

def install
ENV.deparallelize

# C++17 is required.
ENV.append "CXXFLAGS", "-std=c++17"

ENV["PG_CONFIG"] = postgresql.opt_bin/"pg_config"

args = [
"--with-projdir=#{Formula["proj"].opt_prefix}",
"--with-jsondir=#{Formula["json-c"].opt_prefix}",
"--with-pgconfig=#{postgresql.opt_bin}/pg_config",
"--with-protobufdir=#{Formula["protobuf-c"].opt_bin}",
# Unfortunately, NLS support causes all kinds of headaches because
# PostGIS gets all of its compiler flags from the PGXS makefiles. This
# makes it nigh impossible to tell the buildsystem where our keg-only
# gettext installations are.
"--disable-nls",
]

system "./autogen.sh" if build.head?
# Fixes config/install-sh: No such file or directory
# This is caused by a misalignment between ./configure in postgresql@16 and postgis
mv "build-aux", "config"
inreplace %w[configure utils/Makefile.in] do |s|
s.gsub! "build-aux", "config"
end
system "./configure", *args, *std_configure_args
system "make"

# Install to a staging directory to circumvent the hardcoded install paths
# set by the PGXS makefiles.
mkdir "stage"
system "make", "install", "DESTDIR=#{buildpath}/stage"

# Some files are stored in the stage directory with the cellar prefix of
# the version of postgresql used to build postgis. Since we copy these
# files into the postgis keg and symlink them to HOMEBREW_PREFIX, postgis
# only needs to be rebuilt when there is a new major version of postgresql.
postgresql_stage_path = File.join("stage", postgresql.prefix.realpath)
bin.install (buildpath/postgresql_stage_path/"bin").children
doc.install (buildpath/postgresql_stage_path/"share/doc").children

stage_path = File.join("stage", HOMEBREW_PREFIX)
lib.install (buildpath/stage_path/"lib").children
share.install (buildpath/stage_path/"share").children

# Extension scripts
bin.install %w[
utils/create_undef.pl
utils/create_upgrade.pl
utils/postgis_restore.pl
utils/profile_intersects.pl
utils/test_estimation.pl
utils/test_geography_estimation.pl
utils/test_geography_joinestimation.pl
utils/test_joinestimation.pl
]
end

test do
pg_version = postgresql.version.major
expected = /'PostGIS built for PostgreSQL % cannot be loaded in PostgreSQL %',\s+#{pg_version}\.\d,/
postgis_version = Formula["postgis"].version.major_minor
assert_match expected, (share/postgresql.name/"contrib/postgis-#{postgis_version}/postgis.sql").read

require "base64"
(testpath/"brew.shp").write ::Base64.decode64 <<~EOS
AAAnCgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoOgDAAALAAAAAAAAAAAAAAAA
AAAAAADwPwAAAAAAABBAAAAAAAAAFEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAEAAAASCwAAAAAAAAAAAPA/AAAAAAAA8D8AAAAAAAAA
AAAAAAAAAAAAAAAAAgAAABILAAAAAAAAAAAACEAAAAAAAADwPwAAAAAAAAAA
AAAAAAAAAAAAAAADAAAAEgsAAAAAAAAAAAAQQAAAAAAAAAhAAAAAAAAAAAAA
AAAAAAAAAAAAAAQAAAASCwAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAAAAA
AAAAAAAAAAAABQAAABILAAAAAAAAAAAAAAAAAAAAAAAUQAAAAAAAACJAAAAA
AAAAAEA=
EOS
(testpath/"brew.dbf").write ::Base64.decode64 <<~EOS
A3IJGgUAAABhAFsAAAAAAAAAAAAAAAAAAAAAAAAAAABGSVJTVF9GTEQAAEMA
AAAAMgAAAAAAAAAAAAAAAAAAAFNFQ09ORF9GTEQAQwAAAAAoAAAAAAAAAAAA
AAAAAAAADSBGaXJzdCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgIFBvaW50ICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgU2Vjb25kICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICBQb2ludCAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgIFRoaXJkICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgUG9pbnQgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICBGb3VydGggICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgIFBvaW50ICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgQXBwZW5kZWQgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICBQb2ludCAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAg
EOS
(testpath/"brew.shx").write ::Base64.decode64 <<~EOS
AAAnCgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARugDAAALAAAAAAAAAAAAAAAA
AAAAAADwPwAAAAAAABBAAAAAAAAAFEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAADIAAAASAAAASAAAABIAAABeAAAAEgAAAHQAAAASAAAA
igAAABI=
EOS
result = shell_output("#{bin}/shp2pgsql #{testpath}/brew.shp")
assert_match "Point", result
assert_match "AddGeometryColumn", result

pg_ctl = postgresql.opt_bin/"pg_ctl"
psql = postgresql.opt_bin/"psql"
port = free_port

system pg_ctl, "initdb", "-D", testpath/"test"
(testpath/"test/postgresql.conf").write <<~EOS, mode: "a+"

shared_preload_libraries = 'postgis-3'
port = #{port}
EOS
system pg_ctl, "start", "-D", testpath/"test", "-l", testpath/"log"
system psql, "-p", port.to_s, "-c", "CREATE EXTENSION \"postgis\";", "postgres"
system pg_ctl, "stop", "-D", testpath/"test"
end
end
139 changes: 139 additions & 0 deletions Formula/postgresql@16.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
class PostgresqlAT16 < Formula
desc "Object-relational database system"
homepage "https://www.postgresql.org/"
url "https://ftp.postgresql.org/pub/source/v16.2/postgresql-16.2.tar.bz2"
sha256 "446e88294dbc2c9085ab4b7061a646fa604b4bec03521d5ea671c2e5ad9b2952"
license "PostgreSQL"

livecheck do
url "https://ftp.postgresql.org/pub/source/"
regex(%r{href=["']?v?(16(?:\.\d+)+)/?["' >]}i)
end

# https://www.postgresql.org/support/versioning/
deprecate! date: "2028-11-09", because: :unsupported

depends_on "pkg-config" => :build
depends_on "gettext"
depends_on "icu4c"

# GSSAPI provided by Kerberos.framework crashes when forked.
# See https://github.com/Homebrew/homebrew-core/issues/47494.
depends_on "krb5"

depends_on "lz4"
depends_on "openssl@3"
depends_on "readline"
depends_on "zstd"

uses_from_macos "libxml2"
uses_from_macos "libxslt"
uses_from_macos "openldap"
uses_from_macos "perl"

on_linux do
depends_on "linux-pam"
depends_on "util-linux"
end

def install

Check failure on line 39 in Formula/postgresql@16.rb

View workflow job for this annotation

GitHub Actions / test-bot (ubuntu-22.04)

`brew install --verbose --build-bottle ozeias/postgresql/postgresql@16` failed on Linux!

pt/zstd/lib -Wl,--as-needed -Wl,-rpath,'/home/linuxbrew/.linuxbrew/Cellar/postgresql@16/16.2/lib/postgresql@16',--enable-new-dtags -fvisibility=hidden gcc-11 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -fPIC -fvisibility=hidden -I. -I. -I../../src/include -I/home/linuxbrew/.linuxbrew/Cellar/icu4c/74.2/include -I/home/linuxbrew/.linuxbrew/opt/openssl@3/include -I/home/linuxbrew/.linuxbrew/opt/readline/include -D_GNU_SOURCE -I/home/linuxbrew/.linuxbrew/Cellar/libxml2/2.12.5_1/include/libxml2 -I/home/linuxbrew/.linuxbrew/Cellar/lz4/1.9.4/include -I/home/linuxbrew/.linuxbrew/opt/zstd/include -c -o pgcrypto.o pgcrypto.c /usr/bin/mkdir -p '/home/linuxbrew/.linuxbrew/Cellar/postgresql@16/16.2/share/postgresql@16/extension' /usr/bin/mkdir -p '/home/linuxbrew/.linuxbrew/Cellar/postgresql@16/16.2/share/postgresql@16/extension' /usr/bin/install -c -m 755 postgres_fdw.so '/home/linuxbrew/.linuxbrew/Cellar/postgresql@16/16.2/lib/postgresql@16/postgres_fdw.so' /usr/bin/install -c -m 644 ./postgres_fdw.control '/home/linuxbrew/.linuxbrew/Cellar/postgresql@16/16.2/share/postgresql@16/extension/' /usr/bin/install -c -m 644 ./postgres_fdw--1.0.sql ./postgres_fdw--1.0--1.1.sql '/home/linuxbrew/.linuxbrew/Cellar/postgresql@16/16.2/share/postgresql@16/extension/' make[2]: Leaving directory '/tmp/postgresqlA16-20240311-13690-9vhzv0/postgresql-16.2/contrib/postgres_fdw' gcc-11 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -fPIC -fvisibility=hidden -I. -I. -I../../src/include -I/home/linuxbrew/.linuxbrew/Cellar/icu4c/74.2/include -I/home/linuxbrew/.linuxbrew/opt/openssl@3/include -I/home/linuxbrew/.linuxbrew/opt/readline/include -D_GNU_SOURCE -I/home/linuxbrew/.linuxbrew/Cellar/libxml2/2.12.5_1/include/libxml2 -I/home/linuxbrew/.linuxbrew/Cellar/lz4/1.9.4/include -I/home/linuxbrew/.linuxbrew/opt/zstd/include -c -o pgp-armor.o pgp-armor.c /usr/bin/mkdir -p '/home/linuxbrew/.linuxbrew/Cellar/postgresql@16/16.2/lib/postgresql@16' gcc-11 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -fPIC -fvisibility=hidden -shared -o hstore_plperl.so hstore_plperl.o -L../../src/port -L../../src/common -L/home/linuxbrew/.linuxbrew/opt/openssl@3/lib -L/home/linuxbrew/.linuxbrew/opt/readline/lib -L/home/linuxbrew/.linuxbrew/Cellar/libxml2/2.12.5_1/lib -L/home/linuxbrew/.linuxbrew/Cellar/lz4/1.9.4/lib -L/home/linuxbrew/.linuxbrew/opt/zstd/lib -Wl,--as-needed -Wl,-rpath,'/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.38/x86_64-linux-thread-multi/CORE',--enable-new-dtags -fvisibility=hidden -L/home/linuxbrew/.linuxbrew/opt/perl/lib/perl5/5.38/x86_64-linux-thread-multi/CORE -lperl -lpthread -ldl -lm -lcrypt -lutil -lc /usr/bin/mkdir -p '/home/linuxbrew/.linuxbrew/Cellar/postgresql@16/16.2/lib/postgresql@16' gcc-11 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wshadow=compatible-local -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -O2 -fPIC -fvisibility=hidden -shared -o jsonb_plperl.so jsonb_plperl.o -L../../src/port -L../../src/common -L/home/linuxbrew/.linuxbrew/opt/openssl@3/lib -L/home/linuxbrew/.linuxbrew/opt/readline/lib -L
ENV.prepend "LDFLAGS", "-L#{Formula["openssl@3"].opt_lib} -L#{Formula["readline"].opt_lib}"
ENV.prepend "CPPFLAGS", "-I#{Formula["openssl@3"].opt_include} -I#{Formula["readline"].opt_include}"

args = %W[
--disable-debug
--prefix=#{prefix}
--datadir=#{HOMEBREW_PREFIX}/share/#{name}
--libdir=#{HOMEBREW_PREFIX}/lib/#{name}
--includedir=#{HOMEBREW_PREFIX}/include/#{name}
--enable-nls
--enable-thread-safety
--with-gssapi
--with-icu
--with-ldap
--with-libxml
--with-libxslt
--with-lz4
--with-zstd
--with-openssl
--with-pam
--with-perl
--with-uuid=e2fs
--with-extra-version=\ (#{tap.user})
]
if OS.mac?
args += %w[
--with-bonjour
--with-tcl
]
end

# PostgreSQL by default uses xcodebuild internally to determine this,
# which does not work on CLT-only installs.
args << "PG_SYSROOT=#{MacOS.sdk_path}" if OS.mac? && MacOS.sdk_root_needed?

system "./configure", *args
system "make"
system "make", "install-world", "datadir=#{pkgshare}",
"libdir=#{lib}/#{name}",
"pkglibdir=#{lib}/#{name}",
"includedir=#{include}/#{name}",
"pkgincludedir=#{include}/#{name}",
"includedir_server=#{include}/#{name}/server",
"includedir_internal=#{include}/#{name}/internal"

if OS.linux?
inreplace lib/name/"pgxs/src/Makefile.global",
"LD = #{HOMEBREW_PREFIX}/Homebrew/Library/Homebrew/shims/linux/super/ld",
"LD = #{HOMEBREW_PREFIX}/bin/ld"
end
end

def post_install
(var/"log").mkpath
postgresql_datadir.mkpath

# Don't initialize database, it clashes when testing other PostgreSQL versions.
return if ENV["HOMEBREW_GITHUB_ACTIONS"]

system "#{bin}/initdb", "--locale=C", "-E", "UTF-8", postgresql_datadir unless pg_version_exists?
end

def postgresql_datadir
var/name
end

def postgresql_log_path
var/"log/#{name}.log"
end

def pg_version_exists?
(postgresql_datadir/"PG_VERSION").exist?
end

def caveats
<<~EOS
This formula has created a default database cluster with:
initdb --locale=C -E UTF-8 #{postgresql_datadir}
For more details, read:
https://www.postgresql.org/docs/#{version.major}/app-initdb.html
EOS
end

service do
run [opt_bin/"postgres", "-D", f.postgresql_datadir]
environment_variables LC_ALL: "C"
keep_alive true
log_path f.postgresql_log_path
error_log_path f.postgresql_log_path
working_dir HOMEBREW_PREFIX
end

test do
system bin/"initdb", testpath/"test" unless ENV["HOMEBREW_GITHUB_ACTIONS"]
assert_equal "#{HOMEBREW_PREFIX}/share/#{name}", shell_output("#{bin}/pg_config --sharedir").chomp
assert_equal "#{HOMEBREW_PREFIX}/lib/#{name}", shell_output("#{bin}/pg_config --libdir").chomp
assert_equal "#{HOMEBREW_PREFIX}/lib/#{name}", shell_output("#{bin}/pg_config --pkglibdir").chomp
assert_equal "#{HOMEBREW_PREFIX}/include/#{name}", shell_output("#{bin}/pg_config --includedir").chomp
end
end
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# PostgreSQL and PostGIS

This is a brew tap for installing PostgreSQL and PostGIS. Currently this tap has the following formulas:
* `postgis@15`
* `postgresql@15`
* `postgis@15` and `postgis@16`
* `postgresql@15` and `postgresql@16`

## How do I install these formulae?

Expand Down
Loading