安装Zig环境
请参考 在 Linux 上安装 Zig 编译环境。
编译 PostgreSQL
下载 PostgreSQL 源码
通过 Github 下载源码,切换到目标标签
git clone https://github.com/postgres/postgres.git
cd postgres
git checkout REL_14_STABLE
sudo yum -y install readline-devel
使用 Zig 编译
执行如下命令:
export CC="zig cc" CXX="zig c++"
./configure
make -j
# zig cc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -Wno-deprecated-non-prototype -Wno-format-truncation -Wno-stringop-truncation -O2 zic.o -L../../src/port -L../../src/common -Wl,--as-needed -Wl,-rpath,'/usr/local/pgsql/lib',--enable-new-dtags -lpgcommon -lpgport -lz -lreadline -lm -o zic
# error: unsupported linker arg: --enable-new-dtags
# make[2]: *** [zic] Error 1
# make[2]: Leaving directory `/data/postgres/src/timezone'
# make[1]: *** [all-timezone-recurse] Error 2
# make[1]: Leaving directory `/data/postgres/src'
# make: *** [all-src-recurse] Error 2
注意点:目前 Zig 最新版本不支持
--enable-new-dtags
这个连接器参数,不过在 Zig 最新代码中已经解决了,故可选择编码安装最新 Zig 。