[dart2wasm] Allow using experimental dart:ffi in deferred modules

The experimental `dart:ffi` support predates deferred loading
implementation. Any use of FFI features would lazily import `ffi.memory`
into the (fixed coded) main module.

This CL now lazily imports the `ffi.memory` module into all modules that
operate on the memory.

=> This will now allow a flutter app that is compiled with dart2wasm
   in deferred loading mode to possibly defer parts of flutter
   engine code that uses FFI into deferred modules.

Issue https://github.com/dart-lang/sdk/issues/56952

Change-Id: Idf821ce2dd92c36ac1be9dae24307516a1ae86d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510760
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Martin Kustermann
2026-06-10 02:34:44 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent c5f9583eb3
commit 034b90af5d
3 changed files with 48 additions and 31 deletions
@@ -0,0 +1,13 @@
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// dart2wasmOptions=--extra-compiler-option=--enable-experimental-ffi --enable-deferred-loading
// SharedObjects=ffi_native_test_module
import 'ffi_native_test.dart' deferred as D;
main() async {
await D.loadLibrary();
D.main();
}