Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

cbracken
Copy link
Member

Adds a dart_executable rule that compiles Dart code to an ELF, Mach-O, or PE binary. Can be used to build tools written in Dart, or Dart unit tests.

Issue: flutter/flutter#147013

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I added at least one unnecessary checkbox just to see if anyone actually reads these things.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@cbracken cbracken marked this pull request as draft April 19, 2024 05:27
args = []
metadata = {
action_type = [ "dart_executable" ]
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to send a patch upstream to copy this over onto the underlying action target in the dart_action template.

@cbracken cbracken force-pushed the dart-executable branch 2 times, most recently from fc7ba2c to 827f0a2 Compare April 22, 2024 18:25
}

abs_output = rebase_path(output)
exe_vm_args += [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how it's spelled, but we'll want to pass the flag here that disables analytics/telemetry.


abs_output = rebase_path(output)
exe_vm_args += [
"compile",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does dart compile exe run pub? If so, we'll need a way to keep it from touching the network.

Does dart compile exe have a flag that causes it to dump a depfile like flutter_frontend_server does? See https://github.com/flutter/engine/blob/main/build/dart/rules.gni#L71. Without that, GN won't do dependency tracking correctly. You might be able to see that in this PR by editing et source files, and seeing that rebuilds might not happen when you need them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does dart compile exe run pub?

That's a good question. I haven't looked at the implementation. My guess is probably, which we should avoid. Will take a look.

Does dart compile exe have a flag that causes it to dump a depfile like flutter_frontend_server does?

Not one that's documented (even with -v -v set). This patch is still a draft experiment to test the general concept/tool integration. It should work even if we swap out the implementation with an invocation of dart_snapshot (wrapped with a launch script) instead, that approach does support --depfile (and is already implemented above). Will play with that a little.

#
# deps (optional):
# Additional dependencies. Dependencies on the frontend server and
# Flutter's platform.dill are included by default. This rule creates and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't create a depfile as written =)

@goderbauer
Copy link
Member

(triage): I spoke to @cbracken and this is still on his radar. It needs some small tweaks to land.

Adds a dart_executable rule that compiles Dart code to an ELF, Mach-O,
or PE binary. Can be used to build tools written in Dart, or Dart unit
tests.

Issue: flutter/flutter#147013
@cbracken
Copy link
Member Author

Closing this as @matanlurey is picking this one up, starting with #55404.

@cbracken cbracken closed this Sep 24, 2024
auto-submit bot pushed a commit that referenced this pull request Sep 30, 2024
…#55475)

Closes flutter/flutter#155769.

This is a variant of the approach in #52241, based on feedback from @jakemac53 and @jonahwilliams (who originally sped up `dart test` significantly by using `frontend_server` under the scenes: dart-lang/test#1399), in short:

```gn
# tools/engine_tool/BUILD.gn

import("//flutter/build/dart/internal/gen_dartcli_call.gni")

gen_dartcli_call("tests") {
  args = [ "test" ]
  cwd = "//flutter/tools/engine_tool"
}
```

This stanza, when built (`ninja -C ../out/host_debug flutter/tools/engine_tool:tests`) generates the following file:

```sh
# ../out/host_debug/gen/flutter/tools/engine_tool/tests

set -e

# Needed because if it is set, cd may print the path it changed to.
unset CDPATH

# Store the current working directory.
prev_cwd=$(pwd)

# Set a trap to restore the working directory.
trap 'cd "$prev_cwd"' EXIT

CD_PATH="/Users/matanl/Developer/engine/src/flutter/tools/engine_tool"
if [ -n "$CD_PATH" ]; then
  cd "$CD_PATH"
fi

/Users/matanl/Developer/engine/src/flutter/prebuilts/macos-arm64/dart-sdk/bin/dart "test"
```

In turn, when executed (`../out/host_debug/gen/flutter/tools/engine_tool/tests`) it just runs `dart test`:

```sh
flutter % ../out/host_debug/gen/flutter/tools/engine_tool/tests
Building package executable... 
Built test:test.
00:00 +0: test/test_command_test.dart: test command executes test                                                                                                                                                                                                          
00:00 +3: test/run_command_test.dart: run command invokes flutter run
...
00:00 +117: All tests passed!
```

There is no actual compilation performed by the tool (that is handled implicitly by `dart test`), and as a result neither a `depfile` is needed, nor generating a pre-compiled artifact like a snapshot or AOT elf/assembly. 

---

This work is incomplete, that is, we'd want to properly tag the executable so `et` can find it, and create a wrapper template (i.e. `dart_test`) that tightens things up a bit, but I wanted to show the work at this intermediate step to get feedback before moving forward.

/cc @jonahwilliams, @jtmcdole as well.
@cbracken cbracken deleted the dart-executable branch November 28, 2024 16:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants