`DESTDIR=#{buildpath}/stage` convention for postgres extensions

Hey there,

I’m using postgresql@10 with the postgis extension. I’ve built the extension from source because the formula in homebrew-core builds against postgresql which is version 12.

It works, but it’s a little painful when versions change. Rather than manually building from source I should be able to make my own formula for building postgis against version 10, right? I’ve always wanted to learn more about building my own formulas so I thought this would be a good excercise.

I’ve read the documentation and I had a crack at making my own formula: https://github.com/tatey/homebrew-hacks/blob/master/Formula/postgis%402.rb.

The extension is compiling, but I haven’t been able to get the files to end up in my postgres@10 cellar. I’ve noticed in all the homebrew formulas that build postgres extensions they build into a stage.

mkdir "stage"
system "make", "install", "DESTDIR=#{buildpath}/stage"

bin.install Dir["stage/**/bin/*"]
lib.install Dir["stage/**/lib/*"]
include.install Dir["stage/**/include/*"]
(doc/"postgresql/extension").install Dir["stage/**/share/doc/postgresql@10/extension/*"]
(share/"postgresql/extension").install Dir["stage/**/share/postgresql@10/extension/*"]
pkgshare.install Dir["stage/**/contrib/postgis-*/*"]
(share/"postgis_topology").install Dir["stage/**/contrib/postgis_topology-*/*"]

The extension files then end up in the extension’s cellar, not the postgres@10 cellar. I’ve tried doing an internet search, but is there some sort of convention/magic that either makes the extensions available without being in the postgres@10 cellar, or brew is copying it across at some point?

I realise my mental model is a bit broken so I’m hoping you can help me build it.

Cheers,
Tate

I think you still need to manually load the extension since homebrew formulae can’t write to each others install directory.

Appreciate you taking the time to reply @SMillerDev!

I’m positive that when I used to install postgis and postgresql through homebrew (Back when version 10 was the latest) it all worked out of the box.

Now I’m thinking I just imagined that.

Looking at the postgis formula I think these are the magic lines: https://github.com/Homebrew/homebrew-core/blob/master/Formula/postgis.rb#L60-L62

They write to /usr/local/share/postgres etc. This won’t install into the posgres directory but apparently postgres will look there in the homebrew install.

1 Like