diff --git a/README.md b/README.md index 437bcdb..458c207 100644 --- a/README.md +++ b/README.md @@ -138,13 +138,16 @@ Available bazel flags are: * `--@postgres_config//:with_gssapi`: bool (default false) * `--@postgres_config//:with_krb_srvnam`: string (default postgres) * `--@postgres_config//:with_libcurl`: bool (default false) -* `--@postgres_config//:with_lz4`: bool (default false) +* `--@postgres_config//:lz4_lib`: label (default `@lz4//:lz4_frame`) +* `--@postgres_config//:with_lz4`: bool (default true) * `--@postgres_config//:with_pgport`: int (default 5432) * `--@postgres_config//:with_readline`: bool (default false) * `--@postgres_config//:with_segsize`: int (default 1) * `--@postgres_config//:with_ssl`: One of `openssl` (default), `boringssl`, or `none` * `--@postgres_config//:with_wal_blocksize`: int (default 8). One of 2^{0..6}. -* `--@postgres_config//:with_zlib`: bool (default false) -* `--@postgres_config//:with_zstd`: bool (default false) +* `--@postgres_config//:with_zlib`: bool (default true) +* `--@postgres_config//:with_zstd`: bool (default true) +* `--@postgres_config//:zlib_lib`: label (default `@zlib//:zlib`) +* `--@postgres_config//:zstd_lib`: label (default `@zstd//:zstd`) `pg_config.h` comes from a real `rules_cc_autoconf` probe of upstream's `pg_config.h.in`, not a hand-maintained header. See the `:autoconf_probes` target in each postgres version's root. diff --git a/postgres_bazel/config/BUILD.bazel.template b/postgres_bazel/config/BUILD.bazel.template index 2336b72..80fa9c0 100644 --- a/postgres_bazel/config/BUILD.bazel.template +++ b/postgres_bazel/config/BUILD.bazel.template @@ -92,17 +92,33 @@ cc_library( bool_flag( name = "with_zlib", - build_setting_default = False, + build_setting_default = True, +) + +label_flag( + name = "zlib_lib", + build_setting_default = "@zlib//:zlib", ) bool_flag( name = "with_lz4", - build_setting_default = False, + build_setting_default = True, +) + +# Postgres uses the LZ4 frame API, which BCR's lz4 splits out of `:lz4`. +label_flag( + name = "lz4_lib", + build_setting_default = "@lz4//:lz4_frame", ) bool_flag( name = "with_zstd", - build_setting_default = False, + build_setting_default = True, +) + +label_flag( + name = "zstd_lib", + build_setting_default = "@zstd//:zstd", ) bool_flag( diff --git a/postgres_bazel/templates/major/16/BUILD.bazel b/postgres_bazel/templates/major/16/BUILD.bazel index b861c6c..3bb18f8 100644 --- a/postgres_bazel/templates/major/16/BUILD.bazel +++ b/postgres_bazel/templates/major/16/BUILD.bazel @@ -37,6 +37,21 @@ PG_VERSION_NUM = "{version_num}" # repository's BUILD file for the full list. # --------------------------------------------------------------------------- +_ZLIB_DEPS = select({ + "@postgres_config//:zlib_on": ["@postgres_config//:zlib_lib"], + "//conditions:default": [], +}) + +_LZ4_DEPS = select({ + "@postgres_config//:lz4_on": ["@postgres_config//:lz4_lib"], + "//conditions:default": [], +}) + +_ZSTD_DEPS = select({ + "@postgres_config//:zstd_on": ["@postgres_config//:zstd_lib"], + "//conditions:default": [], +}) + # Compiler-aware config_setting_groups so the autoconf rule below can emit # different defines on MSVC than on GCC/Clang. MSVC doesn't grok # `__int128`, GCC's `gnu_printf` format attribute, or x86_64 inline-asm @@ -1394,7 +1409,7 @@ cc_library( # controldata_utils.c computes the control-file CRC. ":pgport_crc32c", ":ssl_backend", - ], + ] + _ZLIB_DEPS + _ZSTD_DEPS, ) cc_library( @@ -1598,7 +1613,7 @@ cc_library( ":include", ":pgport_srv", ":ssl_backend", - ], + ] + _ZLIB_DEPS + _ZSTD_DEPS, ) # Sources that are #included into another .c rather than compiled on their @@ -1680,7 +1695,7 @@ cc_library( ] + select({ "@postgres_config//:gssapi_on": ["@postgres_config//:gssapi_lib"], "//conditions:default": [], - }), + }) + _LZ4_DEPS + _ZLIB_DEPS + _ZSTD_DEPS, ) # localtime.c/pgtz.c/strftime.c, linked into the backend and (localtime.c @@ -1855,7 +1870,7 @@ cc_library( ], hdrs = glob(["src/bin/pg_dump/*.h"]), local_defines = _FRONTEND_DEFINES, - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZLIB_DEPS + _ZSTD_DEPS, ) cc_binary( @@ -1899,7 +1914,7 @@ cc_library( ], hdrs = glob(["src/bin/pg_basebackup/*.h"]), local_defines = _FRONTEND_DEFINES, - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZLIB_DEPS + _ZSTD_DEPS, ) [ @@ -1932,7 +1947,7 @@ cc_binary( ] + glob(["src/bin/pg_rewind/*.h"]), local_defines = _FRONTEND_DEFINES, visibility = ["//visibility:public"], - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZSTD_DEPS, ) cc_binary( @@ -1984,7 +1999,7 @@ cc_binary( ]), local_defines = _FRONTEND_DEFINES, visibility = ["//visibility:public"], - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZSTD_DEPS, ) cc_binary( diff --git a/postgres_bazel/templates/major/17/BUILD.bazel b/postgres_bazel/templates/major/17/BUILD.bazel index 4260555..794bc21 100644 --- a/postgres_bazel/templates/major/17/BUILD.bazel +++ b/postgres_bazel/templates/major/17/BUILD.bazel @@ -37,6 +37,21 @@ PG_VERSION_NUM = "{version_num}" # repository's BUILD file for the full list. # --------------------------------------------------------------------------- +_ZLIB_DEPS = select({ + "@postgres_config//:zlib_on": ["@postgres_config//:zlib_lib"], + "//conditions:default": [], +}) + +_LZ4_DEPS = select({ + "@postgres_config//:lz4_on": ["@postgres_config//:lz4_lib"], + "//conditions:default": [], +}) + +_ZSTD_DEPS = select({ + "@postgres_config//:zstd_on": ["@postgres_config//:zstd_lib"], + "//conditions:default": [], +}) + # Compiler-aware config_setting_groups so the autoconf rule below can emit # different defines on MSVC than on GCC/Clang. MSVC doesn't grok # `__int128`, GCC's `gnu_printf` format attribute, or x86_64 inline-asm @@ -1402,7 +1417,7 @@ cc_library( # controldata_utils.c computes the control-file CRC. ":pgport_crc32c", ":ssl_backend", - ], + ] + _ZLIB_DEPS + _ZSTD_DEPS, ) cc_library( @@ -1606,7 +1621,7 @@ cc_library( ":include", ":pgport_srv", ":ssl_backend", - ], + ] + _ZLIB_DEPS + _ZSTD_DEPS, ) # Sources that are #included into another .c rather than compiled on their @@ -1692,7 +1707,7 @@ cc_library( ] + select({ "@postgres_config//:gssapi_on": ["@postgres_config//:gssapi_lib"], "//conditions:default": [], - }), + }) + _LZ4_DEPS + _ZLIB_DEPS + _ZSTD_DEPS, ) # localtime.c/pgtz.c/strftime.c, linked into the backend and (localtime.c @@ -1892,7 +1907,7 @@ cc_library( ], hdrs = glob(["src/bin/pg_dump/*.h"]), local_defines = _FRONTEND_DEFINES, - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZLIB_DEPS + _ZSTD_DEPS, ) cc_binary( @@ -1936,7 +1951,7 @@ cc_library( ], hdrs = glob(["src/bin/pg_basebackup/*.h"]), local_defines = _FRONTEND_DEFINES, - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZLIB_DEPS + _ZSTD_DEPS, ) [ @@ -1969,7 +1984,7 @@ cc_binary( ] + glob(["src/bin/pg_rewind/*.h"]), local_defines = _FRONTEND_DEFINES, visibility = ["//visibility:public"], - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZSTD_DEPS, ) cc_binary( @@ -2018,7 +2033,7 @@ cc_binary( ]), local_defines = _FRONTEND_DEFINES, visibility = ["//visibility:public"], - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZSTD_DEPS, ) cc_binary( diff --git a/postgres_bazel/templates/major/18/BUILD.bazel b/postgres_bazel/templates/major/18/BUILD.bazel index c77cdad..34ab715 100644 --- a/postgres_bazel/templates/major/18/BUILD.bazel +++ b/postgres_bazel/templates/major/18/BUILD.bazel @@ -37,6 +37,21 @@ PG_VERSION_NUM = "{version_num}" # repository's BUILD file for the full list. # --------------------------------------------------------------------------- +_ZLIB_DEPS = select({ + "@postgres_config//:zlib_on": ["@postgres_config//:zlib_lib"], + "//conditions:default": [], +}) + +_LZ4_DEPS = select({ + "@postgres_config//:lz4_on": ["@postgres_config//:lz4_lib"], + "//conditions:default": [], +}) + +_ZSTD_DEPS = select({ + "@postgres_config//:zstd_on": ["@postgres_config//:zstd_lib"], + "//conditions:default": [], +}) + # Compiler-aware config_setting_groups so the autoconf rule below can emit # different defines on MSVC than on GCC/Clang. MSVC doesn't grok # `__int128`, GCC's `gnu_printf` format attribute, or x86_64 inline-asm @@ -1375,7 +1390,7 @@ cc_library( # controldata_utils.c computes the control-file CRC. ":pgport_crc32c", ":ssl_backend", - ], + ] + _ZLIB_DEPS + _ZSTD_DEPS, ) cc_library( @@ -1409,7 +1424,7 @@ cc_library( ":pgcommon_tools", ":pgport", ":pq", - ], + ] + _LZ4_DEPS + _ZLIB_DEPS + _ZSTD_DEPS, ) cc_binary( @@ -1568,7 +1583,7 @@ cc_library( ":include", ":pgport_srv", ":ssl_backend", - ], + ] + _ZLIB_DEPS + _ZSTD_DEPS, ) # Sources that are #included into another .c rather than compiled on their @@ -1649,7 +1664,7 @@ cc_library( ] + select({ "@postgres_config//:gssapi_on": ["@postgres_config//:gssapi_lib"], "//conditions:default": [], - }), + }) + _LZ4_DEPS + _ZLIB_DEPS + _ZSTD_DEPS, ) # localtime.c/pgtz.c/strftime.c, linked into the backend and (localtime.c @@ -1850,7 +1865,7 @@ cc_library( ], hdrs = glob(["src/bin/pg_dump/*.h"]), local_defines = _FRONTEND_DEFINES, - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZLIB_DEPS + _ZSTD_DEPS, ) cc_binary( @@ -1889,7 +1904,7 @@ cc_library( ], hdrs = glob(["src/bin/pg_basebackup/*.h"]), local_defines = _FRONTEND_DEFINES, - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZLIB_DEPS + _ZSTD_DEPS, ) [ @@ -1922,7 +1937,7 @@ cc_binary( ] + glob(["src/bin/pg_rewind/*.h"]), local_defines = _FRONTEND_DEFINES, visibility = ["//visibility:public"], - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZSTD_DEPS, ) cc_binary( @@ -1975,7 +1990,7 @@ cc_binary( ]), local_defines = _FRONTEND_DEFINES, visibility = ["//visibility:public"], - deps = _FRONTEND_DEPS, + deps = _FRONTEND_DEPS + _LZ4_DEPS + _ZSTD_DEPS, ) cc_binary(