-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Debugging: scripts and documentation (#21)
Co-authored-by: urso <steffen.siering at gmail.com>
- Loading branch information
Showing
7 changed files
with
490 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Script to fetch and build postgres from source. | ||
# | ||
# We use meson and ninja to build postgres. Thanks to this we get a | ||
# compile_commands.json file that can be used with LSP to navigate the postgres | ||
# source code and parallel compilation out of the box, which improves | ||
# compilation times quite a bit. | ||
|
||
#set -x | ||
set -e | ||
|
||
USAGE=" | ||
Usage: $0 <options> | ||
-h: print this help message | ||
-r|--repo <repo>: git repository to clone postgres from. | ||
-b|--branch <branch>: branch to clone from the repository. | ||
Environment variables: | ||
WORKDIR: directory to store the files and installation. | ||
the root of the project. | ||
PG_SRC_DIR: directory to store the postgres source code. Defaults to \$WORKDIR/postgresql_src. | ||
PG_BUILD_DIR: directory to store the build files. Defaults to \$PG_SRC_DIR/build. | ||
PG_INSTALL_DIR: directory to install postgres to. Defaults to \$WORKDIR/local. | ||
" | ||
|
||
ROOTDIR=${PRJ_ROOT:-$(git rev-parse --show-toplevel)} | ||
WORKDIR=${WORKDIR:-"${ROOTDIR}/out"} | ||
PG_SRC_DIR=${PG_SRC_DIR:-"$WORKDIR/postgresql_src"} | ||
PG_BUILD_DIR=${PG_BUILD_DIR:-"$PG_SRC_DIR/build"} | ||
PG_INSTALL_DIR=${PG_INSTALL_DIR:-"$WORKDIR/local"} | ||
|
||
# Use the github mirror by default | ||
POSTGRES_REPO=${POSTGRES_REPO:-https://github.com/postgres/postgres.git} | ||
POSTGRES_BRANCH=${POSTGRES_BRANCH:-"REL_16_STABLE"} | ||
|
||
POSITIONAL_ARGS=() | ||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
-h) | ||
echo "$USAGE" | ||
exit 0 | ||
;; | ||
--repo | -r) | ||
POSTGRES_REPO="$2" | ||
shift 2 | ||
;; | ||
-b | --branch) | ||
POSTGRES_BRANCH="$2" | ||
shift 2 | ||
;; | ||
*) | ||
POSITIONAL_ARGS+=("$1") # save positional arg | ||
shift # past argument | ||
;; | ||
esac | ||
done | ||
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters | ||
|
||
clone() { | ||
echo "Downloading postgres source from $POSTGRES_REPO" | ||
|
||
if [ -d "$PG_SRC_DIR" ] && [ -n "$(ls -A $PG_SRC_DIR)" ]; then | ||
echo "The directory $PG_SRC_DIR already exists and is not empty. Aborting." | ||
return 0 | ||
fi | ||
|
||
mkdir -p $(dirname $PG_SRC_DIR) | ||
git clone --single-branch -b ${POSTGRES_BRANCH} ${POSTGRES_REPO} $PG_SRC_DIR | ||
} | ||
|
||
patch() { | ||
# The meson scripts assume that clang is part of the LLVM suite, which is used when | ||
# enabling the jit build (which we do). | ||
# Unfortunately the is not always the case. We work around this by patching the build scripts: | ||
git -C "$PG_SRC_DIR" apply - <<EOF | ||
diff --git a/meson.build b/meson.build | ||
index 6804f941be..d62142c8f7 100644 | ||
--- a/meson.build | ||
+++ b/meson.build | ||
@@ -755,7 +755,7 @@ if add_languages('cpp', required: llvmopt, native: false) | ||
llvm_binpath = llvm.get_variable(configtool: 'bindir') | ||
ccache = find_program('ccache', native: true, required: false) | ||
- clang = find_program(llvm_binpath / 'clang', required: true) | ||
+ clang = find_program(llvm_binpath / 'clang', 'clang', required: true) | ||
endif | ||
elif llvmopt.auto() | ||
message('llvm requires a C++ compiler') | ||
EOF | ||
} | ||
|
||
configure() { | ||
echo "Configuring postgres build" | ||
|
||
patch | ||
|
||
meson setup "$PG_BUILD_DIR" "$PG_SRC_DIR" \ | ||
--debug \ | ||
-Dprefix=${PG_INSTALL_DIR} \ | ||
-Dbindir=${PG_INSTALL_DIR}/bin \ | ||
-Ddatadir=${PG_INSTALL_DIR}/share \ | ||
-Dincludedir=${PG_INSTALL_DIR}/include \ | ||
-Dlibdir=${PG_INSTALL_DIR}/lib \ | ||
-Dsysconfdir=${PG_INSTALL_DIR}/etc \ | ||
-Dplperl=auto \ | ||
-Dplpython=auto \ | ||
-Dssl=openssl \ | ||
-Dpam=auto \ | ||
-Dldap=auto \ | ||
-Dlibxml=enabled \ | ||
-Dlibxslt=enabled \ | ||
-Dllvm=auto \ | ||
-Duuid=none \ | ||
-Dzstd=auto \ | ||
-Dlz4=enabled \ | ||
-Dgssapi=auto \ | ||
-Dsystemd=auto \ | ||
-Dicu=auto \ | ||
-Dsystem_tzdata=/usr/share/zoneinfo | ||
} | ||
|
||
build() { | ||
echo "Building postgres" | ||
|
||
ninja -C "$PG_BUILD_DIR" | ||
} | ||
|
||
install() { | ||
echo "Installing postgres to $PG_INSTALL_DIR" | ||
|
||
mkdir -p ${PG_INSTALL_DIR} | ||
ninja -C ${PG_BUILD_DIR} install | ||
} | ||
|
||
# The first argument determines the function to run. If no argument is given we run all commands in order: | ||
|
||
if [ -z "$1" ]; then | ||
clone && configure && build && install | ||
exit 0 | ||
fi | ||
|
||
case $1 in | ||
clone) | ||
clone | ||
;; | ||
patch) | ||
patch | ||
;; | ||
configure) | ||
configure | ||
;; | ||
build) | ||
build | ||
;; | ||
install) | ||
install | ||
;; | ||
*) | ||
echo "Usage: $0 {clone|configure|build|install}" | ||
exit 1 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.