4 ms·
So how does it run natively on desktop? Is it like electron? Can't tell from the linux example
by belinder 6y ago
So how does it run natively on desktop? Is it like electron? Can't tell from the linux example
- bilal4hmed 6y agoNot like electron at all. It compiles down to a native binary for the OS.
- axaxs 6y agoEh, it's a little murky. I was playing with dart a little. It can in fact create a single binary, but it looks like it's just putting the interpreter with the code. I say that because if you strip or pack the binary, instead of working it shows the output of running dart with no arguments.
- vsmenon 6y ago[ disclaimer: I work on the Dart team ] It depends on how you run. Dart can either run in JIT mode or AOT mode. In general, when you ship a production app (e.g., for Flutter), you are using AOT - i.e., it's compiling to native machine code. In this case, there is no interpretation or compilation at runtime. We still bundle a runtime for garbage collection.
- axaxs 6y agoWhich does 'compile exe' use? Essentially here is what I see - $ cat a.dart void main() { print("hello world"); } $ dart compile exe a.dart Info: Compiling with sound null safety Generated: /home/x/a.exe ~ $ strip a.exe ~ $ ./a.exe --version Dart SDK version: 2.12.0 (stable) (Thu Feb 25 19:50:53 2021 +0100) on "linux_x64" If I run without --version, it prints the same thing the 'dart' command does.
- vsmenon 6y agoThanks - not what I'd expect, but I can repro. Bug filed here: https://github.com/dart-lang/sdk/issues/45197 https://github.com/dart-lang/sdk/issues/45197 It is AOT though. If you time `dart a.dart` vs `./a.exe` (pre strip :-), the latter should be considerably faster.
- mraleph 6y ago[I work on Dart VM team] `dart2native` just concatenates two binaries together: AOT runtime binary and AOT snapshot binary. AOT snapshot is an ELF binary which contains native code generated from your original Dart code. The approach is not pretty but was chosen as an implementation shortcut. That's why `strip` does not actually do good things to the binary. There is no reason to run `strip` on such binaries - because they don't contain anything strippable.
- axaxs 6y agoThanks. Also noting that upx has the same behavior. I didn't inspect the binaries, just try to see how/if they compress.
- mraleph 6y agoWe are planning to fix it some time in the future, we really only expected moderate usage of `dart2native` and only on Linux. Turns out that there is demand for using it all over the place, which includes Mac and Windows and requires things like signing support... And to make executable signable we need to make them real Mach-O / PE executables and not weird concatenations of bytes.
- vbsteven 6y agoIIRC Flutter compiles your Dart source code to a native platform binary and uses Skia to render the UI. I assume the Flutter Desktop API provides abstractions for creating windows.
- gtirloni 6y agoThe docs[0] are pretty good. It looks like there is a concept of "embedder" that does the hard work. See [1]. 0 - https://flutter.dev/docs/resources/architectural-overview https://flutter.dev/docs/resources/architectural-overview 1 - https://github.com/flutter/flutter/wiki/Custom-Flutter-Engine-Embedders https://github.com/flutter/flutter/wiki/Custom-Flutter-Engin...