Skip to content

Commit 0789e09

Browse files
authored
[Dart 3.8] Add cross-compile support for exe and aot commands. (#6539)
## Sections updated: https://dart.dev/tools/dart-compile#exe https://dart.dev/tools/dart-compile#aot-snapshot ## Details: * Added an `Overview` heading. * Created a `Cross-compilation section for `dart compile exe` and `dart compile aot-snapshot`. * Updated `Known limitations` for `dart compile exe` and `dart compile aot-snapshot`. * Updated the top-most content in `dart compile aot-snapshot` to match the structure of the content in `dart compile exe`. ## Preview: * https://dart-dev--pr6539-dart-cross-compile-hpwvexhx.web.app/tools/dart-compile#exe * https://dart-dev--pr6539-dart-cross-compile-hpwvexhx.web.app/tools/dart-compile#cross-compilation-aot ## Notes: * Issue: #6540 * Don't launch documentation until Dart 3.8 release. * If you would like to test right now, you can do so on the beta branch. --- - [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR. - [x] This PR doesn't contain automatically generated corrections or text (Grammarly, LLMs, and similar). - [x] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style) — for example, it doesn't use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person). - [x] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer. <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide](https://github.com/dart-lang/site-www/blob/main/CONTRIBUTING.md) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Code changes should generally follow the [Dart style guide](https://dart.dev/effective-dart) and use `dart format`. - Updates to [code excerpts](https://github.com/dart-lang/site-shared/blob/main/packages/excerpter) indicated by `<?code-excerpt` need to be updated in their source `.dart` file as well. </details>
1 parent 8e842da commit 0789e09

File tree

3 files changed

+90
-28
lines changed

3 files changed

+90
-28
lines changed

site-shared

src/_includes/known-issues/compile-ki.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/content/tools/dart-compile.md

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ title: dart compile
33
description: Command-line tool for compiling Dart source code.
44
---
55

6+
This guide describes how to use the `dart compile` command
7+
to compile a Dart program to a target platform.
8+
9+
## Overview
10+
611
Use the `dart compile` command to compile
712
a Dart program to a [target platform](/overview#platform).
813
The output—which you specify using a subcommand—can
@@ -164,6 +169,50 @@ Run your compiled app from the `/tmp` directory:
164169
$ ./tmp/myapp
165170
```
166171

172+
#### Cross-compilation {: #cross-compilation-exe }
173+
174+
Cross-compilation to Linux x64 and ARM64 is supported on the
175+
following 64-bit host operating systems: macOS, Windows,
176+
and Linux.
177+
178+
To use cross-compilation, include the following flags:
179+
180+
* `--target-os=linux`: The target operating system
181+
for the compiled executable. The Linux operating system
182+
is supported at this time.
183+
184+
* `--target-arch=value`: The target
185+
architecture for the compiled executable. The value
186+
for this flag can be `arm64` (64-bit ARM processor)
187+
or `x64` (64-bit processor).
188+
189+
The following command demonstrates how to cross-compile a
190+
standalone executable for a 64-bit Linux system:
191+
192+
```console
193+
dart compile exe \
194+
--target-os=linux \
195+
--target-arch=x64 \
196+
hello.dart
197+
```
198+
199+
Internally, this command downloads additional Dart SDK
200+
binaries and caches them in the `~/.dart` directory. Here's
201+
a sample output with the `--verbose` flag included with
202+
the command:
203+
204+
```console
205+
Downloading https://storage.googleapis.com/dart-archive/channels/dev/signed/hash/...4864.../sdk/gen_snapshot_macos_arm64_linux_x64...
206+
Downloading https://storage.googleapis.com/dart-archive/channels/dev/raw/hash/...64e44.../sdk/dartaotruntime_linux_x64...
207+
Specializing Platform getters for target OS linux.
208+
Generating AOT kernel dill.
209+
Compiling /tmp/hello.dart to /tmp/hello.exe using format Kind.exe:
210+
Generating AOT snapshot. path/to/dir/.dart/3.8.0-265.0.dev/gen_snapshot_macos_arm64_linux_x64 []
211+
Generating executable.
212+
Marking binary executable.
213+
Generated: /tmp/hello.exe
214+
```
215+
167216
#### Signing
168217

169218
Executables created with `dart compile exe`
@@ -178,11 +227,21 @@ see the platform documentation for those operating systems:
178227
[`SignTool.exe` documentation]: https://docs.microsoft.com/dotnet/framework/tools/signtool-exe
179228
[Apple Code Signing guide]: {{site.apple-dev}}/support/code-signing/
180229

181-
#### Known limitations
230+
#### Known limitations {: #known-limitations }
231+
232+
The `exe` subcommand has the following known limitations:
233+
234+
* No support for `dart:mirrors` and `dart:developer`.
235+
For a complete list of the core libraries you can use,
236+
see the [Multi-platform][] and [Native platform][] library
237+
tables.
182238

183-
The `exe` subcommand has some known limitations:
239+
* Cross-compilation is supported, but the target is limited
240+
to Linux. For more information, see [Cross-compilation][].
184241

185-
{% include 'known-issues/compile-ki.md' %}
242+
[Multi-platform]: /libraries#multi-platform-libraries
243+
[Native platform]: /libraries#native-platform-libraries
244+
[Cross-compilation]: #cross-compilation-exe
186245

187246
### AOT modules (aot-snapshot) {:#aot-snapshot}
188247

@@ -195,24 +254,47 @@ For example, if you use macOS to create a `.aot` file,
195254
then that file can run on macOS only.
196255
Dart supports AOT modules on Windows, macOS, and Linux.
197256

257+
Compile your app and set the output file:
258+
198259
```console
199260
$ dart compile aot-snapshot bin/myapp.dart
261+
```
262+
263+
When successful, this command outputs the following:
264+
265+
```console
200266
Generated: /Users/me/myapp/bin/myapp.aot
201-
$ dartaotruntime bin/myapp.aot
202267
```
203268

204-
The `aot-snapshot` subcommand has some known limitations.
269+
Run your compiled app from the `/bin` directory:
205270

206-
{% include 'known-issues/compile-ki.md' %}
271+
```console
272+
$ dartaotruntime bin/myapp.aot
273+
```
207274

208275
To learn more, see the
209276
[`dartaotruntime` documentation](/tools/dartaotruntime).
210277

211-
212278
{% comment %}
213279
TODO: Get info from https://github.com/dart-lang/sdk/wiki/Snapshots
214280
{% endcomment %}
215281

282+
#### Cross-compilation {: #cross-compilation-aot }
283+
284+
Cross-compilation support for the `aot-snapshot` subcommand
285+
is the same as what is available for the `exe` subcommand.
286+
For more information, see
287+
[Self-contained executables (exe)][cross-compile-exe].
288+
289+
[cross-compile-exe]: #cross-compilation-exe
290+
291+
#### Known limitations {: #known-limitations-aot }
292+
293+
The `aot-snapshot` subcommand has the the same limitations
294+
as the `exe` subcommand. For more information, see
295+
[Self-contained executables (exe)][known-limitations-exe]
296+
297+
[known-limitations-exe]: #known-limitations
216298

217299
### JIT modules (jit-snapshot) {:#jit-snapshot}
218300

0 commit comments

Comments
 (0)