Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5bdd0cf

Browse files
committed
meson: Add basic PGXS compatibility
Generate a Makefile.global that's complete enough for PGXS to work for some extensions. It is likely that this compatibility layer will not suffice for every extension and not all platforms - we can expand it over time. This allows extensions to use a single buildsystem across all the supported postgres versions. Once all supported PG versions support meson, we can remove the compatibility layer. Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Discussion: https://postgr.es/m/20221005200710.luvw5evhwf6clig6@awork3.anarazel.de
1 parent 9db49fc commit 5bdd0cf

File tree

6 files changed

+311
-11
lines changed

6 files changed

+311
-11
lines changed

meson.build

+2-6
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,6 @@ program_zstd = find_program(get_option('ZSTD'), native: true, required: false)
337337
dtrace = find_program(get_option('DTRACE'), native: true, required: get_option('dtrace'))
338338
missing = find_program('config/missing', native: true)
339339

340-
# used by PGXS
341-
install_sh = find_program('config/install-sh', native: true)
342-
343340
bison_flags = []
344341
if bison.found()
345342
bison_version_c = run_command(bison, '--version', check: true)
@@ -1741,11 +1738,10 @@ endif
17411738

17421739
# A few places with imported code get a pass on -Wdeclaration-after-statement, remember
17431740
# the result for them
1741+
cflags_no_decl_after_statement = []
17441742
if cc.has_argument('-Wdeclaration-after-statement')
17451743
cflags_warn += '-Wdeclaration-after-statement'
1746-
using_declaration_after_statement_warning = true
1747-
else
1748-
using_declaration_after_statement_warning = false
1744+
cflags_no_decl_after_statement += '-Wno-declaration-after-statement'
17491745
endif
17501746

17511747

meson_options.txt

