Skip to content

Commit 01d6832

Browse files
committed
meson: add and use stamp files for generated headers
Without using stamp files, meson lists the generated headers as the dependency for every .c file, bloating build.ninja by more than 2x. Processing all the dependencies also increases the time to generate build.ninja. The immediate benefit is that this makes re-configuring and clean builds a bit faster. The main motivation however is that I have other patches that introduce additional build targets that further would increase the size of build.ninja, making re-configuring more noticeably slower. Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com> Discussion: https://postgr.es/m/cgkdgvzdpinkacf4v33mky7tbmk467oda5dd4dlmucjjockxzi@xkqfvjoq4uiy
1 parent 71ea0d6 commit 01d6832

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

meson.build

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,6 +3133,8 @@ gen_export_kwargs = {
31333133
'install': false,
31343134
}
31353135

3136+
# command to create stamp files on all OSs
3137+
stamp_cmd = [python, '-c', 'import sys; open(sys.argv[1], "w")', '@OUTPUT0@']
31363138

31373139

31383140
###
@@ -3250,14 +3252,14 @@ subdir('src/port')
32503252
frontend_common_code = declare_dependency(
32513253
compile_args: ['-DFRONTEND'],
32523254
include_directories: [postgres_inc],
3253-
sources: generated_headers,
3255+
sources: generated_headers_stamp,
32543256
dependencies: [os_deps, zlib, zstd, lz4],
32553257
)
32563258

32573259
backend_common_code = declare_dependency(
32583260
compile_args: ['-DBUILDING_DLL'],
32593261
include_directories: [postgres_inc],
3260-
sources: generated_headers,
3262+
sources: generated_headers_stamp,
32613263
dependencies: [os_deps, zlib, zstd],
32623264
)
32633265

@@ -3272,15 +3274,15 @@ shlib_code = declare_dependency(
32723274
frontend_stlib_code = declare_dependency(
32733275
include_directories: [postgres_inc],
32743276
link_with: [common_static, pgport_static],
3275-
sources: generated_headers,
3277+
sources: generated_headers_stamp,
32763278
dependencies: [os_deps, libintl],
32773279
)
32783280

32793281
# all shared libraries not part of the backend should depend on this
32803282
frontend_shlib_code = declare_dependency(
32813283
include_directories: [postgres_inc],
32823284
link_with: [common_shlib, pgport_shlib],
3283-
sources: generated_headers,
3285+
sources: generated_headers_stamp,
32843286
dependencies: [shlib_code, os_deps, libintl],
32853287
)
32863288

@@ -3290,7 +3292,7 @@ frontend_shlib_code = declare_dependency(
32903292
frontend_no_fe_utils_code = declare_dependency(
32913293
include_directories: [postgres_inc],
32923294
link_with: [common_static, pgport_static],
3293-
sources: generated_headers,
3295+
sources: generated_headers_stamp,
32943296
dependencies: [os_deps, libintl],
32953297
)
32963298

@@ -3317,7 +3319,7 @@ subdir('src/interfaces/libpq-oauth')
33173319
frontend_code = declare_dependency(
33183320
include_directories: [postgres_inc],
33193321
link_with: [fe_utils, common_static, pgport_static],
3320-
sources: generated_headers,
3322+
sources: generated_headers_stamp,
33213323
dependencies: [os_deps, libintl],
33223324
)
33233325

@@ -3347,7 +3349,7 @@ backend_code = declare_dependency(
33473349
include_directories: [postgres_inc],
33483350
link_args: ldflags_be,
33493351
link_with: [],
3350-
sources: generated_headers + generated_backend_headers,
3352+
sources: generated_backend_headers_stamp,
33513353
dependencies: os_deps + backend_both_deps + backend_deps,
33523354
)
33533355

src/backend/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ backend_mod_code = declare_dependency(
169169
compile_args: pg_mod_c_args,
170170
include_directories: postgres_inc,
171171
link_args: pg_mod_link_args,
172-
sources: generated_headers + generated_backend_headers,
172+
sources: generated_backend_headers_stamp,
173173
dependencies: backend_mod_deps,
174174
)
175175

src/fe_utils/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ generated_sources += psqlscan
2929
fe_utils_sources += psqlscan
3030

3131
fe_utils = static_library('libpgfeutils',
32-
fe_utils_sources + generated_headers,
32+
fe_utils_sources,
3333
c_pch: pch_postgres_fe_h,
3434
include_directories: [postgres_inc, libpq_inc],
3535
c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [],

src/include/meson.build

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,24 @@ install_subdir('catalog',
177177

178178
# autoconf generates the file there, ensure we get a conflict
179179
generated_sources_ac += {'src/include': ['stamp-h']}
180+
181+
182+
# Instead of having targets depending directly on a list of all generated
183+
# headers, have them depend on a stamp files for all of them. Dependencies on
184+
# headers are implemented as order-only dependencies in meson (and then using
185+
# compiler generated dependencies during incremental rebuilds ). The benefit
186+
# of using a stamp file is that it makes ninja.build considerably smaller and
187+
# meson setup faster, as otherwise the list of headers is repeated for every C
188+
# file, bloating build.ninja by ~2x.
189+
generated_headers_stamp = custom_target('generated-headers-stamp.h',
190+
output: 'generated-headers-stamp.h',
191+
input: generated_headers,
192+
command: stamp_cmd,
193+
)
194+
195+
generated_backend_headers_stamp = custom_target('generated-backend-headers-stamp.h',
196+
output: 'generated-backend-headers-stamp.h',
197+
input: generated_backend_headers,
198+
depends: generated_headers_stamp,
199+
command: stamp_cmd,
200+
)

0 commit comments

Comments
 (0)