Skip to content

How to Develop and Test TotalCross VM for Linux and Linux ARM

Antônio Alves M Neto edited this page Oct 17, 2021 · 5 revisions

Compiling and Testing TotalCross Virtual Machine for Linux/Linux ARM

First things first, in order to compile a virtual machine for Linux or Linux ARM, one need to install the following requirements on your machine:

  • Docker CE ;
  • CMake 3.5.1 or later installed (if you are building from the target platform);

Once you have all requirements installed will be able to build a TotalCross Virtual Machine and test.

Building the VM

Basically, to start building TotalCross VM for Linux and Linux ARM for testing, one just need two key elements: i) the libtcvm.so which represents our VM; and ii) the executable Launcher which loads the VM library and points the main tcz file of your application.

Using docker to build

The Dockerfiles and shell scripts required to build TotalCross for Linux take place on TotalCrossVM/docker, as you can see bellow:

TotalcrossVM/docker
├── amd64
│   ├── Dockerfile
│   ├── build
│   ├── build-docker.sh
│   ├── build.bat
│   └── cmake.sh
└── arm32v7
    ├── Dockerfile
    ├── build
    ├── build-docker.sh
    ├── build.bat
    └── cmake.sh

So, go the folder of the target architecture (cd TotalCrossVM/docker/${arch}) and execute the following steps:

  • Build the docker image: ./build-docker.sh;
  • Execute the build file that uses the image above: ./cmake.sh;

the build folder will take place at the same folder with the following structure:

build
├── CMakeCache.txt
├── CMakeFiles
├── Launcher
├── build.ninja
├── cmake_install.cmake
├── libtcvm.so
└── rules.ninja

The Launcher

Using CMake to build it natively

An alternative method for building the TotalCross VM for Linux and Linux ARM is to build it natively using CMake. Take note, this method requires you to build on the target platform, and have all the dependencies already installed on your machine:

  • SDL2;
  • Fontconfig 2.2 or greater;

Installing deps(on APT-based distros):

sudo apt-get install libsdl2-dev libfontconfig1-dev cmake

Installing deps(on Pacman-based distros):

sudo pacman -S sdl2 fontconfig cmake

First, download the TotalCross git repository: Either download the ZIP or clone it with git:

git clone https://github.com/TotalCross/totalcross.git

Now, through a terminal inside the repository we just downloaded, enter the TotalCrossVM folder and create a new folder for the output of the build and enter in it:

cd TotalCrossVM
mkdir build
cd build 

Here, CMake will generate both files for building and compiling TotalCross VM, as well as the compiled binaries for the VM and launcher for your current platform.

Finally, let's point at our upper directory as the source folder for CMake and just point to our current folder as the target directory for CMake to build:

cmake ../
cmake --build .

The build process may take a while, specially if you are building it on low-end hardware, and it will likely have some warnings, but as long as there are no ERRORS as output by the terminal, it should be fine

Verify if the build was successful and if the compiled VM and launcher are working properly, case not, check if all dependencies were satisfied by the build and if it still does not work despite all dependencies being satisfied, please enter in contact with us

But hopefully, with the build being successful the build folder should take the following structure, use the "ls" to check it

build
├── CMakeCache.txt
├── CMakeFiles
├── Launcher
├── third_party
├── cmake_install.cmake
├── libtcvm.so
└── Makefile

Testing the VM

To test the TotalCross Linux VM, one need to:

  • copy Launcher and libtcvm.so to a folder inside your target device, i.e, raspberry pi;
  • choose a TotalCross project to generate and copy tcz files to the same folder on your target device;
  • execute Launcher

To do the first step, let's clone our TCSample repo. Edit it's pom.xml to only generating the TotalCross Zip Files (tcz) by deleting platforms tag (lines ~ 59-63).

- <platforms>
-    <platform>-android</platform>
-    <platform>-linux</platform>
-    <platform>-linux_arm</platform>
- </platforms>

Run mvn package and the tcz files will take place at target folder.

target
└── install
    ├── linux
    └── linux_arm

The final folder on your target device will have the follow structure:

.
├── Launcher
├── libtcvm.so
├── Material_Icons.tcz
├── TCBase.tcz
├── TCFont.tcz
├── TCSample.tcz
└── TCUI.tcz

Execute the following command to test: ./Launcher TCSample