+3
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ option('PYTHON', type : 'array', value: ['python3', 'python'],
172172
option('SED', type : 'string', value: 'gsed',
173173
description: 'path to sed binary')
174174

175+
option('STRIP', type : 'string', value: 'strip',
176+
description: 'path to strip binary, used for PGXS emulation')
177+
175178
option('TAR', type : 'string', value: 'tar',
176179
description: 'path to tar binary')
177180

src/common/meson.build

+1-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ ryu_sources = files(
6464
)
6565
ryu_cflags = []
6666

67-
if using_declaration_after_statement_warning
68-
ryu_cflags += ['-Wno-declaration-after-statement']
69-
endif
67+
ryu_cflags += cflags_no_decl_after_statement
7068

7169
config_info_sources = files('config_info.c',)
7270
config_info_cflags = [

src/include/meson.build

+8-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,14 @@ else
4949
var_cxxflags = ''
5050
endif
5151
var_cppflags = ' '.join(cppflags)
52-
var_cflags_sl = '-fPIC' #FIXME
53-
var_ldflags = ' '.join(ldflags + get_option('c_link_args'))
52+
var_cflags_sl = ' '.join(cc.get_supported_arguments('-fPIC'))
53+
# explicitly add -Wl,--as-needed, normally added by meson, but we want it for
54+
# PGXS compatibility
55+
var_ldflags = ' '.join(
56+
ldflags
57+
+ cc.get_supported_link_arguments('-Wl,--as-needed')
58+
+ get_option('c_link_args')
59+
)
5460
var_ldflags_sl = ''.join(ldflags_sl)
5561
var_ldflags_ex = '' # FIXME
5662
# FIXME - some extensions might directly use symbols from one of libs. If

src/makefiles/meson.build

+260
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
### Compute pgxs_data, used in src/meson.build to generate Makefile.global
2+
### etc, that's complete enough for PGXS to work.
3+
4+
5+
# Emulation of PGAC_CHECK_STRIP
6+
strip_bin = find_program(get_option('STRIP'), required: false, native: true)
7+
strip_cmd = strip_bin.found() ? [strip_bin.path()] : [':']
8+
9+
working_strip = false
10+
if strip_bin.found()
11+
strip_version = run_command(strip_bin, '-V', check: false)
12+
13+
if strip_version.returncode() == 0 and (
14+
strip_version.stdout().contains('GNU strip') or
15+
strip_version.stderr().contains('GNU strip'))
16+
working_strip = true
17+
strip_static_cmd = strip_cmd + ['-x']
18+
strip_shared_cmd = strip_cmd + ['--strip-unneeded']
19+
elif host_system == 'darwin'
20+
working_strip = true
21+
strip_static_cmd = strip_cmd + ['-x']
22+
strip_shared_cmd = strip_cmd + ['-x']
23+
endif
24+
endif
25+
26+
if not working_strip
27+
strip_cmd = [':']
28+
strip_static_cmd = [':']
29+
strip_shared_cmd = [':']
30+
endif
31+
32+
33+
pgxs_kv = {
34+
'PACKAGE_URL': pg_url,
35+
'PACKAGE_VERSION': pg_version,
36+
'PG_MAJORVERSION': pg_version_major,
37+
'PG_VERSION_NUM': pg_version_num,
38+
'configure_input': 'meson',
39+
40+
'vpath_build': 'yes',
41+
'autodepend': cc.get_argument_syntax() == 'gcc' ? 'yes' : 'no',
42+
43+
'host_cpu': host_cpu,
44+
'host': '@0@-@1@'.format(host_cpu, host_system),
45+
'host_os': host_system,
46+
'build_os': build_machine.system(),
47+
'PORTNAME': portname,
48+
'PG_SYSROOT': pg_sysroot,
49+
50+
'abs_top_builddir': meson.build_root(),
51+
'abs_top_srcdir': meson.source_root(),
52+
53+
'enable_thread_safety': 'yes',
54+
'enable_rpath': 'yes',
55+
'enable_nls': libintl.found() ? 'yes' : 'no',
56+
'enable_tap_tests': tap_tests_enabled ? 'yes' : 'no',
57+
'enable_debug': get_option('debug') ? 'yes' : 'no',
58+
'enable_coverage': 'no',
59+
'enable_dtrace': dtrace.found() ? 'yes' : 'no',
60+
61+
'DLSUFFIX': dlsuffix,
62+
'EXEEXT': exesuffix,
63+
64+
'SUN_STUDIO_CC': 'no', # not supported so far
65+
66+
# want the chosen option, rather than the library
67+
'with_ssl' : get_option('ssl'),
68+
'with_uuid': uuidopt,
69+
70+
'default_port': get_option('pgport'),
71+
'with_system_tzdata': get_option('system_tzdata'),
72+
73+
'with_krb_srvnam': get_option('krb_srvnam'),
74+
'krb_srvtab': krb_srvtab,
75+
76+
'STRIP': ' '.join(strip_cmd),
77+
'STRIP_STATIC_LIB': ' '.join(strip_static_cmd),
78+
'STRIP_SHARED_LIB': ' '.join(strip_shared_cmd),
79+
80+
# these seem to be standard these days
81+
'MKDIR_P': 'mkdir -p',
82+
'LN_S': 'ln -s',
83+
# Just always use the install_sh fallback that autoconf uses. Unlikely to
84+
# matter performance-wise for extensions. If it turns out to do, we can
85+
'install_bin': '$(SHELL) $(top_srcdir)/config/install-sh -c',
86+
87+
'CC': var_cc,
88+
'CPP': var_cpp,
89+
'GCC': cc.get_argument_syntax() == 'gcc' ? 'yes' : 'no',
90+
91+
'CPPFLAGS': var_cppflags,
92+
'CFLAGS': var_cflags,
93+
'CXXFLAGS': var_cxxflags,
94+
'CFLAGS_SL': var_cflags_sl,
95+
'CFLAGS_SL_MODULE': ' '.join(cflags_mod),
96+
'CXXFLAGS_SL_MODULE': ' '.join(cxxflags_mod),
97+
'PERMIT_DECLARATION_AFTER_STATEMENT':
98+
' '.join(cflags_no_decl_after_statement),
99+
100+
'CFLAGS_CRC': ' '.join(cflags_crc),
101+
'CFLAGS_UNROLL_LOOPS': ' '.join(unroll_loops_cflags),
102+
'CFLAGS_VECTORIZE': ' '.join(vectorize_cflags),
103+
104+
'LDFLAGS': var_ldflags,
105+
'LDFLAGS_EX': var_ldflags_ex,
106+
'LDFLAGS_EX_BE':
107+
' '.join(cc.get_supported_link_arguments('-Wl,--export-dynamic')),
108+
'LDFLAGS_SL': var_ldflags_sl,
109+
110+
# TODO: requires bitcode generation to be implemented for meson
111+
'BITCODE_CFLAGS': '',
112+
'BITCODE_CXXFLAGS': '',
113+
114+
'BISONFLAGS': ' '.join(bison_flags),
115+
'FLEXFLAGS': ' '.join(flex_flags),
116+
117+
'LIBS': var_libs,
118+
}
119+
120+
if llvm.found()
121+
pgxs_kv += {
122+
'CLANG': clang.path(),
123+
'CXX': ' '.join(cpp.cmd_array()),
124+
'LLVM_BINPATH': llvm_binpath,
125+
}
126+
else
127+
pgxs_kv += {
128+
'CLANG': '',
129+
'CXX': '',
130+
'LLVM_BINPATH': '',
131+
}
132+
endif
133+
134+
pgxs_bins = {
135+
'AR':
136+
find_program(['ar'], native: true, required: false),
137+
'AWK':
138+
find_program(['gawk', 'mawk', 'nawk', 'awk'], native: true, required: false),
139+
'BISON': bison,
140+
'FLEX': flex,
141+
'GZIP': gzip,
142+
'LZ4': program_lz4,
143+
'OPENSSL': openssl,
144+
'PERL': perl,
145+
'PROVE': prove,
146+
'PYTHON': python,
147+
'TAR': tar,
148+
'ZSTD': program_zstd,
149+
'DTRACE': dtrace,
150+
}
151+
152+
pgxs_empty = [
153+
'ICU_CFLAGS', # needs to be added, included by public server headers
154+
155+
# hard to see why we'd need either?
156+
'ZIC',
157+
'TCLSH',
158+
159+
# docs don't seem to be supported by pgxs
160+
'XMLLINT',
161+
'XSLTPROC',
162+
'DBTOEPUB',
163+
'FOP',
164+
165+
# supporting coverage for pgxs-in-meson build doesn't seem worth it
166+
'GENHTML',
167+
'LCOV',
168+
'GCOV',
169+
'MSGFMT_FLAGS',
170+
171+
# translation doesn't appear to be supported by pgxs
172+
'MSGFMT',
173+
'XGETTEXT',
174+
'MSGMERGE',
175+
'WANTED_LANGUAGES',
176+
177+
# Not needed because we don't build the server / PLs with the generated makefile
178+
'LIBOBJS', 'PG_CRC32C_OBJS', 'TAS',
179+
'DTRACEFLAGS', # only server has dtrace probes
180+
181+
'perl_archlibexp', 'perl_embed_ccflags', 'perl_embed_ldflags', 'perl_includespec', 'perl_privlibexp',
182+
'python_additional_libs', 'python_includespec', 'python_libdir', 'python_libspec', 'python_majorversion', 'python_version',
183+
184+
# possible that some of these are referenced explicitly in pgxs makefiles?
185+
# For now not worth it.
186+
'TCL_INCLUDE_SPEC', 'TCL_LIBS', 'TCL_LIB_SPEC', 'TCL_SHARED_BUILD',
187+
188+
'LLVM_CFLAGS', 'LLVM_CPPFLAGS', 'LLVM_CXXFLAGS', 'LLVM_LIBS',
189+
190+
'LDAP_LIBS_BE', 'LDAP_LIBS_FE',
191+
192+
'UUID_LIBS',
193+
194+
'PTHREAD_CFLAGS', 'PTHREAD_LIBS',
195+
196+
'ICU_LIBS',
197+
]
198+
199+
if host_system == 'windows' and cc.get_argument_syntax() != 'msvc'
200+
pgxs_bins += {'WINDRES': windres}
201+
else
202+
pgxs_empty += 'WINDRES'
203+
endif
204+
205+
pgxs_dirs = {
206+
'prefix': get_option('prefix'),
207+
208+
'bindir': '${exec_prefix}' / get_option('bindir'),
209+
'datarootdir': '${prefix}' / get_option('datadir'),
210+
'datadir': '${datarootdir}',
211+
'docdir': '${prefix}' / dir_doc,
212+
'exec_prefix': '${prefix}',
213+
'htmldir': '${docdir}',
214+
'includedir': '${prefix}' / get_option('includedir'),
215+
'libdir': '${exec_prefix}' / get_option('libdir'),
216+
'localedir': '${prefix}' / get_option('localedir'),
217+
'mandir': '${prefix}' / get_option('mandir'),
218+
'sysconfdir': '${prefix}' / get_option('sysconfdir'),
219+
}
220+
221+
pgxs_deps = {
222+
'bonjour': bonjour,
223+
'bsd_auth': bsd_auth,
224+
'gssapi': gssapi,
225+
'icu': icu,
226+
'ldap': ldap,
227+
'libxml': libxml,
228+
'libxslt': libxslt,
229+
'llvm': llvm,
230+
'lz4': lz4,
231+
'nls': libintl,
232+
'pam': pam,
233+
'perl': perl_dep,
234+
'python': python3_dep,
235+
'readline': readline,
236+
'selinux': selinux,
237+
'systemd': systemd,
238+
'tcl': tcl_dep,
239+
'zlib': zlib,
240+
'zstd': zstd,
241+
}
242+
243+
244+
pgxs_cdata = configuration_data(pgxs_kv)
245+
246+
foreach b, p : pgxs_bins
247+
pgxs_cdata.set(b, p.found() ? p.path() : '')
248+
endforeach
249+
250+
foreach pe : pgxs_empty
251+
pgxs_cdata.set(pe, '')
252+
endforeach
253+
254+
foreach d, p : pgxs_dirs
255+
pgxs_cdata.set(d, p)
256+
endforeach
257+
258+
foreach d, v : pgxs_deps
259+
pgxs_cdata.set('with_@0@'.format(d), v.found() ? 'yes' : 'no')
260+
endforeach

src/meson.build

+37
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,40 @@ subdir('bin')
1010
subdir('pl')
1111

1212
subdir('interfaces')
13+
14+
15+
### Generate a Makefile.global that's complete enough for PGXS to work.
16+
#
17+
# This is somewhat ugly, but allows extensions to use a single buildsystem
18+
# across all the supported postgres versions. Once all supported PG versions
19+
# support meson, we can remove all of this.
20+
#
21+
# XXX: Should we make this optional?
22+
23+
# pgxs_cdata is built in makefiles/meson.build, but some of the generated
24+
# files are output into src/
25+
subdir('makefiles')
26+
27+
makefile_global = configure_file(
28+
input: 'Makefile.global.in',
29+
output: 'Makefile.global',
30+
configuration: pgxs_cdata,
31+
install: true,
32+
install_dir: dir_pgxs / 'src',
33+
)
34+
configure_files += makefile_global
35+
36+
makefile_port = configure_file(
37+
input: 'makefiles' / 'Makefile.@0@'.format(portname),
38+
output: 'Makefile.port',
39+
copy: true,
40+
install_dir: dir_pgxs / 'src')
41+
configure_files += makefile_port
42+
43+
install_data(
44+
'Makefile.shlib', 'nls-global.mk',
45+
install_dir: dir_pgxs / 'src')
46+
47+
install_data(
48+
'makefiles/pgxs.mk',
49+
install_dir: dir_pgxs / 'src' / 'makefiles')

0 commit comments

Comments
 (0)