Skip to content

Commit 2a21844

Browse files
committed
feat: add PG Meson introspect targets
Extend the `pg_build()` rule to generate additional Meson introspection targets on top of the regular Postgres build. These targets invoke the [Meson `introspect` command] to emit JSON metadata about the configuration of the build. This metadata is useful for analyzing or programmatically extracting parts of the Postgres build, such as contrib extensions. NOTE: Bump `rules_foreign_cc` to v0.15.0 which is where [PR#1385] is included ("feat: meson additional targets"). [Meson `introspect` command]: https://mesonbuild.com/Commands.html#introspect [PR#1385]: bazel-contrib/rules_foreign_cc#1385
1 parent 6bb7f77 commit 2a21844

File tree

3 files changed

+61
-29
lines changed

3 files changed

+61
-29
lines changed

build/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module(
1010
bazel_dep(name = "download_archives", version = "0.1.0")
1111
bazel_dep(name = "rules_bison", version = "0.4")
1212
bazel_dep(name = "rules_flex", version = "0.4")
13-
bazel_dep(name = "rules_foreign_cc", version = "0.14.0")
13+
bazel_dep(name = "rules_foreign_cc", version = "0.15.0")
1414
bazel_dep(name = "rules_m4", version = "0.3")
1515
bazel_dep(name = "rules_python", version = "1.0.0")
1616
bazel_dep(name = "version_utils", version = "0.1.0")

build/examples/postgres/test.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ def build_test(name):
1111
def build_all_test(name, cfg):
1212
for target in cfg.targets:
1313
build_test(target.name)
14+
name_introspect = "%s--introspect" % target.name
15+
build_test(name_introspect)

build/postgres/pg_build.bzl

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,38 +95,16 @@ def _meson_common_args(pg_src, build_options, auto_features):
9595
env = env | env_meson,
9696
lib_source = pg_src,
9797
options = build_options | meson_tool_options,
98-
setup_args = [
99-
"--auto-features=%s" % auto_features,
100-
],
98+
target_args = {
99+
"setup": [
100+
"--auto-features=%s" % auto_features,
101+
],
102+
},
101103
toolchains = toolchains,
102104
visibility = ["//visibility:public"],
103105
)
104106

105-
def pg_build(name, pg_src, build_options, auto_features):
106-
"""
107-
Generates a Bazel target to build Postgres with the Meson build system.
108-
109-
This rule configures the environment and invokes the rules_foreign_cc
110-
`meson` rule, using preconfigured options, toolchains, etc.
111-
112-
Args:
113-
name (str): The name of the Bazel target to generate.
114-
pg_src (str): The external Bazel repo with the Postgres source code.
115-
build_options (dict): Meson build options that configure optional
116-
Postgres features and other compilation parameters. For the full
117-
list of available options, see [PostgreSQL
118-
Features](https://www.postgresql.org/docs/current/install-meson.html#MESON-OPTIONS-FEATURES)
119-
and
120-
[`meson_options.txt`](https://github.com/postgres/postgres/blob/master/meson_options.txt).
121-
auto_features (str): Controls whether Meson build options and optional
122-
Postgres features not specified in `build_options` will be
123-
`enable`d, `disable`d or `auto` (enabled or disabled based on
124-
detected system capabilities). For more details, see the official
125-
documentation for [Postgres
126-
`--auto-features`](https://www.postgresql.org/docs/current/install-meson.html#CONFIGURE-AUTO-FEATURES-MESON)
127-
and [Meson Build Options
128-
"Features"](https://mesonbuild.com/Build-options.html#features).
129-
"""
107+
def _pg_build_meson(name, pg_src, build_options, auto_features):
130108
pg_binaries = [
131109
"initdb",
132110
"postgres",
@@ -165,6 +143,58 @@ def pg_build(name, pg_src, build_options, auto_features):
165143
output_group = "Meson_logs",
166144
)
167145

146+
def _pg_build_introspect(name, pg_src, build_options, auto_features):
147+
meson_common_args = _meson_common_args(
148+
pg_src = pg_src,
149+
build_options = build_options,
150+
auto_features = auto_features,
151+
)
152+
153+
introspect_target_name = "{}--introspect".format(name)
154+
155+
meson(**(meson_common_args | dict(
156+
name = introspect_target_name,
157+
out_include_dir = "",
158+
out_data_files = ["{}.json".format(name)],
159+
targets = ["introspect"],
160+
tags = ["manual"],
161+
)))
162+
163+
native.filegroup(
164+
name = "{}--logs".format(introspect_target_name),
165+
srcs = [introspect_target_name],
166+
output_group = "Meson_logs",
167+
tags = ["manual"],
168+
)
169+
170+
def pg_build(name, pg_src, build_options, auto_features):
171+
"""
172+
Generates a Bazel target to build Postgres with the Meson build system.
173+
174+
This rule configures the environment and invokes the rules_foreign_cc
175+
`meson` rule, using preconfigured options, toolchains, etc.
176+
177+
Args:
178+
name (str): The name of the Bazel target to generate.
179+
pg_src (str): The external Bazel repo with the Postgres source code.
180+
build_options (dict): Meson build options that configure optional
181+
Postgres features and other compilation parameters. For the full
182+
list of available options, see [PostgreSQL
183+
Features](https://www.postgresql.org/docs/current/install-meson.html#MESON-OPTIONS-FEATURES)
184+
and
185+
[`meson_options.txt`](https://github.com/postgres/postgres/blob/master/meson_options.txt).
186+
auto_features (str): Controls whether Meson build options and optional
187+
Postgres features not specified in `build_options` will be
188+
`enable`d, `disable`d or `auto` (enabled or disabled based on
189+
detected system capabilities). For more details, see the official
190+
documentation for [Postgres
191+
`--auto-features`](https://www.postgresql.org/docs/current/install-meson.html#CONFIGURE-AUTO-FEATURES-MESON)
192+
and [Meson Build Options
193+
"Features"](https://mesonbuild.com/Build-options.html#features).
194+
"""
195+
_pg_build_meson(name, pg_src, build_options, auto_features)
196+
_pg_build_introspect(name, pg_src, build_options, auto_features)
197+
168198
def pg_build_all(name, cfg):
169199
"""
170200
Defines Bazel targets for building all configured Postgres versions.

0 commit comments

Comments
 (0)