2025年9月25日: PostgreSQL 18 发布!

新的 pg_msvc_generator 工具可用

发布于 2021-08-24,作者 Julien Rouhaud
相关开源项目

您好!

我很高兴地宣布 pg_msvc_generator 版本 1.0.0 beta 发布。

pg_msvc_generator 是一个新工具,用于帮助扩展作者提供其扩展的 Windows 版本。它使用 Perl 编写,并采用 PostgreSQL 许可的开源软件。

您可以参考 项目的 README 获取完整描述,或者在遇到任何问题时访问 bug 跟踪器

此工具包含 2 个脚本

  • pg_msvc_generator.pl
  • release.pl

主要的 pg_msvc_generator.pl 脚本会在给定的扩展目录中生成一个 msvc 子目录,其中包含使用 Visual Studio 2019 编译扩展所需的 **.sln** 和 **.vcxproj** 文件,并支持 Debug/Release 和 32/64 位构建。它还将复制 release.pl 并生成 build.bat 脚本,该脚本可以自动编译并为所有本地安装的 PostgreSQL 版本创建发布归档文件和安装程序。

用法

pg_msvc_generator.pl [ options ]

Options:

--default version pgver  : default PostgreSQL version. This is only used
            if you compile the project without specifying a specific major
            version, or when the project is opened with Visual Studio
            IDE.  If not provided, a default value based on the year will
            be chosen (13 for 2021, 14 for 2022 and so on).
-d | --dir ext_directory : root directory of the extension source code.
-e | --extension         : extension name.  If not provided, the extension
            name will be assumed using the last part of the given root
            directory.
-h | --help              : Show this message.

例如

pg_msvc_generator.pl -d C:\git\hypopg

要求

生成项目时:

  • 已安装 Perl 的 Windows 主机,用于生成项目文件

编译扩展时:

  • Perl
  • Visual Studio 2019
  • 您希望为其构建扩展的所有主要 PostgreSQL 版本,从 PGDG 包安装到默认位置 (C:\Program Files\PostgreSQL\$MAJOR_VERSION)
  • 可选:在默认位置 (`C:\Program Files (x86)\NSIS) 安装 NSIS,用于生成安装程序

发布您的扩展

您只需要执行 msvc\release.bat 脚本。它将设置 MSVC 环境并调用 release.pl 脚本。该脚本将在 msvc\${extension_name}-${extension_version} 目录下为发布做好一切准备。

它将通过读取 HKLM/SOFTWARE/PostgreSQL/Installations/ 注册表自动查找已安装的 PostgreSQL 版本,使用所有这些版本编译扩展,并为每个版本生成一个包含 dll 和 SQL 脚本(如果存在)的子目录,一个具有相同内容的 zip 归档文件,以及可选的安装程序。

例如,假设您已安装 PostgreSQL 12 和 13,并发布了 HypoPG 1.3.2 和 NSIS,您的 msvc 目录现在将包含以下附加内容

  • msvc\hypopg-1.3.2\12-x64\lib\hypopg.dll
  • msvc\hypopg-1.3.2\12-x64\share\extension\hypopg.control
  • msvc\hypopg-1.3.2\12-x64\share\extension\*.sql
  • msvc\hypopg-1.3.2\13-x64\lib\hypopg.dll
  • msvc\hypopg-1.3.2\13-x64\share\extension\hypopg.control
  • msvc\hypopg-1.3.2\13-x64\share\extension\*.sql
  • msvc\hypopg-1.3.2\hypopg-1.3.2-pg12-x64.exe
  • msvc\hypopg-1.3.2\hypopg-1.3.2-pg12-x64.zip
  • msvc\hypopg-1.3.2\hypopg-1.3.2-pg13-x64.exe
  • msvc\hypopg-1.3.2\hypopg-1.3.2-pg13-x64.zip

安装程序

如果您已在默认位置 (C:\Program Files (x86)\NSIS) 安装 NSISrelease.pl 脚本将生成一个 .nsi 文件并使用 makensis.exe 编译它,为在运行 release.pl 脚本时找到的每个 PostgreSQL 主要版本生成一个特定的安装程序。在执行时,安装程序将尝试通过读取注册表项 HKEY_LOCAL_MACHINE\SOFTWARE\PostgreSQL\Installations\postgresql-$architecture-$majorversion\Base Directory 来发现服务器的 PostgreSQL 安装路径。

如果找到该注册表项,安装程序将通知用户并将其用作默认安装位置。否则,安装程序将通知用户未自动找到任何安装,并将强制用户在继续安装之前选择一个位置。