From 1eb2c0c4eb98b69e0454fff0e5eea264fb43525c Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Mon, 10 Jun 2024 14:37:22 +0200 Subject: [PATCH] Use dart.library.html to distinguish dart2wasm from dart2js/ddc in conditional imports 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 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')`. Issue https://github.com/dart-lang/sdk/issues/55948 Issue https://github.com/flutter/flutter/issues/149984 --- lib/web_ui/lib/src/engine/renderer.dart | 2 +- lib/web_ui/lib/ui_web/src/ui_web/browser_detection.dart | 5 +---- lib/web_ui/test/ui/utils.dart | 3 +-- web_sdk/sdk_rewriter.dart | 2 +- web_sdk/test/sdk_rewriter_test.dart | 2 +- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/web_ui/lib/src/engine/renderer.dart b/lib/web_ui/lib/src/engine/renderer.dart index fd62aaac8b6bb..246ed9b6d1ab1 100644 --- a/lib/web_ui/lib/src/engine/renderer.dart +++ b/lib/web_ui/lib/src/engine/renderer.dart @@ -7,7 +7,7 @@ import 'dart:math' as math; import 'dart:typed_data'; import 'package:ui/src/engine.dart'; -import 'package:ui/src/engine/skwasm/skwasm_stub.dart' if (dart.library.ffi) 'package:ui/src/engine/skwasm/skwasm_impl.dart'; +import 'package:ui/src/engine/skwasm/skwasm_impl.dart' if (dart.library.html) 'package:ui/src/engine/skwasm/skwasm_stub.dart'; import 'package:ui/ui.dart' as ui; import 'package:ui/ui_web/src/ui_web.dart' as ui_web; diff --git a/lib/web_ui/lib/ui_web/src/ui_web/browser_detection.dart b/lib/web_ui/lib/ui_web/src/ui_web/browser_detection.dart index 44de74c1d2389..661849419e869 100644 --- a/lib/web_ui/lib/ui_web/src/ui_web/browser_detection.dart +++ b/lib/web_ui/lib/ui_web/src/ui_web/browser_detection.dart @@ -195,10 +195,7 @@ class BrowserDetection { bool get isEdge => userAgent.contains('Edg/'); /// Whether we are running from a wasm module compiled with dart2wasm. - /// - /// Note: Currently the ffi library is available from dart2wasm but not dart2js - /// or dartdevc. - bool get isWasm => const bool.fromEnvironment('dart.library.ffi'); + bool get isWasm => const bool.fromEnvironment('dart.tool.dart2wasm'); } /// A short-hand accessor to the [BrowserDetection.instance] singleton. diff --git a/lib/web_ui/test/ui/utils.dart b/lib/web_ui/test/ui/utils.dart index ec7eaf4c0aed8..62e142de8a22b 100644 --- a/lib/web_ui/test/ui/utils.dart +++ b/lib/web_ui/test/ui/utils.dart @@ -5,8 +5,7 @@ import 'dart:async'; import 'package:ui/src/engine.dart'; -import 'package:ui/src/engine/skwasm/skwasm_stub.dart' - if (dart.library.ffi) 'package:ui/src/engine/skwasm/skwasm_impl.dart'; +import 'package:ui/src/engine/skwasm/skwasm_impl.dart' if (dart.library.html) 'package:ui/src/engine/skwasm/skwasm_stub.dart'; import 'package:ui/ui.dart'; import '../common/rendering.dart'; diff --git a/web_sdk/sdk_rewriter.dart b/web_sdk/sdk_rewriter.dart index 119f38239ca97..bb69a4cdaf471 100644 --- a/web_sdk/sdk_rewriter.dart +++ b/web_sdk/sdk_rewriter.dart @@ -102,7 +102,7 @@ const Set rootLibraryNames = { }; final Map extraImportsMap = { - RegExp('skwasm_(stub|impl)'): "import 'dart:_skwasm_stub' if (dart.library.ffi) 'dart:_skwasm_impl';", + RegExp('skwasm_(stub|impl)'): "import 'dart:_skwasm_impl' if (dart.library.html) 'dart:_skwasm_stub';", 'ui_web': "import 'dart:ui_web' as ui_web;", 'engine': "import 'dart:_engine';", 'web_unicode': "import 'dart:_web_unicode';", diff --git a/web_sdk/test/sdk_rewriter_test.dart b/web_sdk/test/sdk_rewriter_test.dart index 95cfe8256f9cd..cc1eae42607c8 100644 --- a/web_sdk/test/sdk_rewriter_test.dart +++ b/web_sdk/test/sdk_rewriter_test.dart @@ -165,7 +165,7 @@ void printSomething() { test('gets correct extra imports', () { // Root libraries. expect(getExtraImportsForLibrary('engine'), [ - "import 'dart:_skwasm_stub' if (dart.library.ffi) 'dart:_skwasm_impl';", + "import 'dart:_skwasm_impl' if (dart.library.html) 'dart:_skwasm_stub';", "import 'dart:ui_web' as ui_web;", "import 'dart:_web_unicode';", "import 'dart:_web_test_fonts';",