Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows Arm64] Update tool to target Arm64 on Arm64 hosts #129807

Open
Tracked by #62597
loic-sharma opened this issue Jun 30, 2023 · 7 comments
Open
Tracked by #62597

[Windows Arm64] Update tool to target Arm64 on Arm64 hosts #129807

loic-sharma opened this issue Jun 30, 2023 · 7 comments
Labels
a: desktop Running on desktop P3 Issues that are less important to the Flutter project platform-host-arm Building on an ARM-based platform platform-target-arm Targeting an ARM-based platform platform-windows Building on or for Windows specifically team-windows Owned by the Windows platform team tool Affects the "flutter" command-line tool. See also t: labels. triaged-windows Triaged by the Windows platform team

Comments

@loic-sharma
Copy link
Member

loic-sharma commented Jun 30, 2023

Background

See: https://flutter.dev/go/windows-arm64

Once #129805 lands, Arm64 hosts will be able to build x64 executables. These executables run using x64 emulation.

Solution

  1. Add Windows Arm64 to the HostPlatform and TargetPlatform enums
  2. Update the Flutter Windows plugin templates to show how to use the target architecture to bundle pre-built libraries
  3. If on Arm64 host and the "beta" or "stable" release channels, produce a warning that an x64 executable will be built.
  4. If on Arm64 host and the "master" release channel,
    1. Use Abi.current() to determine the target architecture
    2. Download Windows Arm64 artifacts
  5. Update Windows Arm64 devicelab tests: build, run, benchmark
@loic-sharma loic-sharma added platform-windows Building on or for Windows specifically a: desktop Running on desktop P3 Issues that are less important to the Flutter project platform-host-arm Building on an ARM-based platform platform-target-arm Targeting an ARM-based platform labels Jun 30, 2023
@loic-sharma loic-sharma added the tool Affects the "flutter" command-line tool. See also t: labels. label Jun 30, 2023
@loic-sharma loic-sharma changed the title [Windows Arm64] Update tool to target Arm64 on Arm64 machines [Windows Arm64] Update tool to target Arm64 on Arm64 hosts Jun 30, 2023
@dcharkes
Copy link
Contributor

@loic-sharma Please give me a ping when you want to land this, so that we can ensure the native assets support added in #134203 works for Windows arm64 as well. (Or if you land it earlier than that PR, I'll give you a ping on how to test the native assets on Arm64 Windows.)

@loic-sharma
Copy link
Member Author

loic-sharma commented Sep 19, 2023

@pbo-linaro is the contributor working on adding Windows Arm64 support.

@dcharkes It looks like the native assets support added by #134203 works already on Windows Arm64 machines thanks to x64 emulation. FYI we're still working on running tests on Windows Arm64 machines, your new tests won't run on Arm64 machines yet.

@pbo-linaro, Daco is working on adding "native assets", which is a new way to support native code in pub packages. From my understanding, this will be an alternative to Flutter's existing support for native plugins. The package author creates a build.dart file that uses the user's installed compilers to compile the native assets. For more information, see:

In #134203, Daco enabled the Flutter Windows build to use native assets using the x64 MSVC toolchain. To enable targeting Arm64, we will need to update the logic added by #134203 to use the correct MSVC toolchain depending on the host/target.

(Daco feel free to correct any details I may have gotten wrong!)

@pbo-linaro
Copy link
Contributor

Hi, I'm currently working on windows-arm64 support and managed to get native (x64, arm64) and cross compilation (x64 -> arm64 and arm64 -> x64) of flutter apps to work on my local branch.

One issue I'm investigating now is support for native_assets, where it fails because cl compiler can't be identified for arm64 architecture. After digging into this, I reached this native_toolchain_c/lib/src/native_toolchain/msvc.dart, and found that support need to be done here.

I don't think flutter project will accept a windows-arm64 enablement without native assets, so it would be nice if we could fix this together @dcharkes. Once native repository has correct support, I should be able to do the rest on flutter side.

@loic-sharma: Do you see native assets as something mandatory for first enablement?
@dcharkes: Do you think anything more beyond toolchain detection has to be done to support new windows-arm64 platform?

Thanks,
Pierrick

@dcharkes
Copy link
Contributor

Hi, I'm currently working on windows-arm64 support and managed to get native (x64, arm64) and cross compilation (x64 -> arm64 and arm64 -> x64) of flutter apps to work on my local branch.

🎉

One issue I'm investigating now is support for native_assets, where it fails because cl compiler can't be identified for arm64 architecture. After digging into this, I reached this native_toolchain_c/lib/src/native_toolchain/msvc.dart, and found that support need to be done here.

Yep, that sounds correct!

I don't think flutter project will accept a windows-arm64 enablement without native assets, so it would be nice if we could fix this together @dcharkes. Once native repository has correct support, I should be able to do the rest on flutter side.

Yes, please feel free to create PRs to the dart-lang/native repo to do toolchain detection. ❤️
I don't have access to an arm64 win machine myself. Neither do the GitHub actions have support for Windows arm64 as far as I know.
You should be able to have your local copy of the dart-lang/native packages and use a path dependency in the pubspec.yaml of flutter_tools to test your changes directly from flutter tools.

@dcharkes: Do you think anything more beyond toolchain detection has to be done to support new windows-arm64 platform?

I'm not aware of anything. The Abi.windowsArm64 is already in dart:ffi, and @rmacnak-google has been fixing corner cases recently. (There are some remaining corner cases: dart-lang/sdk#53829. If you run into a crash when doing an FFI call please give us a ping. But these are relatively uncommon cases: e.g. structs by value with specific struct sizes. This shouldn't stop you with implementing support for native assets for Windows arm64, as most tests just pass integer values.)

@pbo-linaro
Copy link
Contributor

Thanks for your reactive answer!

The advice about using a path in pubspec.yaml is what I was missing to try this locally, that should help.
I'll propose a PR to add support in native then.

@flutter-triage-bot
Copy link

The triaged-desktop label is irrelevant if there is no team-desktop label or fyi-desktop label.

@cbracken cbracken added the triaged-windows Triaged by the Windows platform team label Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: desktop Running on desktop P3 Issues that are less important to the Flutter project platform-host-arm Building on an ARM-based platform platform-target-arm Targeting an ARM-based platform platform-windows Building on or for Windows specifically team-windows Owned by the Windows platform team tool Affects the "flutter" command-line tool. See also t: labels. triaged-windows Triaged by the Windows platform team
Projects
None yet
Development

No branches or pull requests

5 participants