dart-sdk/utils
Ömer Sinan Ağacan affc3392a0 [dart2wasm] Implement Wasm FfiNative support
This CL introduces a new kernel-to-kernel pass in Wasm backend to
compile `FfiNative`-annotated external functions to external functions
with `wasm:import` pragmas.

The new pass `WasmFfiNativeTransformer` extends `FfiNativeTransformer`.
Some `FfiNativeTransformer` methods made public to allow reuse in the
pass.

The conversion works like this: when we see a member like:

    @FfiNative<Int8 Function(Int8, Int8)>("ffi.addInt8")
    external int addInt8(int a, int b);

We generate a Wasm import using Wasm ABI types according to emscripten
calling conventions:

    @pragma('wasm:import', 'ffi.addInt8')
    external static WasmI32 addInt8_$import(WasmI32 a, WasmI32 b);

and convert the original member (`addInt8()`) to a wrapper function that
calls the Wasm import, converting the arguments and return values to
Dart types:

    static int addInt8(int a, int b) {
      return WasmI32.toIntSigned(
        addInt8_$import(
            WasmI32::int8FromInt(a),
            WasmI32::int8FromInt(b),
        ));
    }

Build, test, and CI changes:

- Test runner now uses `// SharedObjects=...` lines in dart2wasm tests
  to pass extra Wasm modules to d8 command used to run the tests.

  Support for `// SharedObjects=...` lines were already used in
  native/AOT FFI tests, not added in this CL. We just start to use those
  lines in dart2wasm tests.

- dart2wasm gn file updated with a target "test_wasm_modules" that
  builds FFI test Wasm modules to Wasm using emcc (emscripten C
  compiler).

- CI dart2wasm_hostasserts configuration updated to copy the Wasm files
  generated by the "test_wasm_modules" target to the shards.

TEST=tests/web/wasm/ffi_native_test

Change-Id: I6527fe4e2ca2b582e16d84fee244e9cbe6dee307
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252822
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Ömer Ağacan <omersa@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2022-09-23 09:41:22 +00:00
..
analysis_server Reapply "[build] Don't list Dart sources up front when creating application snapshots." 2021-04-27 17:22:54 +00:00
bazel Revert "Revert "Move most of the code from u/b/kernel_worker.dart to p/frontend_server"" 2021-06-14 13:28:23 +00:00
compiler [dart2js] Rename platform files. 2021-10-15 21:40:08 +00:00
dart2native
dart2wasm [dart2wasm] Implement Wasm FfiNative support 2022-09-23 09:41:22 +00:00
dartanalyzer Replace a bunch of references to .packages 2021-10-12 20:16:15 +00:00
dartdev [ CLI ] Migrate package:dartdev to null safety 2022-01-26 21:16:49 +00:00
dartdevc [ddc] Include shared library for new runtime types 2022-05-25 18:23:29 +00:00
dds Reapply "[build] Don't list Dart sources up front when creating application snapshots." 2021-04-27 17:22:54 +00:00
gen_kernel Replace a bunch of references to .packages 2021-10-12 20:16:15 +00:00
kernel-service Replace a bunch of references to .packages 2021-10-12 20:16:15 +00:00
peg
tests/peg [test] Apply simarm64 status file entries to simarm64c. 2021-02-25 21:18:02 +00:00
aot_snapshot.gni [dart2wasm] Build platform dill and compile dart2wasm to AOT snapshots 2022-05-10 10:06:06 +00:00
application_snapshot.gni [build] Don't invoke the JIT runtime when using kernel for SDK snapshots. 2022-05-17 21:36:56 +00:00
compile_platform.gni Replace a bunch of references to .packages 2021-10-12 20:16:15 +00:00
create_timestamp.gni Reapply "[build] Track glob dependencies via depfiles, instead of always re-executing scripts at GN time." 2021-05-12 00:27:28 +00:00
OWNERS [infra] Add OWNERS to the Dart SDK 2022-02-14 14:06:34 +00:00