您现在的位置是:首页 > 文章详情

Dart 支持交叉编译

日期:2025-05-12点击:19

Flutter main channel 提供了一个新功能:支持交叉编译 Dart AOT 可执行文件

目前支持从 Windows 和 macOS 编译为 Linux 二进制文件:

  • --target-os=linux

  • --target-arch=value:目标体系结构,可以是 arm64(64 位 ARM 处理器)或 x64(64 位处理器)

例如 :dart compile exe --target-os=linux --target-arch=x64 hello.dart -o hello

目前,执行这个命令会下载额外的 Dart SDK 二进制文件,并将它们缓存在 ~/.dart 目录 :

 Downloading https://storage.googleapis.com/dart-archive/channels/dev/signed/hash/...4864.../sdk/gen_snapshot_macos_arm64_linux_x64... Downloading https://storage.googleapis.com/dart-archive/channels/dev/raw/hash/...64e44.../sdk/dartaotruntime_linux_x64... Specializing Platform getters for target OS linux. Generating AOT kernel dill. Compiling /tmp/hello.dart to /tmp/hello.exe using format Kind.exe: Generating AOT snapshot. path/to/dir/.dart/3.8.0-265.0.dev/gen_snapshot_macos_arm64_linux_x64 [] Generating executable. Marking binary executable. Generated: /tmp/hello.exe 

例如在 window 上通过 dart compile exe --target-os=linux  hello.dart -o hello 编译下方代码,然后到 linux 下执行,可以看到代码可以正常运行:

 void main() {   for (var i = 0; i < 10; i++) {     print('hello ${i + 1}');   } } 

你觉得 Dart 上的交叉编译是否会是刚需?

原文链接:https://www.oschina.net/news/349490
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章