-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There are multiple differences between the `native_assets.yaml` that is embedded in the kernel file and the `build_output.yaml -> assets`. * Based on the discussions on #955 and #946, it is clear that the `path` for assets should be in `Asset`, not in `AssetPath` for the file-path the asset has after the `build.dart` run. When the embedders (Flutter/Dart) embed the native assets mapping then the `path`s start representing the path on the system where the Dart/Flutter app is running. This should be embedded in the path-type there. * The kernel info does not contain link mode (currently), as static linking is not supported. It's not clear that if we support static linking whether any information should be embedded in the kernel info at all. * The native_assets.yaml for the kernel file is laid out for easy lookup at runtime (keyed on Target). * We want to change the `Asset`s to output OS and Architecture instead of Target. Therefore we should not share the data structure between `Asset`s and `KernelAsset`s (new name for the entries that are embedded via native_assets.yaml in a kernel file.) This means that `dartdev` and `flutter_tools` will have to start converting `Asset`s to `KernelAsset`s when making the `native_assets.yaml` file. Therefore this is a breaking change and will have to be rolled into Dart and flutter/flutter manually.
- Loading branch information
Showing
6 changed files
with
165 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
143 changes: 143 additions & 0 deletions
143
pkgs/native_assets_builder/lib/src/model/kernel_assets.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
/// Library defining the `native_assets.yaml` format for embedding in a Dart | ||
/// kernel file. | ||
/// | ||
/// The `native_assets.yaml` embedded in a kernel file has a different format | ||
/// from the assets passed in the `build_output.yaml` from individual native | ||
/// assets builds. This library defines the format of the former so that it | ||
/// can be reused in `package:dartdev` and `package:flutter_tools`. | ||
/// | ||
/// The format should be consistent with `pkg/vm/lib/native_assets/` in the | ||
/// Dart SDK. | ||
library kernel_native_assets; | ||
|
||
import 'package:native_assets_cli/native_assets_cli_internal.dart'; | ||
|
||
import '../utils/yaml.dart'; | ||
|
||
class KernelAssets { | ||
final List<KernelAsset> assets; | ||
|
||
KernelAssets(this.assets); | ||
|
||
String toNativeAssetsFile() { | ||
final assetsPerTarget = <Target, List<KernelAsset>>{}; | ||
for (final asset in assets) { | ||
final assets = assetsPerTarget[asset.target] ?? []; | ||
assets.add(asset); | ||
assetsPerTarget[asset.target] = assets; | ||
} | ||
|
||
final yamlContents = { | ||
'format-version': [1, 0, 0], | ||
'native-assets': { | ||
for (final entry in assetsPerTarget.entries) | ||
entry.key.toString(): { | ||
for (final e in entry.value) e.id: e.path.toYaml(), | ||
} | ||
}, | ||
}; | ||
|
||
return yamlEncode(yamlContents); | ||
} | ||
} | ||
|
||
class KernelAsset { | ||
final String id; | ||
final Target target; | ||
final KernelAssetPath path; | ||
|
||
KernelAsset({ | ||
required this.id, | ||
required this.target, | ||
required this.path, | ||
}); | ||
} | ||
|
||
abstract class KernelAssetPath { | ||
List<String> toYaml(); | ||
} | ||
|
||
/// Asset at absolute path [uri] on the target device where Dart is run. | ||
class KernelAssetAbsolutePath implements KernelAssetPath { | ||
final Uri uri; | ||
|
||
KernelAssetAbsolutePath(this.uri); | ||
|
||
static const _pathTypeValue = 'absolute'; | ||
|
||
@override | ||
List<String> toYaml() => [_pathTypeValue, uri.toFilePath()]; | ||
} | ||
|
||
/// Asset at relative path [uri], relative to the 'dart file' executed. | ||
/// | ||
/// The 'dart file' executed can be one of the following: | ||
/// | ||
/// 1. The `.dart` file when executing `dart path/to/script.dart`. | ||
/// 2. The `.kernel` file when executing from a kernel file. | ||
/// 3. The `.aotsnapshot` file when executing from an AOT snapshot with the Dart | ||
/// AOT runtime. | ||
/// 4. The executable when executing a Dart app compiled with `dart compile exe` | ||
/// to a single file. | ||
/// | ||
/// Note when writing your own embedder, make sure the `Dart_CreateIsolateGroup` | ||
/// or similar calls set up the `script_uri` parameter correctly to ensure | ||
/// relative path resolution works. | ||
class KernelAssetRelativePath implements KernelAssetPath { | ||
final Uri uri; | ||
|
||
KernelAssetRelativePath(this.uri); | ||
|
||
static const _pathTypeValue = 'relative'; | ||
|
||
@override | ||
List<String> toYaml() => [_pathTypeValue, uri.toFilePath()]; | ||
} | ||
|
||
/// Asset is avaliable on the system `PATH`. | ||
/// | ||
/// [uri] only contains a file name. | ||
class KernelAssetSystemPath implements KernelAssetPath { | ||
final Uri uri; | ||
|
||
KernelAssetSystemPath(this.uri); | ||
|
||
static const _pathTypeValue = 'system'; | ||
|
||
@override | ||
List<String> toYaml() => [_pathTypeValue, uri.toFilePath()]; | ||
} | ||
|
||
/// Asset is loaded in the process and symbols are available through | ||
/// `DynamicLibrary.process()`. | ||
class KernelAssetInProcess implements KernelAssetPath { | ||
KernelAssetInProcess._(); | ||
|
||
static final KernelAssetInProcess _singleton = KernelAssetInProcess._(); | ||
|
||
factory KernelAssetInProcess() => _singleton; | ||
|
||
static const _pathTypeValue = 'process'; | ||
|
||
@override | ||
List<String> toYaml() => [_pathTypeValue]; | ||
} | ||
|
||
/// Asset is embedded in executable and symbols are available through | ||
/// `DynamicLibrary.executable()`. | ||
class KernelAssetInExecutable implements KernelAssetPath { | ||
KernelAssetInExecutable._(); | ||
|
||
static final KernelAssetInExecutable _singleton = KernelAssetInExecutable._(); | ||
|
||
factory KernelAssetInExecutable() => _singleton; | ||
|
||
static const _pathTypeValue = 'executable'; | ||
|
||
@override | ||
List<String> toYaml() => [_pathTypeValue]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters