Developing on Windows, but building on Linux with WSL

August 23, 2024

If you want to develop applications with Model RealTime on Windows, but build them for Linux you have a few options:

However, another approach, which we will look at in this newsletter, is to use the Windows Subsystem for Linux (WSL). WSL is a feature in Windows that allows to run a Linux kernel inside a lightweight virtual machine. It has been specifically designed for developers that need to run both Windows and Linux seamlessly on the same machine, without the need for a separate virtual machine or dual booting.

Install Model RealTime on WSL

The easiest way to install Model RealTime on WSL is to use the Install Product script. It downloads and installs all prerequisites of Model RealTime, such as an appropriate version of Java, and then installs Model RealTime itself. Before running the script, the environment variable RT_INSTALL_BASE should be set to specify a folder where to place everything that is downloaded and installed. Also, you need to make sure the script has executable permissions (this may depend on if you downloaded the script to a Windows or Linux folder). If needed, use the command chmod a+x installProduct.sh to give the script executable permission.

Here is an example where Model RealTime, and all its prerequisites, will be installed in the user home folder under model-rt-install:

export RT_INSTALL_BASE=~/model-rt-install
./installProduct.sh hcl-model-realtime-12.0.2-v20240610_1628_product.zip

If you want to place the Model RealTime installation somewhere else, you can give that path as an additional parameter for the script. Note that your Windows drives are available in WSL under /mnt/ so a command similar to the one below could be used for installing Model RealTime at C:\mrt-installations\wsl:

./installProduct.sh hcl-model-realtime-12.0.2-v20240610_1628_product.zip /mnt/c/mrt-installations/wsl

Refer to the documentation for all options provided by the script.

Run the Model Compiler on WSL

Even if it's possible in recent versions of WSL to run Linux GUI applications it's enough with the command-line for building with the Model Compiler. Crafting the command-line to use can take a little time, but once done you just need to invoke it any time something was changed in the model or the TC, to run the build again.

As a starting point for creating the command-line you can first build your Linux TC on Windows. The build will fail, of course, since the TC is for Linux, but in the Model Compiler console you can copy the command for running the build from the command-line:

Make some modifications to the copied command:

  1. Replace the path to Java in the beginning of the command. If you let the Install Product script install Java at the default location, it will be available in WSL at ~/Install/JAVA_17/bin/java.
  2. Remove command arguments that specify default values. This is not strictly necessary, but gives you a much shorter command-line to use since most arguments often have their default values.
  3. Replace Windows paths with WSL paths. For example, replace C:/ with /mnt/c/.
  4. Add the -DRTPerlVariable argument to specify the location of Perl. By default a special version of Perl, called rtperl, is used during the build. The version of rtperl that comes with the Model RealTime installation does not work on WSL. Instead it's recommended to use the standard Perl tool which typically is available at /usr/bin/perl.

Here is an example of what a typical command for running the Model Compiler on WSL could look like:

~/Install/JAVA_17/bin/java -Xmx4024m -DRSA_RT_HOME=/mnt/c/mrt-installations/wsl/rsa_rt -DRTPerlVariable=/usr/bin/perl -Dworkspace_loc=/mnt/c/eclipse-workspace/rt-12-0-2-workspace -Djava.library.path=/mnt/c/mrt-installations/wsl/plugins/com.ibm.xtools.umldt.rt.core.tools_1.50.0.v20240610_1628/tools/modelcompiler_lib -jar /mnt/c/mrt-installations/wsl/plugins/com.ibm.xtools.umldt.rt.core.tools_1.50.0.v20240610_1628/tools/modelcompiler.jar --root /mnt/c/eclipse-workspace/rt-12-0-2-workspace --licenseFile=/mnt/c/Users/MATTIAS.MOHLIN/rtist-license.bin --out=/mnt/c/eclipse-workspace/rt-12-0-2-workspace --build /mnt/c/eclipse-workspace/rt-12-0-2-workspace/MyApplication/unix.tcjs

Refer to the Model Compiler documentation for a full list of all command-line arguments that are available.

Run and Debug the Application

You can directly run the application that is built in WSL. For example:

./executable -URTS_DEBUG=quit

You can use the Model Debugger for debugging the application on Windows. WSL shares the IP address of the Windows host so you can directly access the ports you need, such as the debug port. If you, for example, launch your application like this on WSL

./executable -obslisten=12345

you can then right-click on your Linux TC in Model RealTime and do Debug As - Remote RealTime Application (Attach), enter the port in the dialog and start to debug the application in the same way as if it was built on Windows.