From 153b668c8b43adde4d98cb0022a2e4a263926853 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Tue, 11 Jun 2024 12:21:11 +0000 Subject: [PATCH] [stable] [dart2wasm] Make `dart compile wasm` compiled apps disable `dart.library.ffi` This is a follow-up to [0]. That CL changed dart2wasm's modular transformer to issue an error if `dart:ffi` is imported. Users of packages that have specialized code for the VM (which supports FFI) use conditional imports based on `dart.library.ffi`. We don't want the VM-specific code to be used for web in dart2wasm (as dart2wasm doesn't support the entirety of `dart:ffi`). As a result we're going to make `dart.library.ffi` be false in coditional imports (as well as in `const bool.fromEnvironment('dart.library.ffi')`). [0] https://dart-review.googlesource.com/c/sdk/+/368568 Bug: https://github.com/dart-lang/sdk/issues/55948 Bug: https://github.com/flutter/flutter/issues/149984 Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/370580 Cherry-pick-request: https://github.com/dart-lang/sdk/issues/55979 Change-Id: Ia968bacf92566d421606fc026c7f016fe5abff01 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370880 Reviewed-by: Slava Egorov --- CHANGELOG.md | 10 ++++++++++ .../lib/js_interop_checks.dart | 14 ++++++++++---- pkg/dart2wasm/lib/compile.dart | 4 +++- pkg/dart2wasm/lib/dart2wasm.dart | 3 +++ pkg/dart2wasm/lib/target.dart | 18 +++++++++++++----- pkg/dart2wasm/lib/translator.dart | 1 + pkg/dart2wasm/tool/compile_benchmark | 5 +++++ tests/web/wasm/ffi/disabled_helper.dart | 5 +++++ tests/web/wasm/ffi/disabled_test.dart | 12 ++++++++++++ tests/web/wasm/ffi/enabled_helper.dart | 8 ++++++++ tests/web/wasm/ffi/enabled_test.dart | 14 ++++++++++++++ tests/web/wasm/{ => ffi}/ffi_native_test.dart | 1 + .../wasm/{ => ffi}/ffi_native_test_module.c | 0 utils/dart2wasm/BUILD.gn | 2 +- 14 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 tests/web/wasm/ffi/disabled_helper.dart create mode 100644 tests/web/wasm/ffi/disabled_test.dart create mode 100644 tests/web/wasm/ffi/enabled_helper.dart create mode 100644 tests/web/wasm/ffi/enabled_test.dart rename tests/web/wasm/{ => ffi}/ffi_native_test.dart (98%) rename tests/web/wasm/{ => ffi}/ffi_native_test_module.c (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3057ceccd84b..d3d19966fdfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## 3.4.4 + +This is a patch release that: + +- Fixes an issue where `const bool.fromEnvironment('dart.library.ffi')` is true + and conditional import condition `dart.library.ffi` is true in dart2wasm. + (issue [#55948]). + +[#55948]: https://github.com/dart-lang/sdk/issues/55948 + ## 3.4.3 - 2024-06-05 This is a patch release that: diff --git a/pkg/_js_interop_checks/lib/js_interop_checks.dart b/pkg/_js_interop_checks/lib/js_interop_checks.dart index 4cbd3363659d..33bfdd891c3b 100644 --- a/pkg/_js_interop_checks/lib/js_interop_checks.dart +++ b/pkg/_js_interop_checks/lib/js_interop_checks.dart @@ -85,6 +85,8 @@ class JsInteropChecks extends RecursiveVisitor { final ExportChecker exportChecker; final bool isDart2Wasm; + final List _disallowedInteropLibrariesInDart2Wasm; + /// Native tests to exclude from checks on external. // TODO(rileyporter): Use ExternalName from CFE to exclude native tests. static final List _allowedNativeTestPatterns = [ @@ -107,7 +109,7 @@ class JsInteropChecks extends RecursiveVisitor { // Negative lookahead to test the violation. RegExp( r'(? compileToModule(compiler.WasmCompilerOptions options, mode = wasm.Mode.regular; } final WasmTarget target = WasmTarget( - removeAsserts: !options.translatorOptions.enableAsserts, mode: mode); + enableExperimentalFfi: options.translatorOptions.enableExperimentalFfi, + removeAsserts: !options.translatorOptions.enableAsserts, + mode: mode); CompilerOptions compilerOptions = CompilerOptions() ..target = target ..sdkRoot = options.sdkPath diff --git a/pkg/dart2wasm/lib/dart2wasm.dart b/pkg/dart2wasm/lib/dart2wasm.dart index f4bf8141939c..06f65469d4d5 100644 --- a/pkg/dart2wasm/lib/dart2wasm.dart +++ b/pkg/dart2wasm/lib/dart2wasm.dart @@ -97,6 +97,9 @@ final List