Out of tree builds
Recently I was asked “what’s a vpath build?” If you regularly build postgres from source it’s something you should know about. A vpath build is one where the build tree is kept completely separate from the source tree, so you can completely remove the build tree and your source tree is still there, clean and pristine. It’s very easy to set up unless you’re building with the Microsoft toolset. Essentially what you do is create the root of your build tree, change directory into that directory, and then call
configure in your source tree from there.
configure knows all about setting up the vpath tree and does all the work for you. After that, you just run
make etc just like you would normally. So it looks like this:
mkdir mybuild cd mybuild /path/to/postgresql-source/configure make
You can even do this inside your source tree, so that mybuild is a subdirectory of the postgresql source root.
Another advantage of this is that if you’re working on several
git branches at once in a given work tree, you can keep a build tree for each branch and then switch between branches.
The Buildfarm client has support for this type of build in its configuration file, and it’s actually the most efficient way to run the client.
Thanks for this, I never knew this existed. As someone who often builds from source and likes to tinker with dev code every now an then I can see using this in the future.
It works for many autotools-based projects, CMake projects, etc. Very handy.
Alternately, you can use multiple git worktrees. The worktrees can target the same branch or different branches. It’s very handy when you’re developing on multiple branches or against multiple versions of Pg.
I used to use “git clone –reference” for this, but then you need to push/pull between your various local trees. With git-worktree you don’t, so your checkouts for 9.1, 9.2, 9.3, 9.4, 9.5, 9.6, 10, 10+patches, etc can all share the same repo with no hassle. It’s great.
Right. To be clear, you can use both separate worktrees and vpath builds. I tend to have a separate worktree for each long-lived branch (REL9_6_STABLE etc) as well as the master branch, and switch between master and short-lived topic branches. (BTW, I’m pretty sure git-worktree doesn’t let you have multiple trees for the same branch.) There is an older more loosely coupled technique from before git-worktree became available that I have used for years, and is used today in the buildfarm client.