Files
sdk/runtime/docs/compiler/ffi_pragmas.md
T
Alexander Markov dcdfcc2b8d Reland "[vm/ffi] Express FFI call closures explicitly in AST"
This reverts commit 1800039c2a.

The changes fd2e9b9f1a and
c20f9eaf6f are relanded as is.

Reason for revert was fixed separately in
https://dart-review.googlesource.com/c/sdk/+/341621

TEST=ci

CoreLibraryReviewExempt: Implementation change only.
Issue: https://github.com/dart-lang/sdk/issues/54172
Issue: https://github.com/dart-lang/sdk/issues/39692
Change-Id: I1a2324768502e5ffbce328127938c0d3c96c38ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341642
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-12-15 15:25:29 +00:00

1.4 KiB

Pragmas used in the FFI implementation

Native Assets

This pragma is used for passing native assets to the VM.

@pragma('vm:ffi:native-assets', {
  'format-version': [1, 0, 0],
  'native-assets': {
    'linux_x64': {
      'package:foo/foo.dart': ['absolute', '/path/to/libfoo.so']
    }
  }
})
library 'vm:native-assets';

Related files:

Native

The fully expanded version of @Native passed to the VM.

@pragma(
  'vm:ffi:native',
  Native<IntPtr Function(Pointer<Void>, IntPtr)>(
    symbol: 'MyClass_MyMethod',
    assetId: '<library uri>',
  ),
)
external int _myFunction$FfiNative(Pointer<Void> self, int x);

This is passed as a pragma so it is treated consistently with other pragmas.

Related files:

FFI Calls

This pragma is used to mark Dart closures which perform FFI calls:

  @pragma('vm:ffi:call-closure', _FfiCall<Int32 Function(Int32)>(isLeaf: false))
  int #ffiCall0(int arg1) => _ffiCall<int>(target);