dart-lang / dart-lang/sdk

Add an option to specify `dartaotruntime` for `dart compile exe`

Open
#61,374 1 comment 2 reactions 1 assignee Claimed by @rmacnak-google View on GitHub
area-vm triaged type-enhancement
Dominant language
Dart
Stars
11.3k
Forks
1.9k
PR merge metrics
PR metrics pending

Description

First of all, it's great to see cross-compiling aot-snapshot is getting gradually supported in https://github.com/dart-lang/sdk/issues/28617. We have investigated on how to use new cross-compiling feature in https://github.com/google/dart_cli_pkg, and hit a blocker.

The Dart SDK officially supports only glibc on linux, but there is community supported musl-libc variant available at https://github.com/dart-musl/dart. The Dart SDK itself cannot tell the difference between the two libc variants, and treat them as the same linux platform. However, in `cli_pkg` we implemented logic to distinguish the two and thus allow users to create standalone distributable for both glibc and musl-libc.

For `dart compile aot-snapshot`, the output of the same sdk version for same architecture appears to be interchangeable for glibc and musl-libc. I can create an `aot-snapshot` on `linux_arm64` (gnu) and run it with `dartaotruntime` on `linux_arm64` (musl) without any issue, and vice versa. In other words, the generated aot-snapshot isn't strictly tied to the libc, unless there are libc specific ffi/native calls in the application code.

For `dart compile exe`, it becomes problematic because the `dartaotruntime` binary is libc specific. To compile an `exe` from `linux_arm64` (gnu) to `linux_x64` (musl), I can hack it by manually swapping the `dartaotruntime_linux_x64` file in the sdk cache to musl-libc version, and then `dart compile exe` will generate a working binary for `linux_x64` (musl). However, this hack won't work for `linux_arm64` (gnu) to `linux_arm64` (musl), as Dart SDK treat them as the same platform, thus will use the `dartaotruntime` from current sdk without using sdk cache.

Therefore, I'd like to request a new feature that allow us to specific the location of `dartaotruntime`. Again, an option to specific location of sdk cache won't fully work, unless the `dartaotruntime` for the current platform in the sdk cache (currently it does not exists) can take precedence over the file bundled with dart sdk.

---

Note: Dart SDK currently hard codes the download path from storage.googleapis.com, meaning on dart-musl/dart-android it will not be able to download the correct cross-compiler. However, these files can be download manually:

- `https://storage.googleapis.com/dart-archive/channels/${channel.name}/${stage.name}/$version/$path`
- `https://github.com/dart-musl/dart/releases/download/$version/$path`
- `https://github.com/dart-android/dart/releases/download/$version/$path`

The "path" part looks like:

- `dartaotruntime_${target_os}_${target_arch}`
- `gen_snapshot_${host_os}_${host_arch}_${target_os}_${target_arch}`

These files are downloaded to:

- `$HOME/.dart/dartdev/sdk_cache/$version/$path`

---

@nex3 @sstrickl

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.