Building Sailfish OS packages manually
Sailfish OS provides a streamlined developer experience through the Sailfish IDE. At the moment it only provides for projects that are built with qmake. This might cause problems especially when porting over existing applications that use a different build system. Some developers might also prefer to use a different editor environment. This document aims to describe the steps to build an application manually using the Sailfish OS build machine that comes with the SDK. We use CMake in this document but the steps to take are roughly the same for any build setup.
The first thing you need to do is to install the Sailfish OS SDK. It can be downloaded from Sailfish OS development site. Next you should check out the sample application inside your home directory from this git repo. Now you can run Virtualbox and it should show both the build machine and the emulator as shown below.
You are now ready to install all the build dependencies that your software requires. We recommend declaring them in the spec file so they get installed automatically when you build your package with the
mb2 command described below. For this example it only consists of CMake. Note that you should not log in to the machine from the terminal but instead always connect to it via SSH. You can minimize the VirtualBox window as you won’t need it for the actual work. Log in to the machine using SSH:
ssh -p 2222 -i ~/SailfishOS/vmshare/ssh/private_keys/engine/mersdk mersdk@localhost
Before going further let’s verify that everything is properly installed and that we are logged in the correct machine. Issue the following command:
This should provide the following output:
This means that the build machine can build packages for both ARM and i486 platforms. The former is used for the device whereas the latter is for the emulator. We want to use both so we need to install CMake for both of these target types. This is achieved with the following two commands:
sb2 -t SailfishOS-armv7hl -m sdk-install -R zypper in cmake
sb2 -t SailfishOS-i486 -m sdk-install -R zypper in cmake
Building the packages
The SDK has set up VirtualBox shared folders so that your home directory is visible inside the build machine. You can find it in the directory
/home/src1. The first step in starting the build is to go inside your project checkout. That can be accomplished with the following command:
Now you are ready to build the emulator and device packages. If you have set up a spec file the commands are simple.
mb2 -t SailfishOS-i486 build
mb2 -t SailfishOS-armv7hl build
Once the build finishes, you can find the RPM packages in the RPMS directory. If you wish to build your project manually, just wrap your own build commands with sb2 like this:
sb2 -t SailfishOS-i486 -m sdk-build cmake [cmake options]
sb2 -t SailfishOS-i486 -m sdk-build make
Now you can log out of the build machine.
Running the package in the emulator
It is very strongly recommended that you only deploy your application to the emulator and device as an RPM package. The following instructions only cover this case. Start the emulator with the VirtualBox. It will boot up and look like this.
To transfer the RPM to the emulator, issue the following command.
scp -P 2223 -i ~/SailfishOS/vmshare/ssh/private_keys/SailfishOS_Emulator/root \
Then log in the machine.
ssh -p 2223 -i ~/SailfishOS/vmshare/ssh/private_keys/SailfishOS_Emulator/root \
Install the RPM with the following command:
rpm -i cmakesample-1.0-1.i486.rpm
This causes the application icon to appear in the menu.
Congratulations, you have successfully built a Sailfish OS application with a custom build system.
Deploying and running the app on the device
Deploying on the device is straightforward. First you need to set the device to developer mode and transfer the RPM file to the device.
scp cmakesample-1.0-1.armv7hl.rpm email@example.com:
Then you can to log in to the device and become root.
ssh -lnemo 192.168.2.15
The last step is to install the package:
rpm -i cmakesample-1.0-1.armv7hl.rpm
Now your application has appeared in the list of installed applications and is ready to be run.