Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Support for AOT compilation #103

Closed
sriio opened this issue May 7, 2019 · 6 comments
Closed

Support for AOT compilation #103

sriio opened this issue May 7, 2019 · 6 comments

Comments

@sriio
Copy link

sriio commented May 7, 2019

With Dart 2.3, you can compile your backend ahead of time but it doesn't work with angel ...

Steps to reproduce:

Download Dart 2.3 here : http://gsdview.appspot.com/dart-archive/channels/stable/raw/2.3.0/sdk/

Create a new angel project with angel init test_project

Go to test_project and run dart2aot bin/prod.dart bin/prod.dart.aot

Problem:

You get this error :

 dart2aot bin/prod.dart bin/prod.dart.aot
error: import of dart:mirrors with --enable-mirrors=false

Cause:

Like the case of Flutter, the package 'mirrors' doesn't work with aot compilation ... No workaround, just find a way to replace it (with reflectable for example which is ok with aot)

@thosakwe
Copy link
Member

thosakwe commented May 7, 2019

Actually, Angel 2 has no dependency on dart:mirrors. Reflection is abstracted away via package:angel_container.

Note the call to MirrorsReflector() in prod.dart. If you delete that, along with the import of package:angel_container:mirrors.dart, you will be able to build it.

Removing mirrors-by-default was one of the biggest changes in Angel 2.

Also, there already is support for using package:reflectable. See package:angel_container_generator.

@thosakwe thosakwe closed this as completed May 7, 2019
@sriio
Copy link
Author

sriio commented May 7, 2019

Thank you for your reply. I'm going to try your advices.

@sriio
Copy link
Author

sriio commented May 7, 2019

Still failing despite your instructions.

prod.dart

import 'package:dart_hello/dart_hello.dart';
import 'package:angel_production/angel_production.dart';

main(List<String> args) =>
    Runner('dart_hello', configureServer)
        .run(args);

Command :

dart2aot bin/prod.dart bin/prod.dart.aot
error: import of dart:mirrors with --enable-mirrors=false

@thosakwe
Copy link
Member

thosakwe commented May 7, 2019

Ah, on further investigation, I figured it out. angel_jael depends on jael, which uses dart:mirrors.

Just remove the angel_jael dependency, along with the usage of MirrorsReflector(), and it'll work.

Note: this means that, at least at the moment, Jael will not work in AOT. A new major version could potentially use the Reflector abstraction, instead of dart:mirrors.

@sriio
Copy link
Author

sriio commented May 7, 2019

Indeed, I commented in config.dart the importation of angel_jael and configuration line, now it works !
Instant startup, reduce memory from about 250mb to 30mb, all good :-)

Thank you for your help.

@thosakwe
Copy link
Member

thosakwe commented May 7, 2019 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants