Skip to content

Commit

Permalink
Fix cross build - add copy of PCRE2 dependecy
Browse files Browse the repository at this point in the history
Meson currently doesn't support subprojects to be native and non-native at the same time.
See: mesonbuild/meson#10947
Unfortunately, sdb depends on rz_util which in turn depends on PCRE2.
Excluding PCRE2 from the native build makes linking of rz_util not possible anymore.
Adding it, will make Meson complain that the dependencies cannot be mixed.

Hence, we compile a copy of PCRE2 for the native build if required.
  • Loading branch information
Rot127 committed Feb 5, 2024
1 parent e9d3720 commit 4ecb0fd
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 3 deletions.
2 changes: 1 addition & 1 deletion librz/util/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ if meson.is_cross_build()
cc_native.find_library('psapi'),
]
endif
rz_util_native_deps = [ldl_native, lrt_native, mth_native, th_native, utl_native, pcre2_dep] + platform_native_deps
rz_util_native_deps = [ldl_native, lrt_native, mth_native, th_native, utl_native, pcre2_native_dep] + platform_native_deps
if execinfo_native.found()
rz_util_native_deps += [execinfo_native]
endif
Expand Down
8 changes: 6 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,17 @@ endif

pcre2_dep_opt = get_option('use_sys_pcre2')
pcre2_dep = disabler()
if pcre2_dep_opt.enabled() or pcre2_dep_opt.auto()
if (pcre2_dep_opt.enabled() or pcre2_dep_opt.auto()) and not meson.is_cross_build()
pcre2_dep = dependency('libpcre2-8', required: false, static: true)
if not pcre2_dep.found()
pcre2_dep = cc.find_library('pcre2', required: true, static: true)
endif
else
pcre2_dep = dependency('pcre2', 'pcre2_dep', version: '>=10.42', required: true, static: true)
pcre2_dep = dependency('pcre2', version: '>=10.42', required: true, static: true)
endif

if meson.is_cross_build()
pcre2_native_dep = dependency('pcre2_cross_native', required: true, static: true, native: true)
endif

# handle magic library
Expand Down
90 changes: 90 additions & 0 deletions subprojects/packagefiles/pcre2_cross_native/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copy of PCRE2 library for the native version if a cross build happens.
# Because Meson currently doesn't support subprojects to be native and non-native:
# https://github.com/mesonbuild/meson/issues/10947

project('pcre2_cross_native', 'c', version: '10.42')

cc = meson.get_compiler('c')

conf_data = configuration_data()

pcre2_chartables = configure_file(input : 'src/pcre2_chartables.c.dist',
output : 'pcre2_chartables.c',
configuration : conf_data)

pcre2_h = configure_file(input : 'src/pcre2.h.generic',
output : 'pcre2.h',
configuration : conf_data)

config_h = configure_file(input : 'src/config.h.generic',
output : 'config.h',
configuration : conf_data)

libpcre2_c_args = [
'-DHAVE_CONFIG_H', # Default values from config.h
'-DPCRE2_CODE_UNIT_WIDTH=8',
'-DHAVE_MEMMOVE',
'-DSUPPORT_PCRE2_8',
'-DSUPPORT_UNICODE',
'-fvisibility=default',
]

pcre2_files = [
'src/pcre2_auto_possess.c',
pcre2_chartables,
'src/pcre2_compile.c',
'src/pcre2_config.c',
'src/pcre2_context.c',
'src/pcre2_convert.c',
'src/pcre2_dfa_match.c',
'src/pcre2_error.c',
'src/pcre2_extuni.c',
'src/pcre2_find_bracket.c',
'src/pcre2_maketables.c',
'src/pcre2_match.c',
'src/pcre2_match_data.c',
'src/pcre2_newline.c',
'src/pcre2_ord2utf.c',
'src/pcre2_pattern_info.c',
'src/pcre2_script_run.c',
'src/pcre2_serialize.c',
'src/pcre2_string_utils.c',
'src/pcre2_study.c',
'src/pcre2_substitute.c',
'src/pcre2_substring.c',
'src/pcre2_tables.c',
'src/pcre2_ucd.c',
'src/pcre2_valid_utf.c',
'src/pcre2_xclass.c',
]

cpu_jit_supported = [ 'aarch64', 'arm', 'mips', 'mips64', 'ppc', 'ppc64', 'riscv32', 'riscv64', 's390x', 'x86', 'x86_64' ]

# tcc doesn't support the MSVC asm syntax PCRE2 uses (`__asm { ... }`).
# It is used in the JIT compiler code.
if cc.get_id() != 'tcc' and target_machine.cpu_family() in cpu_jit_supported
libpcre2_c_args += ['-DSUPPORT_JIT']
pcre2_files += ['src/pcre2_jit_compile.c']
endif

if target_machine.system() == 'openbsd' or target_machine.system() == 'netbsd'
# jit compilation fails with "no more memory" if wx allocations are allowed.
libpcre2_c_args += ['-DSLJIT_WX_EXECUTABLE_ALLOCATOR']
endif

pcre2_includes = [
include_directories('.'),
include_directories('src/'),
]

libpcre2_cross_native = static_library('pcre2_cross_native', pcre2_files,
c_args: libpcre2_c_args,
include_directories: pcre2_includes,
install: false,
native: true,
)

pcre2_cross_native_dep = declare_dependency(
link_with: libpcre2_cross_native,
include_directories: pcre2_includes,
)
9 changes: 9 additions & 0 deletions subprojects/pcre2_cross_native.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[wrap-git]
url = https://github.com/PCRE2Project/pcre2.git
revision = 52c08847921a324c804cabf2814549f50bce1265
directory = pcre2_cross_native
patch_directory = pcre2_cross_native

[provide]
dependency_names = pcre2_cross_native
pcre2_cross_native = pcre2_cross_native_dep

0 comments on commit 4ecb0fd

Please sign in to comment.