Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meson: test extensions build by pkg-conf #72

Open
wants to merge 14 commits into
base: meson
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
486 changes: 411 additions & 75 deletions .cirrus.yml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions contrib/citext/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ tests += {
],
},
}

bitcode_modules += {
'target': citext,
'srcfiles': citext_sources,
}
113 changes: 90 additions & 23 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ portname = host_system

exesuffix = '' # overridden below where necessary
dlsuffix = '.so' # overridden below where necessary
rpath_origin = '$ORIGIN'
library_path_var = 'LD_LIBRARY_PATH'

# Format of file to control exports from libraries, and how to pass them to
Expand Down Expand Up @@ -222,6 +223,7 @@ elif host_system == 'cygwin'
elif host_system == 'darwin'
dlsuffix = '.dylib'
library_path_var = 'DYLD_LIBRARY_PATH'
rpath_origin = '@loader_path'

export_file_format = 'darwin'
export_fmt = '-exported_symbols_list=@0@'
Expand Down Expand Up @@ -260,8 +262,16 @@ elif host_system == 'netbsd'
# LDFLAGS.
ldflags += ['-Wl,-z,now', '-Wl,-z,relro']

# netbsd patched their meson in a broken way:
# https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=56959
# until there's a way out of that, disable rpath_origin
rpath_origin = ''

elif host_system == 'openbsd'
# you're ok
# openbsd's $ORIGIN doesn't use an absolute path to the binary, but argv[0]
# (i.e. absolute when invoked with an absolute name, but e.g. not absolute
# when invoked via PATH search).
rpath_origin = ''

elif host_system == 'sunos'
portname = 'solaris'
Expand All @@ -273,6 +283,7 @@ elif host_system == 'windows'
exesuffix = '.exe'
dlsuffix = '.dll'
library_path_var = ''
rpath_origin = ''

export_file_format = 'win'
export_file_suffix = 'def'
Expand Down Expand Up @@ -758,6 +769,8 @@ if not llvmopt.disabled()

ccache = find_program('ccache', native: true, required: false)
clang = find_program(llvm_binpath / 'clang', required: true)
llvm_lto = find_program(llvm_binpath / 'llvm-lto', required: true)
irlink = find_program('src/tools/irlink', native: true)
endif
else
llvm = not_found_dep
Expand Down Expand Up @@ -2598,6 +2611,10 @@ nls_targets = []
test_deps = []
tests = []

# List of object files + source files to generated LLVM IR for inlining.
# Each element is a hash of {'target': target, 'srcfiles': ...}.
bitcode_modules = []


# Default options for targets

Expand All @@ -2606,25 +2623,41 @@ bin_install_rpaths = []
lib_install_rpaths = []
mod_install_rpaths = []


# Don't add rpaths on darwin for now - as long as only absolute references to
# libraries are needed, absolute LC_ID_DYLIB ensures libraries can be found in
# their final destination.
# Add extra_lib_dirs to rpath. This ensures we find libraries we depend on.
#
# Not needed on darwin, even if we use relative rpaths for our own libraries,
# as the install_name of libraries in extra_lib_dirs will point to their
# location anyway.
if host_system != 'darwin'
bin_install_rpaths += postgres_lib_d
lib_install_rpaths += postgres_lib_d
mod_install_rpaths += postgres_lib_d
endif

# If the host can form relative rpaths, use that to make the installation
# properly relocatable
if rpath_origin != ''
# PG binaries might need to link to libpq, use relative path to reference
bin_to_lib = run_command(python, files('src/tools/relpath.py'),
dir_bin, dir_lib, check: true).stdout().strip()
bin_install_rpaths += rpath_origin / bin_to_lib

# PG extensions might need to link to libpq, use relative path to reference
# (often just .)
mod_to_lib = run_command(python, files('src/tools/relpath.py'),
dir_lib_pkg, dir_lib, check: true).stdout().strip()
mod_install_rpaths += rpath_origin / mod_to_lib

test_use_library_path_var = false
else

# Add absolute path to libdir to rpath. This ensures installed binaries /
# libraries find our libraries (mainly libpq).
bin_install_rpaths += dir_prefix / dir_lib
lib_install_rpaths += dir_prefix / dir_lib
mod_install_rpaths += dir_prefix / dir_lib

