Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
ffi: Refactor to simpler API.
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
  • Loading branch information
ShogunPanda committed Apr 11, 2026
commit 1f02596069713cc981169b5fd7fd2518b3612042
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ endif
FFI_BINDING_GYPS := $(wildcard test/ffi/*/binding.gyp)

FFI_BINDING_SOURCES := \
$(wildcard test/ffi/*/*.c)
$(wildcard test/ffi/*/*.c) \
$(wildcard test/ffi/*/*.def)

# Implicitly depends on $(NODE_EXE), see the build-ffi-tests rule for rationale.
test/ffi/.buildstamp: $(ADDONS_PREREQS) \
Expand Down
63 changes: 58 additions & 5 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,28 @@
dest='shared_sqlite_libpath',
help='a directory to search for the shared sqlite DLL')

shared_optgroup.add_argument('--shared-ffi',
action='store_true',
dest='shared_ffi',
default=None,
help='link to a shared libffi DLL instead of static linking')

shared_optgroup.add_argument('--shared-ffi-includes',
action='store',
dest='shared_ffi_includes',
help='directory containing libffi header files')

shared_optgroup.add_argument('--shared-ffi-libname',
action='store',
dest='shared_ffi_libname',
default='ffi',
help='alternative libffi name to link to [default: %(default)s]')

shared_optgroup.add_argument('--shared-ffi-libpath',
action='store',
dest='shared_ffi_libpath',
help='a directory to search for the shared libffi DLL')

shared_optgroup.add_argument('--shared-temporal_capi',
action='store_true',
dest='shared_temporal_capi',
Expand Down Expand Up @@ -1017,11 +1039,11 @@
default=None,
help='build without SQLite (disables SQLite and Web Storage API)')

parser.add_argument('--with-ffi',
parser.add_argument('--without-ffi',
action='store_true',
dest='with_ffi',
dest='without_ffi',
default=None,
help='build with FFI (Foreign Function Interface) support')
help='build without FFI (Foreign Function Interface) support')

parser.add_argument('--experimental-quic',
action='store_true',
Expand Down Expand Up @@ -2190,9 +2212,40 @@ def without_sqlite_error(option):

configure_library('sqlite', o, pkgname='sqlite3')

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

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

return target_arch in supported.get(os_name, set())

def configure_ffi(o):
o['variables']['node_use_ffi'] = b(options.with_ffi)
return
use_ffi = not options.without_ffi

if use_ffi and not options.shared_ffi:
target_arch = o['variables']['target_arch']
if not bundled_ffi_supported(flavor, target_arch):
warn(f'FFI is disabled for {flavor}/{target_arch}: the bundled libffi '
'integration is not available on this platform. Use --shared-ffi '
'to provide a system libffi or --without-ffi to silence this '
'warning.')
use_ffi = False

o['variables']['node_use_ffi'] = b(use_ffi)

if options.without_ffi:
if options.shared_ffi:
error('--without-ffi is incompatible with --shared-ffi')
return

if not use_ffi:
return

configure_library('ffi', o, pkgname='libffi')

Expand Down
Loading