Skip to content

Commit

Permalink
libffi: Update to latest upstream PR version
Browse files Browse the repository at this point in the history
This uses meson port from libffi/libffi#746 as
of 2023-08-17.
  • Loading branch information
xclaesse authored and willwray committed Apr 22, 2024
1 parent 75486ac commit 6a668f9
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 70 deletions.
6 changes: 6 additions & 0 deletions ci_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@
"libpciaccess-dev"
]
},
"libffi": {
"_comment": "libffi has too many unit tests and it exceed command line limit to rebuild test targets",
"test_options": [
"--no-rebuild"
]
},
"libffmpegthumbnailer": {
"brew_packages": [
"ffmpeg@4"
Expand Down
1 change: 1 addition & 0 deletions releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,7 @@
"libffi"
],
"versions": [
"3.4.4-3",
"3.4.4-2",
"3.4.4-1"
]
Expand Down
2 changes: 1 addition & 1 deletion subprojects/packagefiles/libffi/include/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ configure_file(input : 'ffi.h.in',
configuration : ffi_h_conf,
install_dir : get_option('includedir'))

install_headers(f'../src/@targetdir@/ffitarget.h')
install_headers('../src' / targetdir / 'ffitarget.h')
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
res = subprocess.run(args, stdout=subprocess.PIPE, universal_newlines=True, check=True)

with open(outfile, 'r') as f:
if re.search('\.hidden.*foo', f.read()):
if re.search('(\.hidden|\.private_extern).*foo', f.read()):
sys.exit(0)
print('.hidden not found in the outputted assembly')
sys.exit(1)
102 changes: 61 additions & 41 deletions subprojects/packagefiles/libffi/meson.build
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
project('libffi', 'c', version : '3.4.4',
meson_version : '>= 0.64.0',
default_options : ['buildtype=debugoptimized',
meson_version : '>= 0.56.0',
default_options : ['debug=true',
'optimization=3',
'warning_level=1'])

fs = import('fs')

libtool_version = run_command('meson-scripts/extract-libtool-version.py',
meson.current_source_dir() / 'libtool-version',
check: true).stdout().split(':')
check: true).stdout().strip().split(':')
current = libtool_version[0].to_int()
revision = libtool_version[1].to_int()
age = libtool_version[2].to_int()
Expand All @@ -20,6 +21,7 @@ host_cpu_family = host_machine.cpu_family()
host_system = host_machine.system()

cc = meson.get_compiler('c')
is_msvc = cc.get_id() == 'msvc'
is_msvc_like = cc.get_argument_syntax() == 'msvc'
is_gnu_like = cc.get_argument_syntax() == 'gcc'

Expand Down Expand Up @@ -82,67 +84,72 @@ have_long_double_variant = false
if host_cpu_family == 'aarch64' and host_system in ['cygwin', 'windows']
target = 'ARM_WIN64'
targetdir = 'aarch64'
if is_msvc_like
if is_msvc
asm_sources = ['win64_armasm.S']
endif
elif host_cpu_family == 'aarch64'
target = 'AARCH64'
elif host_cpu_family.startswith('alpha')
elif host_cpu_family == 'alpha'
target = 'ALPHA'
asm_sources = ['osf.S']
# Support 128-bit long double, changeable via command-line switch.
have_long_double = 'defined(__LONG_DOUBLE_128__)'
elif host_cpu_family.startswith('arc')
elif host_cpu_family == 'arc'
target = 'ARC'
asm_sources = ['arcompact.S']
elif host_cpu_family == 'arm' and host_system in ['cygwin', 'windows']
target = 'ARM_WIN32'
targetdir = 'arm'
if is_msvc_like
if is_msvc
asm_sources = ['sysv_msvc_arm32.S']
endif
elif host_cpu_family == 'arm'
target = 'ARM'
elif host_cpu_family.startswith('avr32')
elif host_cpu_family == 'avr'
target = 'AVR32'
elif host_cpu_family.startswith('bfin')
elif host_cpu_family == 'bfin'
# FIXME: bfin family is missing in Meson
target = 'BFIN'
elif host_cpu_family == 'cris'
# FIXME: cris family is missing in Meson
target = 'LIBFFI_CRIS'
targetdir = 'cris'
elif host_cpu_family == 'csky'
target = 'CSKY'
elif host_cpu_family == 'frv'
# FIXME: frv family is missing in Meson
target = 'FRV'
asm_sources = ['eabi.S']
elif (host_cpu_family.startswith('hppa') and host_system in ['linux', 'openbsd']) or \
(host_cpu_family.startswith('parisc') and host_system == 'linux')
elif (host_cpu_family in ['hppa', 'hppa64'] and host_system in ['linux', 'openbsd']) or \
(host_cpu_family == 'parisc' and host_system == 'linux')
# FIXME: hppa family is missing in Meson
target = 'PA_LINUX'
targetdir = 'pa'
asm_sources = ['linux.S']
elif host_cpu_family.startswith('hppa') and not '64' in host_cpu_family and host_system in ['hpux']
elif host_cpu_family == 'hppa' and host_system in ['hpux']
# FIXME: hppa family is missing in Meson
target = 'PA_HPUX'
targetdir = 'pa'
asm_sources = ['hpux32.S']
elif host_cpu_family == 'x86' and host_system in ['freebsd', 'openbsd']
target = 'X86_FREEBSD'
targetdir = 'x86'
if is_msvc_like
if is_msvc
asm_sources = ['sysv_intel.S']
endif
elif (host_cpu_family == 'x86' and host_system in ['cygwin', 'windows', 'os2', 'interix']) or \
(host_cpu_family == 'x86_64' and host_system in ['cygwin', 'windows'])
targetdir = 'x86'
if size_t == 4
target = 'X86_WIN32'
if is_msvc_like
if is_msvc
asm_sources = ['sysv_intel.S']
masm_args += '/safeseh'
endif
else
target = 'X86_WIN64'
c_sources = ['ffiw64.c']
if is_msvc_like
if is_msvc
asm_sources = ['win64_intel.S']
else
asm_sources = ['win64.S']
Expand All @@ -152,7 +159,7 @@ elif host_cpu_family in ['x86', 'x86_64'] and host_system in ['darwin', 'ios']
targetdir = 'x86'
if size_t == 4
target = 'X86_DARWIN'
if is_msvc_like
if is_msvc
asm_sources = ['sysv_intel.S']
endif
else
Expand All @@ -169,7 +176,7 @@ elif host_cpu_family in ['x86', 'x86_64']
asm_sources = ['unix64.S', 'win64.S']
else
target = 'X86'
if is_msvc_like
if is_msvc
asm_sources = ['sysv_intel.S']
endif
endif
Expand All @@ -178,10 +185,11 @@ elif host_cpu_family in ['x86', 'x86_64']
c_sources = ['ffi64.c', 'ffiw64.c']
asm_sources = ['unix64.S', 'win64.S']
endif
elif host_cpu_family.startswith('ia64')
elif host_cpu_family == 'ia64'
target = 'IA64'
asm_sources = ['unix.S']
elif host_cpu_family == 'kvx'
# FIXME: kvx family is missing in Meson
target = 'KVX'
elif host_cpu_family == 'loongarch64'
target = 'LOONGARCH64'
Expand All @@ -190,76 +198,84 @@ elif host_cpu_family.startswith('m32r')
elif host_cpu_family == 'm68k'
target = 'M68K'
elif host_cpu_family == 'm88k'
# FIXME: m88k family is missing in Meson
target = 'M88K'
asm_sources = ['obsd.S']
elif host_cpu_family.startswith('microblaze')
elif host_cpu_family == 'microblaze'
target = 'MICROBLAZE'
elif host_cpu_family == 'moxie'
# This CPU family is used in CI cross compilation
target = 'MOXIE'
asm_sources = ['eabi.S']
elif host_cpu_family == 'metag'
# FIXME: metag family is missing in Meson
target = 'METAG'
elif host_cpu_family.startswith('mips') and \
elif host_cpu_family in ['mips', 'mips64'] and \
(host_system.startswith('irix5.') or host_system.startswith('irix6.') or host_system.startswith('rtems'))
target = 'MIPS'
asm_sources = ['o32.S', 'n32.S']
elif host_cpu_family.startswith('mips') and host_system in ['linux', 'openbsd', 'freebsd']
elif host_cpu_family in ['mips', 'mips64'] and host_system in ['linux', 'openbsd', 'freebsd']
target = 'MIPS'
asm_sources = ['o32.S', 'n32.S']
# Support 128-bit long double for NewABI.
have_long_double = 'defined(__mips64)'
elif host_cpu_family.startswith('nios2') and host_system == 'linux'
elif host_cpu_family == 'nios2' and host_system == 'linux'
# FIXME: nios2 family is missing in Meson
target = 'NIOS2'
elif host_cpu_family.startswith('or1k')
elif host_cpu_family == 'or1k'
# FIXME: or1k family is missing in Meson
target = 'OR1K'
elif (host_cpu_family.startswith('powerpc') and \
elif (host_cpu_family in ['ppc', 'ppc64'] and \
host_system in ['linux', 'sysv', 'amigaos', 'eabi', 'beos', 'rtems']) or \
(host_cpu_family in ['powerpc64', 'powerpc64le'] and host_system == 'freebsd')
(host_cpu_family == 'ppc64' and host_system == 'freebsd')
target = 'POWERPC'
c_sources = ['ffi.c', 'ffi_sysv.c', 'ffi_linux64.c']
asm_sources = ['sysv.S', 'ppc_closure.S', 'linux64.S', 'linux64_closure.S']
have_long_double_variant = true
elif host_cpu_family.startswith('powerpc') and host_system == 'darwin'
elif host_cpu_family in ['ppc', 'ppc64'] and host_system == 'darwin'
target = 'POWERPC_DARWIN'
targetdir = 'powerpc'
c_sources = ['ffi_darwin.c']
asm_sources = ['darwin.S', 'darwin_closure.S']
elif host_cpu_family in ['powerpc', 'rs6000'] and host_system in ['darwin', 'aix']
elif host_cpu_family in ['ppc', 'rs6000'] and host_system in ['darwin', 'aix']
target = 'POWERPC_AIX'
targetdir = 'powerpc'
c_sources = ['ffi_darwin.c']
asm_sources = ['aix.S aix_closure.S']
elif host_cpu_family == 'powerpc' and host_system in ['freebsd', 'openbsd', 'netbsd']
elif host_cpu_family == 'ppc' and host_system in ['freebsd', 'openbsd', 'netbsd']
target = 'POWERPC_FREEBSD'
targetdir = 'powerpc'
c_sources = ['ffi.c', 'ffi_sysv.c']
asm_sources = ['sysv.S', ' pc_closure.S']
have_long_double_variant = true
elif host_cpu_family == 'powerpcspe' and host_system == 'freebsd'
target = 'POWERPC_FREEBSD'
targetdir = 'powerpc'
c_sources = ['ffi.c', 'ffi_sysv.c']
asm_sources = ['sysv.S', ' pc_closure.S']
add_project_arguments('-D__NO_FPRS__', language: 'c')
elif host_cpu_family.startswith('riscv')
if cc.get_define('__SPE__') != ''
add_project_arguments('-D__NO_FPRS__', language: 'c')
else
have_long_double_variant = true
endif
elif host_cpu_family in ['riscv32', 'riscv64']
target = 'RISCV'
elif host_cpu_family.startswith('s390')
elif host_cpu_family in ['s390', 's390x']
target = 'S390'
elif host_cpu_family == 'sh64' or host_cpu_family.startswith('sh5')
# FIXME: Meson only has sh4 family
target = 'SH64'
elif host_cpu_family.startswith('sh')
# FIXME: Meson only has sh4 family
target = 'SH'
elif host_cpu_family.startswith('sparc')
elif host_cpu_family in ['sparc', 'sparc64']
target = 'SPARC'
c_sources = ['ffi.c', 'ffi64.c']
asm_sources = ['v8.S', 'v9.S']
elif host_cpu_family.startswith('tile')
elif host_cpu_family == 'tile'
# FIXME: tile family is missing in Meson
target = 'TILE'
asm_sources = ['tile.S']
elif host_cpu_family == 'vax'
# FIXME: vax family is missing in Meson
target = 'VAX'
asm_sources = ['elfbsd.S']
elif host_cpu_family.startswith('xtensa')
elif host_cpu_family == 'xtensa'
# FIXME: xtensa family is missing in Meson
target = 'XTENSA'
else
error('Unsupported pair: system "@0@", cpu family "@1@"'.format(host_system, host_cpu_family))
Expand Down Expand Up @@ -421,7 +437,11 @@ if get_option('doc')
endif

if get_option('tests')
subdir('testsuite')
if meson.version().version_compare('>=0.58.0')
subdir('testsuite')
else
error('Meson >= 0.58 is required for unit tests')
endif
endif

install_man([
Expand Down
65 changes: 49 additions & 16 deletions subprojects/packagefiles/libffi/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ endforeach

ffiinc = include_directories('..', '../include', targetdir)

if is_msvc_like
if is_msvc
# MSVC, cannot compile assembly files directly. They need to be preprocessed
# with the C compiler first, then compiled with MASM.
ffi_asm_sources = cc.preprocess(ffi_asm_sources,
output: '@BASENAME@.masm',
include_directories: ffiinc,
)
add_languages('masm', native: false)
if meson.version().version_compare('>=0.64.0')
ffi_asm_sources = cc.preprocess(ffi_asm_sources,
output: '@BASENAME@.masm',
include_directories: ffiinc,
)
add_languages('masm', native: false)
else
error('Meson >= 0.64 is required with MSVC')
endif
endif

ffi_link_args = []
Expand All @@ -39,13 +43,33 @@ ffi_map_file = []
if get_option('ffi-build-versioned')
libffi_map_in = meson.project_source_root() / 'libffi.map.in'
arg_prefix = '-Wl,--version-script='
if cc.has_link_argument(arg_prefix + libffi_map_in)
ffi_map_file = cc.preprocess(libffi_map_in,
output: '@BASENAME@',
include_directories: ffiinc,
compile_args: '-DGENERATE_LIBFFI_MAP',
)
ffi_link_args += arg_prefix + ffi_map_file[0].full_path()
if cc.has_multi_link_arguments(['-shared', arg_prefix + libffi_map_in])
if meson.version().version_compare('>=0.64.0')
ffi_map_file = cc.preprocess(libffi_map_in,
output: '@BASENAME@',
include_directories: ffiinc,
compile_args: '-DGENERATE_LIBFFI_MAP',
)
ffi_map_abs = ffi_map_file[0].full_path()
else
ffi_map_file = configure_file(
output: 'libffi.map',
command: [
meson.get_compiler('c'),
get_option('c_args'),
'-I' + join_paths(meson.current_build_dir(), '..'),
'-I' + join_paths(meson.current_build_dir(), '..', 'include'),
'-I' + join_paths(meson.current_source_dir(), targetdir),
'-DGENERATE_LIBFFI_MAP',
'-E', '-x', 'assembler-with-cpp',
join_paths(meson.current_source_dir(),'../libffi.map.in'),
'-o',
'@OUTPUT@'
],
)
ffi_map_abs = meson.current_build_dir() / 'libffi.map'
endif
ffi_link_args += arg_prefix + ffi_map_abs
endif
endif

Expand All @@ -54,16 +78,25 @@ if get_option('default_library') == 'static'
public_c_args += ['-DFFI_STATIC_BUILD']
endif

# masm_args is new in Meson 0.64, older versions fails when passing unknown
# keyword arguments. We only need it when using MSVC which already requires
# Meson >= 0.64 above, this tricks avoids passing it to older versions.
extra_kwargs = {}
if meson.version().version_compare('>=0.64.0')
extra_kwargs += {'masm_args': masm_args}
endif

ffi_lib = library('ffi', ffi_c_sources, ffi_asm_sources,
c_args : ['-DTARGET=' + target, '-DFFI_BUILDING_DLL', public_c_args],
masm_args : masm_args,
c_args : ['-DFFI_BUILDING_DLL', public_c_args],
include_directories : ffiinc,
link_args: ffi_link_args,
link_depends: ffi_map_file,
version : ffi_version,
soversion : ffi_soversion,
darwin_versions : ffi_darwin_versions,
install : true)
install : true,
kwargs: extra_kwargs,
)

pkgconf = import('pkgconfig')
pkgconf.generate(ffi_lib,
Expand Down

0 comments on commit 6a668f9

Please sign in to comment.