# Add extra_lib_dirs to rpath. This ensures we find libraries we depend on.
#
# Not needed on darwin even if we use relative rpaths for our own libraries,
# as the install_name of libraries in extra_lib_dirs will point to their
# location anyway.
bin_install_rpaths += postgres_lib_d
lib_install_rpaths += postgres_lib_d
mod_install_rpaths += postgres_lib_d
test_use_library_path_var = true
endif


Expand Down Expand Up @@ -2679,6 +2712,8 @@ gen_export_kwargs = {
'install': false,
}

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


###
Expand Down Expand Up @@ -2782,14 +2817,14 @@ subdir('src/port')
frontend_common_code = declare_dependency(
compile_args: ['-DFRONTEND'],
include_directories: [postgres_inc],
sources: generated_headers,
sources: generated_headers_stamp,
dependencies: [os_deps, zlib, zstd],
)

backend_common_code = declare_dependency(
compile_args: ['-DBUILDING_DLL'],
include_directories: [postgres_inc],
sources: generated_headers,
sources: generated_headers_stamp,
dependencies: [os_deps, zlib, zstd],
)

Expand All @@ -2804,15 +2839,15 @@ shlib_code = declare_dependency(
frontend_stlib_code = declare_dependency(
include_directories: [postgres_inc],
link_with: [common_static, pgport_static],
sources: generated_headers,
sources: generated_headers_stamp,
dependencies: [os_deps, libintl],
)

# all shared libraries not part of the backend should depend on this
frontend_shlib_code = declare_dependency(
include_directories: [postgres_inc],
link_with: [common_shlib, pgport_shlib],
sources: generated_headers,
sources: generated_headers_stamp,
dependencies: [shlib_code, os_deps, libintl],
)

Expand All @@ -2834,7 +2869,7 @@ subdir('src/fe_utils')
frontend_code = declare_dependency(
include_directories: [postgres_inc],
link_with: [fe_utils, common_static, pgport_static],
sources: generated_headers,
sources: generated_headers_stamp,
dependencies: [os_deps, libintl],
)

Expand Down Expand Up @@ -2862,7 +2897,7 @@ backend_code = declare_dependency(
include_directories: [postgres_inc],
link_args: ldflags_be,
link_with: [],
sources: generated_headers + generated_backend_headers,
sources: [generated_backend_headers_stamp],
dependencies: os_deps + backend_both_deps + backend_deps,
)

Expand All @@ -2888,6 +2923,11 @@ subdir('src/interfaces/ecpg/test')

subdir('doc/src/sgml')

# generate bitcode for JIT inlining after giving contrib modules etc a chance
# to add themselves to bitcode_modules[]
subdir('src/backend/jit/llvm/bitcode', if_found: llvm)


generated_sources_ac += {'': ['GNUmakefile']}

# After processing src/test, add test_install_libs to the testprep_targets
Expand Down Expand Up @@ -2948,6 +2988,14 @@ above, or by running configure and then make maintainer-clean.
endif


# To make MacOS installation work without a prior make install, even with SIP
# enabled, make rpaths relative after installation. This also makes the
# installation relocatable.
if host_system == 'darwin'
meson.add_install_script('src/tools/relativize_shared_library_references')
endif



###############################################################
# Install targets
Expand Down Expand Up @@ -3054,6 +3102,26 @@ test('install_test_files',

test_result_dir = meson.build_root() / 'testrun'

# it seems freebsd doesn't use libdir for pkgconfig path
if host_system == 'freebsd'
pkgconf_installdir = dir_prefix / 'libdata' / 'pkgconfig'
else
pkgconf_installdir = dir_prefix / dir_lib / 'pkgconfig'
endif
test_pkg_conf_file = files('src/tools/ci/test_pkg_conf')
test('pkg_conf_extensions',
test_pkg_conf_file,
args: [
'--meson', meson_bin.path(),
'--meson_args', meson_args,
'--rootdir', meson.source_root(),
'--pkgconf_installdir', pkgconf_installdir,
'--builddir', meson.build_root(),
'--pkg_conf_path', get_option('pkg_config_path'),
'--',
cc.cmd_array(),
],)


# XXX: pg_regress doesn't assign unique ports on windows. To avoid the
# inevitable conflicts from running tests in parallel, hackishly assign
Expand All @@ -3072,10 +3140,9 @@ test_env.set('REGRESS_SHLIB', regress_module.full_path())
# Export PG_TEST_EXTRA so it can be checked in individual tap tests.
test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))

