Skip to content

Commit 91d97f7

Browse files
ShogunPandacjihrig
authored andcommitted
ffi: Refactor to simpler API.
Signed-off-by: Paolo Insogna <[email protected]>
1 parent 631d73a commit 91d97f7

47 files changed

Lines changed: 3764 additions & 5225 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,8 @@ endif
545545
FFI_BINDING_GYPS := $(wildcard test/ffi/*/binding.gyp)
546546

547547
FFI_BINDING_SOURCES := \
548-
$(wildcard test/ffi/*/*.c)
548+
$(wildcard test/ffi/*/*.c) \
549+
$(wildcard test/ffi/*/*.def)
549550

550551
# Implicitly depends on $(NODE_EXE), see the build-ffi-tests rule for rationale.
551552
test/ffi/.buildstamp: $(ADDONS_PREREQS) \

configure.py

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,28 @@
686686
dest='shared_sqlite_libpath',
687687
help='a directory to search for the shared sqlite DLL')
688688

689+
shared_optgroup.add_argument('--shared-ffi',
690+
action='store_true',
691+
dest='shared_ffi',
692+
default=None,
693+
help='link to a shared libffi DLL instead of static linking')
694+
695+
shared_optgroup.add_argument('--shared-ffi-includes',
696+
action='store',
697+
dest='shared_ffi_includes',
698+
help='directory containing libffi header files')
699+
700+
shared_optgroup.add_argument('--shared-ffi-libname',
701+
action='store',
702+
dest='shared_ffi_libname',
703+
default='ffi',
704+
help='alternative libffi name to link to [default: %(default)s]')
705+
706+
shared_optgroup.add_argument('--shared-ffi-libpath',
707+
action='store',
708+
dest='shared_ffi_libpath',
709+
help='a directory to search for the shared libffi DLL')
710+
689711
shared_optgroup.add_argument('--shared-temporal_capi',
690712
action='store_true',
691713
dest='shared_temporal_capi',
@@ -1017,11 +1039,11 @@
10171039
default=None,
10181040
help='build without SQLite (disables SQLite and Web Storage API)')
10191041

1020-
parser.add_argument('--with-ffi',
1042+
parser.add_argument('--without-ffi',
10211043
action='store_true',
1022-
dest='with_ffi',
1044+
dest='without_ffi',
10231045
default=None,
1024-
help='build with FFI (Foreign Function Interface) support')
1046+
help='build without FFI (Foreign Function Interface) support')
10251047

10261048
parser.add_argument('--experimental-quic',
10271049
action='store_true',
@@ -2188,9 +2210,40 @@ def without_sqlite_error(option):
21882210

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

2213+
def bundled_ffi_supported(os_name, target_arch):
2214+
supported = {
2215+
'freebsd': {'arm', 'arm64', 'ia32', 'x64'},
2216+
'linux': {'arm', 'arm64', 'ia32', 'x64'},
2217+
'mac': {'arm64', 'x64'},
2218+
'win': {'arm', 'arm64', 'x64'},
2219+
}
2220+
2221+
if target_arch == 'x86':
2222+
target_arch = 'ia32'
2223+
2224+
return target_arch in supported.get(os_name, set())
2225+
21912226
def configure_ffi(o):
2192-
o['variables']['node_use_ffi'] = b(options.with_ffi)
2193-
return
2227+
use_ffi = not options.without_ffi
2228+
2229+
if use_ffi and not options.shared_ffi:
2230+
target_arch = o['variables']['target_arch']
2231+
if not bundled_ffi_supported(flavor, target_arch):
2232+
warn(f'FFI is disabled for {flavor}/{target_arch}: the bundled libffi '
2233+
'integration is not available on this platform. Use --shared-ffi '
2234+
'to provide a system libffi or --without-ffi to silence this '
2235+
'warning.')
2236+
use_ffi = False
2237+
2238+
o['variables']['node_use_ffi'] = b(use_ffi)
2239+
2240+
if options.without_ffi:
2241+
if options.shared_ffi:
2242+
error('--without-ffi is incompatible with --shared-ffi')
2243+
return
2244+
2245+
if not use_ffi:
2246+
return
21942247

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

0 commit comments

Comments
 (0)