diff --git a/librz/util/meson.build b/librz/util/meson.build index eccbfa7f1fa..f7a9ca31704 100644 --- a/librz/util/meson.build +++ b/librz/util/meson.build @@ -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 diff --git a/meson.build b/meson.build index a55a9e0b50e..c9f7c75b9da 100644 --- a/meson.build +++ b/meson.build @@ -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 diff --git a/subprojects/packagefiles/pcre2_cross_native/meson.build b/subprojects/packagefiles/pcre2_cross_native/meson.build new file mode 100644 index 00000000000..9e8dc206423 --- /dev/null +++ b/subprojects/packagefiles/pcre2_cross_native/meson.build @@ -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, +) diff --git a/subprojects/pcre2_cross_native.wrap b/subprojects/pcre2_cross_native.wrap new file mode 100644 index 00000000000..d77f572ecaa --- /dev/null +++ b/subprojects/pcre2_cross_native.wrap @@ -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