Closed dcharkes closed 2 months ago
Due to flutter run -d all
running native assets builds concurrently, we cannot share the hook compilation to kernel across the same hook but different config invocations in https://github.com/dart-lang/native/issues/1256.
Currently,
NativeAssetsBuilder
s methods can be called by the embedder as follows:BuildConfig
/LinkConfig
s is fine. Everything is happening in the.dart_tool/native_assets_builder/<hashed_config>/
.This is currently mostly fine.
The situation in which this breaks in Flutter is when
flutter run -d all
has overlapping devices. E.g. if there are two Android phones connected. (It works fine with MacOS, iOS Simuatlor, iOS device, and Android emulator together.)Flutter does not allow running more than one
flutter
command in the terminal concurrently. It has some kind of lock.Dart doesn't have any commands running multiple native asset builds.
However, Dart doesn't guard against concurrent invocations. So two concurrent
dart run
process runs will cause undefined behavior.Also there's no guard against running
dart
andflutter
concurrently.We should explore making the
NativeAssetsBuilder
re-entrant. It should support the following scenarios:multiple invocations in the same Dart processNot needed.Since multiple processes need to communicate, we'd likely want to use lock files on the file system.
dart:io
surfaces locks: https://api.dart.dev/stable/3.4.4/dart-io/RandomAccessFile/lock.html