-
Notifications
You must be signed in to change notification settings - Fork 68
[native_assets_cli] Dart API interface per asset type #994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Nesting the assets inside an asset type in the API has consequences for how a Having it nested means that older So, @mosuem and I believe it's better to have a single list of assets. |
I don't understand this at all. One only uses I'd view our system as a layered architecture:
It probably makes sense for there to be one linker per asset-API/asset-type (imagine C linker: it combines all the native code into one One way to look at it is a map-reduce system: All emitted assets by |
Conceptually yes, but the question is how to make this work nicely. Suppose there are two packages that have a To avoid these issues, @mosuem and I thought it would make sense to have asset-types conceptually namespaced by package name. So instead of the asset-type determining to which # build_output.yaml/json
assets:
- # immediately bundled
assets_for_linking:
native_toolchain_c:
- # an asset being sent to native_toolchain_c tool/link.dart for linking The downside of namespacing asset types with package names is that we can't really do drop-in-replacements of linkers. E.g. if someone comes up with a better JSON minifier, every So from a map-reduce point of view:
Map reduce works with the first approach, if I understand correctly. The comment was written with assuming this approach. If we both have a concept of |
Definitely not. There's multiple options:
One could do a combination:
|
I like the combination option. I'd need to spend a bit more time thinking about some of the specifics.
But in general I think this a good approach. For our first use cases, I think the (Side note: These considerations are more for #153. Not really what this issue was about.) |
On the lowest level each bundling & runtime system (flutter and dart) will have a fixed set of asset-APIs it supports. So if
An interesting thought experiment would be to see how one could make custom asset-APIs that neither Dart / Flutter know about which then get lowered to the ones that the bundling tool support:
If we can make this work we have a general mechanism that
|
I was thinking we would execute
Yes that's the idea. Now that we have a
I think it would make it simpler if we always run the linking step so that this package would always emit the same format. Then it's runtime doesn't have to branch on JIT/AOT. (Side note: This sounds exactly like the use case mentioned in flutter/flutter#143348.)
Yep, that's the idea! 👌 |
For some things no linking will be needed (e.g. readily available
Yes. Stay tuned about this - working on that part! |
I'm thinking that it's a required step for the svg compiler mentioned in that issue. cc @mosuem all the above thoughts. |
Svgs can be parsed & displayed at runtime or can be pre-processed to something else (e.g. a bunch of triangles with shading information - which may take long time) and that something else can be loaded & displayed. Also the We may want to communicate to If there's a real need we can of course support running the linking in development mode as well, I just fear that it may be misused to do a lot of work where it will harm development cycle. |
That requires the
(We currently don't have a concept of develop vs release in Dart standalone. Should all JIT be considered development mode?)
Hm, that's indeed something to consider. |
Somewhat as described above: If I have svgs in my package, then I need to tell the system my package needs those svgs: // hooks/build.dart
import 'package:svg_cli_build/svg_cli_build.dart';
main(args) async {
await runBuild((config, output) {
SvgBuilder('package:mypackage', ['icons/a.svg', 'icons/b.svg']).build(config, output);
});
} In my package (doesn't have to be root package) I then do // package:foowidget/foowidget.dart
import 'package:svg/svg.dart';
class FooWidget {
... = loadSvgApi('package:mypackage', 'icons/a.svg');
} Now
Now
i.e. we have a higher-level concepts
that under the hood rely on lower level things supported by dart/flutter build/bundle/runtime. In some sense this is very natural: The package that knows how to e.g. compile C code probably also knows how to link it. The package that provides a intl/l18n API probably knows how to tree shake the intl/l18n files. So it can have a package for the compile-time component (build/link) and one for runtime - they can possibly even be the same. |
Currently, Asset has a non-nullable assetId. Which makes sense for data assets and native code assets as they both are accessed from Dart code through asset id. It's unlikely that we would access Jar assets via an asset id ever. So we might want move assetId into code asset and data asset. (Or we make |
I think with the refactorings done by @mkustermann this can be marked as done. |
The Dart API can be revved independently of the protocol, bumping this out of v1.0.
Make
package:native_assets_cli
only consume an API that shows getters for native code (and not any getters for Java or other asset types). This can be achieved byNativeBuildConfig
insideBuildConfig
which doesn't work well with the shared fields such asoutputDirectory
, orBuildConfig implements NativeBuildConfig
where only a subset of the getters is visible, orNativeBuildConfig
onBuildConfig
.Make
package:native_toolchain_c
add assets to aNativeBuildOutput
that doesn't have methdods/setters related to Java assets or data assets. This can be achieved byBuildOutput implements NativeBuildOutput
andNativeBuildOutput.addAsset
takesNativeCodeAsset
instead ofAsset
.We could even have assetId be optional for some asset types (jars) in the API.
Question: Don't we ever have builders that would like to add more than one asset type? They would need to take the full
BuildOutput
.Related:
Sister issue for the JSON protocol:
The text was updated successfully, but these errors were encountered: