#!/bin/bash set -ex pg_version_num="`pg_config --version | cut -d' ' -f2 | tr -d . | cut -c-2`" pg_short_version=pg"$pg_version_num" output=src/"$pg_short_version".rs case "${1:-}" in --select-pg) echo "$pg_short_version" ; exit 0 ;; esac if ! which bindgen 2>/dev/null 1>/dev/null then echo 'Please install `bindgen` for Rust (`cargo install bindgen`)' >&2 echo 'and ensure it is on the PATH.' >&2 exit 2 fi # Bindgen doesn't work on OS X without this. xcode='/Applications/Xcode.app' xcode_libs='Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/' if [ -d "$xcode" ] then export DYLD_LIBRARY_PATH="$xcode/$xcode_libs":"$DYLD_LIBRARY_PATH" fi echo "Generating $output" >&2 mkdir -p tmp/ cat > tmp/pgheaders.h <<\EOF #include #include "postgres.h" #include "access/reloptions.h" #include "fmgr.h" #include "foreign/fdwapi.h" #include "foreign/foreign.h" #include "optimizer/pathnode.h" #include "optimizer/planmain.h" #include "optimizer/restrictinfo.h" #include "utils/builtins.h" #include "utils/json.h" #include "utils/lsyscache.h" #include "utils/rel.h" EOF [ "$pg_version_num" = "93" ] || \ cat >> tmp/pgheaders.h <<\EOF #include "replication/output_plugin.h" #include "replication/logical.h" EOF gcc -I "`pg_config --includedir-server`" -E tmp/pgheaders.h > tmp/pgexpanded.h bindgen --no-derive-debug --builtins tmp/pgexpanded.h -o "$output"