Skip to content
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
19 changes: 11 additions & 8 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2310,17 +2310,20 @@ def without_sqlite_error(option):
configure_library('sqlite', o, pkgname='sqlite3')

def bundled_ffi_supported(os_name, target_arch):
supported = {
'freebsd': {'arm', 'arm64', 'x64'},
'linux': {'arm', 'arm64', 'x64'},
'mac': {'arm64', 'x64'},
'win': {'arm64', 'x64'},
}

if target_arch == 'x86':
target_arch = 'ia32'

return target_arch in supported.get(os_name, set())
if target_arch in {'arm', 'arm64', 'ia32', 'x64', 'x86_64',
'riscv64', 'loong64'}:
return True

if target_arch in {'mips', 'mipsel', 'mips64el'}:
return os_name in {'freebsd', 'linux', 'openbsd'}

if target_arch == 'ppc64':
return os_name in {'aix', 'freebsd', 'linux', 'mac', 'openbsd'}

return False

def configure_ffi(o):
use_ffi = not options.without_ffi
Expand Down
102 changes: 68 additions & 34 deletions deps/libffi/generate-headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,63 @@
LIBFFI_VERSION = '3.5.2'
LIBFFI_VERSION_NUMBER = '30502'

TARGETS = {
('freebsd', 'arm'): ('ARM', 'arm'),
('freebsd', 'arm64'): ('AARCH64', 'aarch64'),
('freebsd', 'x64'): ('X86_64', 'x86'),
('linux', 'arm'): ('ARM', 'arm'),
('linux', 'arm64'): ('AARCH64', 'aarch64'),
('linux', 'x64'): ('X86_64', 'x86'),
('mac', 'arm64'): ('AARCH64', 'aarch64'),
('mac', 'x64'): ('X86_64', 'x86'),
('win', 'arm'): ('ARM_WIN32', 'arm'),
('win', 'arm64'): ('ARM_WIN64', 'aarch64'),
('win', 'x64'): ('X86_WIN64', 'x86'),
}
def normalize_arch(target_arch):
aliases = {
'x86': 'ia32',
'x86_64': 'x64',
'arm64': 'arm64',
'aarch64': 'arm64',
}
return aliases.get(target_arch, target_arch)


def get_target(os_name, target_arch):
try:
return TARGETS[(os_name, target_arch)]
except KeyError as exc:
supported = ', '.join(
f'{os_name}/{arch}' for os_name, arch in sorted(TARGETS))
raise ValueError(
f'Unsupported libffi target {os_name}/{target_arch}. '
f'Supported targets: {supported}.') from exc
target_arch = normalize_arch(target_arch)

if target_arch == 'arm':
return ('ARM_WIN32' if os_name == 'win' else 'ARM', 'arm')

if target_arch == 'arm64':
return ('ARM_WIN64' if os_name == 'win' else 'AARCH64', 'aarch64')

if target_arch == 'ia32':
if os_name in ('freebsd', 'openbsd'):
return ('X86_FREEBSD', 'x86')
if os_name in ('ios', 'mac'):
return ('X86_DARWIN', 'x86')
if os_name == 'win':
return ('X86_WIN32', 'x86')
return ('X86', 'x86')

if target_arch == 'x64':
return ('X86_WIN64' if os_name == 'win' else 'X86_64', 'x86')

if target_arch == 'riscv64':
return ('RISCV', 'riscv')

if target_arch == 'loong64':
return ('LOONGARCH64', 'loongarch64')

if target_arch in ('mips', 'mipsel', 'mips64el'):
if os_name in ('freebsd', 'linux', 'openbsd'):
return ('MIPS', 'mips')

if target_arch == 'ppc64':
if os_name == 'aix':
return ('POWERPC_AIX', 'powerpc')
if os_name == 'mac':
return ('POWERPC_DARWIN', 'powerpc')
if os_name in ('freebsd', 'openbsd'):
return ('POWERPC_FREEBSD', 'powerpc')
if os_name == 'linux':
return ('POWERPC', 'powerpc')

raise ValueError(f'Unsupported libffi target {os_name}/{target_arch}.')


def has_long_double(os_name, target_arch):
target_arch = normalize_arch(target_arch)

if os_name == 'win':
return '0'

Expand All @@ -50,6 +80,7 @@ def has_long_double(os_name, target_arch):


def uses_exec_trampoline_table(os_name, target_arch):
target_arch = normalize_arch(target_arch)
return os_name == 'mac' and target_arch in ('arm', 'arm64')


Expand All @@ -72,6 +103,7 @@ def render_ffi_header(base_dir, os_name, target_arch, target):


def render_fficonfig(os_name, target_arch):
target_arch = normalize_arch(target_arch)
lines = [
'/* Auto-generated by generate-headers.py. */',
'#ifndef LIBFFI_FFICONFIG_H_',
Expand All @@ -94,15 +126,15 @@ def render_fficonfig(os_name, target_arch):
'#define EH_FRAME_FLAGS "a"',
])

if target_arch in ('x64', 'x86') and os_name != 'win':
if target_arch in ('ia32', 'x64') and os_name != 'win':
lines.append('#define HAVE_AS_X86_PCREL 1')

if uses_exec_trampoline_table(os_name, target_arch):
lines.append('#define FFI_EXEC_TRAMPOLINE_TABLE 1')
elif os_name in ('freebsd', 'mac'):
elif os_name in ('freebsd', 'mac', 'openbsd'):
lines.append('#define FFI_MMAP_EXEC_WRIT 1')

if os_name == 'linux':
if os_name != 'win':
lines.extend([
'#define HAVE_DLFCN_H 1',
'#define HAVE_MMAP 1',
Expand All @@ -111,15 +143,10 @@ def render_fficonfig(os_name, target_arch):
'#define HAVE_SYS_MMAN_H 1',
'#define HAVE_UNISTD_H 1',
])
elif os_name in ('freebsd', 'mac'):

if os_name in ('freebsd', 'ios', 'mac', 'openbsd'):
lines.extend([
'#define HAVE_DLFCN_H 1',
'#define HAVE_MMAP 1',
'#define HAVE_MMAP_ANON 1',
'#define HAVE_MMAP_DEV_ZERO 1',
'#define HAVE_MMAP_FILE 1',
'#define HAVE_SYS_MMAN_H 1',
'#define HAVE_UNISTD_H 1',
])

if os_name == 'mac' and target_arch == 'arm64':
Expand Down Expand Up @@ -204,12 +231,19 @@ def detect_target_arch():
'x86_64': 'x64',
'x64': 'x64',
'win32': 'x64',
'i386': 'x86',
'i686': 'x86',
'x86': 'x86',
'i386': 'ia32',
'i686': 'ia32',
'ia32': 'ia32',
'x86': 'ia32',
'arm64': 'arm64',
'aarch64': 'arm64',
'arm': 'arm',
'riscv64': 'riscv64',
'loong64': 'loong64',
'ppc64': 'ppc64',
'mips': 'mips',
'mipsel': 'mipsel',
'mips64el': 'mips64el',
}

for candidate in candidates:
Expand Down
Loading
Loading