Skip to content
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

Crash trying to compile a flutter app with macros #55139

Closed
jakemac53 opened this issue Mar 7, 2024 · 11 comments
Closed

Crash trying to compile a flutter app with macros #55139

jakemac53 opened this issue Mar 7, 2024 · 11 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-feature-macros Implement macros features in the CFE feature-macros Implementation of the macros feature

Comments

@jakemac53
Copy link
Contributor

I am trying to test out macros in flutter but am getting a failure today for flutter run -d linux.

You can try my example by cloning https://github.com/jakemac53/macros_example/tree/flutter-app, and running flutter run --enable-experiment macros -d linux (or whichever device you have locally set up, it probably isn't linux specific as this is a kernel compilation failure).

I get the error below:

flutter run --enable-experiment macros -d linux
Launching lib/main.dart on Linux in debug mode...
Unhandled exception:
Crash when compiling:
Unsupported operation: Unexpected library member DynamicTypeDeclarationBuilder(dynamic) (DynamicTypeDeclarationBuilder)

#0      MacroApplications._computeSourceLibraryMacroApplicationData (package:front_end/src/fasta/kernel/macro/macro.dart:518)
#1      MacroApplications.computeLibrariesMacroApplicationData (package:front_end/src/fasta/kernel/macro/macro.dart:374)
#2      SourceLoader.computeMacroApplications (package:front_end/src/fasta/source/source_loader.dart:1719)
#3      KernelTarget.buildOutlines.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:436)
#4      withCrashReporting (package:front_end/src/fasta/crash.dart:133)
#5      KernelTarget.buildOutlines (package:front_end/src/fasta/kernel/kernel_target.dart:415)
#6      _buildInternal (package:front_end/src/kernel_generator_impl.dart:151)
#7      generateKernelInternal.<anonymous closure> (package:front_end/src/kernel_generator_impl.dart:119)
<asynchronous suspension>
#8      withCrashReporting (package:front_end/src/fasta/crash.dart:133)
<asynchronous suspension>
#9      kernelForProgramInternal.<anonymous closure> (package:front_end/src/api_prototype/kernel_generator.dart:65)
<asynchronous suspension>
#10     CompilerContext.clear (package:front_end/src/fasta/compiler_context.dart:139)
<asynchronous suspension>
#11     kernelForProgramInternal (package:front_end/src/api_prototype/kernel_generator.dart:64)
<asynchronous suspension>
#12     _compileMacros (package:front_end/src/kernel_generator_impl.dart:365)
<asynchronous suspension>
#13     precompileMacros (package:front_end/src/kernel_generator_impl.dart:314)
<asynchronous suspension>
#14     IncrementalCompiler.computeDelta.<anonymous closure> (package:front_end/src/fasta/incremental_compiler.dart:347)
<asynchronous suspension>
#15     CompilerContext.clear (package:front_end/src/fasta/compiler_context.dart:139)
<asynchronous suspension>
#16     IncrementalCompiler.compile (package:vm/incremental_compiler.dart:77)
<asynchronous suspension>
#17     FrontendCompiler.compile (package:frontend_server/frontend_server.dart:617)
<asynchronous suspension>
#18     listenAndCompile.<anonymous closure> (package:frontend_server/frontend_server.dart:1311)
<asynchronous suspension>
the Dart compiler exited unexpectedly.
@jakemac53 jakemac53 added area-front-end Use area-front-end for front end / CFE / kernel format related issues. feature-macros Implementation of the macros feature labels Mar 7, 2024
@johnniwinther johnniwinther added the cfe-feature-macros Implement macros features in the CFE label Mar 8, 2024
@davidmorgan
Copy link
Contributor

Started digging into this; it looks like a config issue, so, hopefully I can fix it :)

@davidmorgan
Copy link
Contributor

Okay there's a bunch to unpack here, that I will dig into tomorrow :)

  • Flutter platform dill is called product_strong.dill, not vm_product_strong.dill, so macro_target.dart picks the wrong file, that's an easy fix :)
  • VmTarget doesn't work to compile the macro, FlutterTarget does ... needs some digging.
  • frontend_server.dart calls writeDepfile in package:vm/kernel_front_end.dart, which chokes on the macro URI; we can probably just skip it, needs checking.

And this is enough to get a macro in the "hello world" app working for target "linux". (i.e. desktop).

@DanTup
Copy link
Collaborator

DanTup commented Mar 21, 2024

@davidmorgan do you have a branch or something where this is working? I'm interested in doing some testing with the Flutter debug adapter to see if everything "just works".. it's not important to me if everything works or is merged, but if I can rig it enough to run locally, it could give me a head-start on testing :-)

@davidmorgan
Copy link
Contributor

Sure, just about :) ... happy to have more people trying it :)

"flutter run" with "-d linux" or "-d chrome" are working after

https://dart-review.googlesource.com/c/sdk/+/358443 -- which just merged
https://dart-review.googlesource.com/c/sdk/+/358700 -- running through CQ

--you'll need flutter set up to run with a locally built Dart SDK, until the change rolls into flutter properly.

Looking next at getting it running with emulators.

@DanTup
Copy link
Collaborator

DanTup commented Mar 21, 2024

@davidmorgan thanks! Is the Linux support specific to Linux, or would those fixes also apply to macOS or Windows desktop? (I don't currently have easy access to Linux).

Being able to use Web is very useful though, I haven't yet been able to test debugging web+macros at all! :)

@davidmorgan
Copy link
Contributor

I guess it's any desktop, but I haven't tried it yet :)

@DanTup
Copy link
Collaborator

DanTup commented Mar 26, 2024

Looks like those changes got to Flutter before I tested this, although it doesn't seem Windows desktop works:

Launching lib\main.dart on Windows in debug mode...
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(249,5):
  error MSB8066:
    Custom build for 'C:\Dev\Test Projects\flutter_macros\build\windows\x64\CMakeFiles\
        aae1f60e616df67f7401464f9aab49b5\flutter_windows.dll.rule;
        C:\Dev\Test Projects\flutter_macros\build\windows\x64\CMakeFiles\
        67902b57a4e953a86851e7e164897bd8\flutter_assemble.rule'
      exited with code 1. [C:\Dev\Test Projects\flutter_macros\build\windows\x64\flutter\flutter_assemble.vcxproj]
Error: Build process failed.

Exited (1).

Web is working though, and that's a superset of desktop to the debug adapter, so that gives me something to do some testing with. Thanks! :)

@DanTup
Copy link
Collaborator

DanTup commented Mar 26, 2024

Tried on macOS but unfortunately also failed there:

Launching lib/main.dart on macOS in debug mode...
2024-03-26 16:45:52.224 xcodebuild[4800:37848] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
Target kernel_snapshot failed: Exception

Command PhaseScriptExecution failed with a nonzero exit code
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'Flutter Assemble' from project 'Runner')
** BUILD FAILED **

Error: Build process failed

Exited (1).

@davidmorgan
Copy link
Contributor

I believe all the "flutter run"s are working now, please reopen if that's not the case :)

@DanTup
Copy link
Collaborator

DanTup commented Jun 5, 2024

Can confirm on Windows desktop this is all working great. I can run, step into, and hit breakpoints in generated code. Thanks! 🙂

@davidmorgan
Copy link
Contributor

@DanTup thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. cfe-feature-macros Implement macros features in the CFE feature-macros Implementation of the macros feature
Projects
Development

No branches or pull requests

4 participants