Skip to content

Instantly share code, notes, and snippets.

@asmaier
Last active February 26, 2025 09:53
Show Gist options
  • Save asmaier/e1a4313e8f365b4a8f8dd9719561dcbe to your computer and use it in GitHub Desktop.
Save asmaier/e1a4313e8f365b4a8f8dd9719561dcbe to your computer and use it in GitHub Desktop.
Cross-compiling Flet app on ARM Mac for x86 Windows

Overview

So you are a Python developer using MAC with ARM (M1 - M4) processors, but you need/want to develop a desktop app with https://flet.dev/ for x86 on Windows?

Then you came to the right place. But buckle up, it will be a bumpy ride!

VMWare Fusion

Since https://github.com/dockur/windows is not supported for Mac you will need a different solution to run Windows on Mac. And if you don't want to pay money for Parallels, I recommend to use VMware Fusion. It should be noted though, that VMware Fusion will only allow to install the ARM Version of Windows. We will work around this issue in the end, but if you want to avoid that trouble, you should use Parallels, because it offers to fully emulate a x86 version of Windows on a Mac with (AR)M processor. Installation of VMware Fusion on Mac is easy though

$ brew install vmware-fusion

Windows

To install Windows with VMware Fusion just follow the guide.

During the Windows 11 installation process you will be promted you create an account with Microsoft. To avoid that you can disconnect the network adapter from the VM and then follow the instructions here.

VMware Tools

After the Windows installation process finished I recommend to install VMware tools from VMware Fusions Virtual Machine Menu. Select "complete" as setup type so drag-and-drop functionality is installed.

Load root certificate store

If you have still deactivated the network adapter for your VM, activate it now. Then open the powershell terminal on your Windows VM an type

curl https://www.google.com

This will trigger the lazy loading of the root certificate store on Windows and will avoid connection issues you might run into if you don't do this. See

Activate Developer mode

In the windows powershell terminal type

start ms-settings:developers

and activate the developer mode as decribed at https://flet.dev/docs/publish/windows#enable-developer-mode .

Install necessary software packages

With winget in the powershell terminal on your Windows VM we will install git, Python, the package manager uv and the Visual Studio Desktop Development workload (see https://flet.dev/docs/publish/windows#visual-studio-2022) with

winget install -e --id Git.Git
winget install -e --id Python.Python.3.11
winget install -e --id=astral-sh.uv
winget install Microsoft.VisualStudio.2022.Community --silent --override "--wait --quiet --add ProductLang En-us --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended"

At this point all requirements for flet/flutter have been installed. I recommend to make a snapshot of your VM at this point.

Install flet/flutter

Start a new terminal (so all your installed software is loaded in your path) and create a flet test app

uv init flet_test --bare
cd flet_test
uv add flet[all]   # this will install flet into your uv venv, it makes different flet versions possible for different uv projects
uv run flet create
uv run flet run

At this point a window with the example app should have opened. Close it and create a window exe from your app with

uv run flet build windows

This will download and install flutter and package your app to a windows app . The app will have about 1100 files and be 70 MB (compressed 30MB) big, thanks to the magic of flutter.

To check if this was successful you can start the exe with

start .\build\windows\flet_test.exe

Make your ARM app run on x86

If you now would zip your app directory and start it on a x86 Windows machine it would fail with an "helpful" error 0xc0000142. But don't despair. The solution is simple. In your app folder delete the three files

  • vcruntime140.dll,
  • vcruntime140_1.dll
  • msvcp140.dll

This will make your app run on x86 (see flutter/flutter#129808 (comment)), because the app will simply use the DLLs that come with your x86 Windows instead.

SUCCESS!

Why does that work at all?

At the time of writing this gist flutter still doesn't support ARM natively. Instead it will build and run x86 code also on ARM:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment