dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
106 stars 36 forks source link

[native_assets_cli] HookOutput dependencies should not have to include any Dart files #1256

Closed dcharkes closed 4 days ago

dcharkes commented 2 weeks ago

The compiler should know what Dart source files have been used running a Dart script. So we shouldn't request hook writers to list transitively all Dart files in HookOutput.dependencies.

Currently the hook is run as dart path/to/some/hook/<hookname>.dart --config=path/to/config.json.

In order to get a list of all Dart files used, we have multiple options:

  1. Manually compiling to kernel first, and having that output a .d file (not preferred, I'd rather not depend on SDK internals.).
  2. Adding a --dependencies=path/to/deps.d to dart. dart --dependencies=path/to/deps.d path/to/some/hook/<hookname>.dart --config=path/to/config.json. This could be used for other use cases as well. (preferred)

Then we can also get rid of the weird dartBuildFiles for the CBuilder:

        final cbuilder = CBuilder.library(
          sources: [addCUri.toFilePath()],
          name: name,
          assetName: name,
          pic: pic,
          dartBuildFiles: ['hook/build.dart'],
        );

Thanks @kustermann!

dcharkes commented 1 week ago

@jensjoha can the CFE output a list of dart source files?

jensjoha commented 1 week ago

The frontend_server for instance lists the keys in component.uriToSource (as in +file1\n+file2 etc). Is that what you want? (I seem to be missing some context here).

mkustermann commented 1 week ago

We could even make flutter build and dart build:

Most of our tools already support emitting .d dependency files (e.g. dart --snapshot-kind=kernel --snapshot=test.dill --depfile=test.dill.d test.dart, frontend-server, dart2js, dart2wasm, ...) - because flutter already needs those dependency files to detect whether to rebuild things.

We should be really optimizing for compile times in dart build / flutter build, e.g. if the package graphs depth is 30 and all of them use hooks, saving a single second (e.g. via parallel compile of hooks to kernel) would save half a minute for a developer.

kustermann commented 4 days ago

Guys, I’m not on your team!

Private and Confidential

Maximilian A. Kustermann @.***

On Mon 15. Jul 2024 at 10:14, Daco Harkes @.***> wrote:

Closed #1256 https://github.com/dart-lang/native/issues/1256 as completed.

— Reply to this email directly, view it on GitHub https://github.com/dart-lang/native/issues/1256#event-13501809283, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABS4RZKYOHMBXTWT4DISVFDZMOAHHAVCNFSM6AAAAABKHMUOX2VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJTGUYDCOBQHEZDQMY . You are receiving this because you were mentioned.Message ID: @.***>