# Add the temporary installation to the library search path on platforms where
# that works (everything but windows, basically). On windows everything
# library-like gets installed into bindir, solving that issue.
if library_path_var != ''
# On platforms without $ORIGIN support we need to add the temporary
# installation to the library search path.
if test_use_library_path_var and library_path_var != ''
test_env.prepend(library_path_var, test_install_location / get_option('libdir'))
endif

Expand Down
40 changes: 40 additions & 0 deletions src/backend/jit/llvm/bitcode/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2022-2023, PostgreSQL Global Development Group
#
# emit LLVM bitcode for JIT inlining

assert(llvm.found())

foreach bitcode_module : bitcode_modules
bitcode_targets = []
bitcode_obj = bitcode_module['target']
if 'name' not in bitcode_module
bitcode_name = bitcode_obj.name()
else
bitcode_name = bitcode_module['name']
endif

foreach srcfile : bitcode_module['srcfiles']
srcfilename = '@0@'.format(srcfile)
targetname = '@0@_@1@_@[email protected]'.format(
bitcode_name,
fs.parent(srcfilename).underscorify(), fs.name(srcfilename))
bitcode_targets += custom_target(
targetname,
input: [srcfile, bitcode_obj.extract_objects(srcfile)],
output: targetname,
command: [llvm_irgen_command, bitcode_cflags],
install: true,
install_dir: dir_bitcode,
)
endforeach

index_name = '@[email protected]'.format(bitcode_name)
bitcode_index = custom_target('@0@'.format(bitcode_name),
output: index_name,
input: bitcode_targets,
command: [irlink, '--lto', llvm_lto, '--outdir', '@OUTDIR@', '--index', index_name, '@INPUT@'],
install: true,
install_dir: dir_bitcode,
)
backend_targets += bitcode_index
endforeach
29 changes: 18 additions & 11 deletions src/backend/jit/llvm/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,20 @@ backend_targets += llvmjit

# Define a few bits and pieces used here and elsewhere to generate bitcode

llvm_irgen_args = [
'-c', '-o', '@OUTPUT@', '@INPUT@',
llvm_irgen_command = []
if ccache.found()
llvm_irgen_command += ccache
endif

llvm_irgen_command += [
clang,
'-c', '-o', '@OUTPUT0@', '@INPUT0@',
'-flto=thin', '-emit-llvm',
'-MD', '-MQ', '@OUTPUT@', '-MF', '@DEPFILE@',
'-O2',
'-Wno-ignored-attributes',
'-Wno-empty-body',
]

if ccache.found()
llvm_irgen_command = ccache
llvm_irgen_args = [clang.path()] + llvm_irgen_args
else
llvm_irgen_command = clang
endif
llvm_irgen_dep_args = ['-MD', '-MQ', '@OUTPUT0@', '-MF', '@DEPFILE@']


# XXX: Need to determine proper version of the function cflags for clang
Expand All @@ -74,7 +73,7 @@ bitcode_cflags += '-I@SOURCE_ROOT@/src/include'
# Note this is intentionally not installed to bitcodedir, as it's not for
# inlining
llvmjit_types = custom_target('llvmjit_types.bc',
command: [llvm_irgen_command] + llvm_irgen_args + bitcode_cflags,
command: llvm_irgen_command + llvm_irgen_dep_args + bitcode_cflags,
input: 'llvmjit_types.c',
output: 'llvmjit_types.bc',
depends: [postgres],
Expand All @@ -83,3 +82,11 @@ llvmjit_types = custom_target('llvmjit_types.bc',
depfile: '@[email protected]',
)
backend_targets += llvmjit_types

# Figure out -I's needed to build all postgres code, including all its
# dependencies
pkg_config = find_program(['pkg-config', 'pkgconf'], required: true)
r = run_command(pkg_config,
['--cflags-only-I', meson.build_root() / 'meson-uninstalled/postgresql-extension-uninstalled.pc'],
check: true)
bitcode_cflags += r.stdout().split()
Loading