Deploying FireMonkey to HTML5 with FMXLinux on WSL2
The absolutely quickest way to get started with Linux deployment from Delphi is to use the Windows Subsystem for Linux (WSL). As of Windows 10 Version 2004 (Build 19041) WSL2 includes a full Linux kernel, so debugging and everything works as expected.
- Install WSL2 (You can verify your build number via the System Information applet, but Build 19041 has been available for a while now.)
- Control Panel
- Programs
- Turn Windows features on or off
- Windows Subsystem for Linux
- Reboot
- Install Ubuntu via the Microsoft Store – Ubuntu without version # is the current LTS version and will update in the future. There are other distributions (Kali, Pegwin, Alpine WSL, etc.), but they are all a little different.
- Launch Ubuntu – Via the Start Menu or from a PowerShell/Terminal/CLI window with the
WSL
orUbuntu
commands. If you have more than one Linux installed then WSL launches the default one. The first time you launch it be aware it will take a few minutes, and then prompt you for new Linux credentials. - Run SetupUbuntu4Delphi21.sh – I made a script on gist that does all the setup for Ubuntu to get it ready to target from Delphi. You can use
wget
to download it or you can type the commands manually. It creates a script file called pa21.sh in your home folder to quickly launch PAServer. You can modify it to pass default configuration settings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#!/bin/bash echo Updating the local package directory sudo apt update echo Upgrade any outdated pacakges sudo apt full–upgrade –y echo Intall new packages necessary for Delphi sudo apt install joe wget p7zip–full curl openssh–server build–essential zlib1g–dev libcurl4–gnutls–dev libncurses5 xorg libgl1–mesa–dev libosmesa–dev libgtk–3–bin –y echo Clean–up unused packages sudo apt autoremove –y cd ~ echo Downloading LinuxPAServer for Sydney 10.4 (21.0) Update 1 wget https://altd.embarcadero.com/releases/studio/21.0/1/PAServer/LinuxPAServer21.0.tar.gz echo Setting up directories to extract PA Server into mkdir PAServer mkdir PAServer/21.0 tar xvf LinuxPAServer21.0.tar.gz –C PAServer/21.0 —strip–components=1 rm LinuxPAServer21.0.tar.gz echo #!/bin/bash >pa21.sh echo ~/PAServer/21.0/paserver >>pa21.sh chmod +x pa21.sh echo —————————————————– echo To launch PAServer type ~/pa21.sh echo —————————————————– ~/pa21.sh |
- Install FMXLinux from GetIt
- Run the
broadwayd
server – You should already havepaserver
running (the script above launched it), so you will probably want a new Ubuntu terminal window where you can launchbroadwayd
. I like using the new Windows Terminal since it makes it easy to open multiple tabs, and WSL integrates with it nicely.
- Import Linux SDK in Delphi IDE – Tools > Options > Deployment > SDK Manager – The IP address for the PAServer instance is localhost /
127.0.0.1
, so keep in mind you are sharing ports between the WSL instance and your host Windows 10 OS.
- Now is just a matter of running most any FireMonky project and connecting to
localhost:8080
from your browser.
One thing to keep in mind is there is one instance of the app running on the server for each client, and each has its own port number. There are ways to manage this on the server with a little effort, but that is a blog post for another day.
https://embt.co/3oFnZVW