-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
There's scenarios where developer tooling might want to compile code which contains platform specific core library imports for an unsupported platform (e.g, the web-based Flutter Widget Previewer should be able to render widgets from libraries with dart:io or dart:ffi imports, as long as the widgets don't actually use APIs from those libraries). There currently isn't consistent support for this provided by the various web runtimes:
- Neither DDC or dart2js have stubs for
dart:ffiordart:mirrors, so these libraries can never be imported webdev serveprevents applications withdart:io(anddart:isolate?) imports from being executedflutter run -d chrome,dart compile js, and DDC all allow fordart:ioanddart:isolateimports
As previously discussed, we need a solution to allow for these native core libraries to be referenced in web projects created by developer tooling while also continuing to encourage the ecosystem to move towards making their packages platform agnostic.
This effort will consist of multiple parts:
- Add DDC and dart2js stubs for native core libraries
- Add --allow-native-core-library-imports to DDC and dart2js to allow for native library imports #62128
- This flag is disabled by default, and will not initially include
dart:ioanddart:isolateto avoid a breaking change. - Print warnings if an unsupported library is imported when
--allow-native-core-library-importsis specified, with a (hidden?) flag to silence the warnings (e.g.,--silence-native-core-library-imports-warnings). - We could consider printing details about which package or library is responsible for the imports, along with links to documentation on using conditional imports for platform specific libraries.
- This flag is disabled by default, and will not initially include
- Make treatment of
dart:ioanddart:isolateimports consistent with other native libraries:- File a breaking change request to no longer allow for
dart:ioanddart:isolateimports by default for DDC anddart compile js. - Initially include a notice that this behavior will be disabled by default in a future release when DDC or
dart compile jsencounters these imports without--allow-native-core-library-imports. - In a follow-up release, remove the warning and place
dart:ioanddart:isolateimports behind the--allow-native-core-library-importsflag.
- File a breaking change request to no longer allow for
This new behavior will not be widely promoted to avoid encouraging developers from using this in their day to day workflows.