[how to] Setup Go 1.4.2 / 1.5 / 1.6 runtime and go-qml pkg for MerSDK
Hi sailors,
the first Go-compiled application (Dewpoint Calculator) has hit harbour and I was kindly asked how to setup build environment to get Go and go-qml bindings to work.
There where a few hurdles to take and things to modify on MerSDK to archive this goal plus patching the original go-qml package to get bindings to work with Silica UI.
To make things easy for you I created a setup script that can be found at https://github.com/nekrondev/jolla_go.
Prerequirements:
- Virtualbox has been installed
- you have a vanilla (unmodified) MerSDK VM
- you can ssh into MerSDK with user mersdk (ssh mersdk@localhost, you have to generate a public/private keypair and add it to your keyring and MerSDK public keys (location depends if you are on linux or win))
Getting started:
- ssh into MerSDK using mersdk user
- at mersdk's home directory clone my github repository with "git clone https://github.com/nekrondev/jolla_go.git ~/"
- opt: modify proxy-settings at beginning of mersdk_jolla_go.sh script if you are behind a proxy
- launch setup script "./mersdk_jolla_go.sh"
- take a nap until setup completed
- launch upgrade script "./mersdk_jolla_go15_upgrade.sh" to build Go 1.5 runtime with upgraded go-qml package
- take another nap
This will take some time since all needed sources and zypper packages will be downloaded, compiled and installed for MerSDK and ARM target.
Example code:
Once everything is up and running you may investigate ~/src/dewpointcalc to see a working GO QML application (Dewpoint Calculator). You can build the RPM for i486 by executing "mb2 build". To create the RPM for Jolla (ARM target) simply launch "mb2 -t SailfishOS-armv7hl build". Compilation of go code stand-alone can be done by "go build". To deploy i486 RPM to a running SailfishOS EMU VM type "./deploy".
Pro hints:
I made a few changes to the go-qml package to make it working for Silica UI. One problem was that by using a coverpage and switching to coverview the original go-qml bindings would close the application. I fixed this by adding a custom event filter to QQuickWindow. Next I wanted to have my application i18n-ready. Therefore I added a new CPP method newTranslator() that can be fired from your go code by calling the engine types function "Translator(path to i18n files)". The newTranslator() CPP method will load the correct locale based on your phones system locale settings. To launch your application on the Emu for a different system locale ssh into Emu as user nemo and fire your application by including the language, i.e. "LANG=de_DE.UTF8 harbour-dewpointcalc" for German language. I also added packing/unpacking of QDateTime to go type time.Time which is missing from the orignal go-qml package. Vim has been modded with plugins for go and qml. From vim you can type :GoBuild to build your application plus many more (see go-vim docs). Long running controller threads can be fired as go routines, unblocking your QML GUI. QML objects should be tagged with "objectName: "myObj"" so they can be found from the controller by ObjectByName("myObj") function. Do not forget to strip your binary to get a smaller executable (-ldflags "-s"). The .desktop file must contain X-Nemo-Application-Type=generic to get launched by invoker.
Cover action quirk
[UPDATED] CoverActions are not working for standard QQuickWindow which is used by Go qml bindings -- so your application currently can not use cover actions --> fixed with new go-qml_jolla.patch from my github repository (please note you have to install additional packages: sudo zypper -n install -t pattern "sailfish-silica-devel"). To initialize your Sailfish Go application do the following things:
From main() call if err := qml.SailfishRun(run); err != nil { ... qml.SailfishRun() is a new method to launch a SailfishApp:: instance.
Initialize the engine with qml.SailfishNewEngine()
Load your main.qml file with control := engine.SailfishSetSource("qml/main.qml") (note: you have to use the path relative to the sailfishapp installation, i.e. /usr/share/harbour-xxxx/path to qml from here)
Create your app window with window := control.SailfishCreateWindow()
Finally show your application window with window.SailfishShow()
After view has been rendered save rootobject (used for ObjectByName() to locate QML objects to manipulate via go-qml bindings)
Happy hacking!
Cheers, Nekron
Update 20150828:
Updated go-qml patch to initialize a "pure" SailfishApp with cover actions (see quirks above)
Update 20150820:
Added additional upgrade script for Go 1.5 into repository (you can now upgrade from your Go 1.4.2 setup to Go 1.5 if you like)
Update 20160405:
Updated repository with go runtime 1.6 upgrade script, new go1.6 mersdk patch and updated go-qml bindings working for go1.6 onwards (no pointer to pointer cgo panics anymore!).
Really excellent. Thank you. Richard
richardski ( 2015-08-19 09:09:25 +0200 )editThank you very much!
magullo ( 2015-08-19 13:20:13 +0200 )editI was thinking about doing something like this myself actually, but i decided to wait for go 1.5 since it makes cross compiling a lot easier.
Do you have an example app?
slaveriq ( 2015-08-19 13:43:04 +0200 )editThank you!
BirdZhang ( 2015-08-19 15:02:53 +0200 )edit@slaveriq: I included Dewpoint Calculator which shows the use of Translator and interactions between controller (go) and view (qml). Actually to get Go 1.5rc1 running on your Jolla/MerSDK, you need to have go1.4 installed to build the binaries. It is also needed to patch go1.5 to build go binary even if there are sym# errors.I just gave it a try and go1.5rc1 compiles fine on MerSDK. Once 1.5 has been finally released I will add an additional upgrade script.
Nekron ( 2015-08-19 15:41:49 +0200 )edit