Thursday, November 27, 2014

virt-viewer (using gtk3) for Windows

For the last few weeks I've been spending some time to have virt-viewer,
using gtk3, running on Windows. And it finally works!

Here is a not so brief description about the projects that I've hacked on (and the problems I've faced out during the process). if you're not interested in the process, just scroll down till the end of the email, where you will find the installer and a few instructions about what you need to generate the installer by yourself.

- msitools:
Apart from the broken build system on F21[0] and the wixl-heat generating the same ID for dirs used by other libraries/components[1] I have added .wxi files for the virt-viewer dependencies in order to have a build using gtk3. The dependencies are basically 3: 
- gtk3 itself[2]
- spice-gtk3[3]
- gtk-vnc2[4].
All the .wxi files were generated following the "How To" in the msitools webpage[5].
[0]: https://git.gnome.org/browse/msitools/commit/?id=c4c397438b797de4e68bb6d7fb891872db9e7bab
[1]: https://git.gnome.org/browse/msitools/commit/?id=41db587bae5a6c4cbc8f40a52bf2d6f25416653f
[2]: https://git.gnome.org/browse/msitools/commit/?id=c03676f95a348fd7da511355398f3a073400f819
[3]: https://git.gnome.org/browse/msitools/commit/?id=08cdc65a46f9eaaf49cd0acde0c3aaead341973d
[4]: https://git.gnome.org/browse/msitools/commit/?id=19c465b9f89583cdc905609abfd9cfb2c6beb26f
[5]: https://wiki.gnome.org/msitools/HowTo/CreateLibraryWxi

- virt-viewer:
Once that msitools has all the necessary bits included, it is time to hack a bit on virt-viewer and provide a way to generate the .msi file for virt-viewer using gtk3[6]. It is quite simple and basically a copy and paste from the file we already have been using for gtk2. just changing the dependencies and installation folder (just to avoid myself getting confused with the versions and so on).
[6]: https://fedorapeople.org/cgit/fidencio/public_git/virt-viewer.git/commit/?h=wip/msi-gtk3&id=4495b42a23ba5a795185bea0cadc540126b58751

After generate and install the .msi file on my Windows VM I crossed my fingers and ran remote-viewer!
Well, the results were not exactly the expected ones. A crash in libGdk-3.0.dll with no more info could be seen and also a lack of icons.

Okay, okay. First things first. Let me try to hunt this crash. Where can I start from? Hmmm. What about getting a debugger? :-)

- gdb:
Just got the binary from the mingw sourceforge webpage[7]
[7]: http://sourceforge.net/projects/mingw/files/MinGW/Extension/gdb/

Now I have the gdb, let me hunt the crash!
gdb.exe remote-viewer.exe ... and more problems! There were no debug-symbols in any of the packages I've been using ... and I need them!

- debugging:
 - approach 1 - -debug packages are your friends: well, not always. I've
installed the -debug packages and have added the new installed files
into the respective .wxi files. Then I've generated a new build and ... same crash, same poor info I had before (and nothing more). :-(
 - approach 2 - compile everything by yourself: this is what worked for me, but we have to agree that it's not exactly the most handy thing to do when you just want to debug something. Also, it inserted new bugs when launching the application, something about missing files that, for sure, were in the correct path. Anyways, it helped me to debug and I found that the Gdk crash could be avoided with a simple patch on spice-gtk[8].
[8]: http://cgit.freedesktop.org/spice/spice-gtk/commit/?id=b0703419bf15facc0527a81afbb3b07e67de909b

Yay! Now I have the virt-viewer working, but still no icons (apart from
the ones provided by virt-viewer itself).

For the icons problem, here is the basic solution:
- Build the .msi file using only the needed icons from the system installed adwaita-icon-theme. It works pretty well for virt-viewer, but if any other app tries to take advantage of the gtk3 on Windows, the app *must* have to do the same.

Yay, again! virt-viewer shows all the icons! Let's do some tests ... I've started by clicking in the menu options. The first one: "File -> Screenshot" ... and then crash!
Okay, this is an easy one. Basically I had to include the schemas.compiled[9] and schemas.dtd[10] into our gtk3 .wxi file, They are not being included because these files are not distributed with the .rpm, they are generated during the rpm's installation process.
[9]: https://fedorapeople.org/cgit/fidencio/public_git/msitools.git/commit/?h=wip/gtk3&id=e8990a125537ead4fad5d1adedc028cd72f5c932
[10]: https://fedorapeople.org/cgit/fidencio/public_git/msitools.git/commit/?h=wip/gtk3&id=97eefd9a3279a1766c81e54b0eb0e5660fece737

And now, finally, we are able to have a functional build of virt-viewer for windows using gtk3!

Do you want to try the build?
https://fidencio.fedorapeople.org/virt-viewer-gtk3-x86-2.0.msi
https://fidencio.fedorapeople.org/virt-viewer-gtk3-x64-2.0.msi

Do you want to build it by your self?
Okay, you'll need to:
- mingw-spice-gtk with my patch (build already pushed to f21):
https://fidencio.fedorapeople.org/mingw-spice-gtk/

- virt-viewer with my patches:
https://fedorapeople.org/cgit/fidencio/public_git/virt-viewer.git/log/?h=wip/msi-gtk3

Compile and install msitools from git. Install mingw-spice-gtk and gtk-vnc2 packages. Then, inside the virt-viewer folder, do:
 $ mingw32-configure --with-spice-gtk --with-gtk=3.0
 $ make
 $ make -C data/ msi-gtk3

Next steps:
- generate the gtk2 or gtk3 build according to the configure options.
- add support for foreign menu for Windows.

3 comments:

  1. Hi, I was looking on the internet for a virt-viewer build with USB support on Windows client and happened to find your blog. Do you know why usb support is disabled in windows builds? Thanks

    ReplyDelete
  2. is there also an msys2 build (https://sourceforge.net/projects/msys2/) (not updated)

    ReplyDelete
  3. Thank y very much for this blog, also for this article, I can't find it in the internes already a long time.

    Best regards
    Toby, due diligence data room

    ReplyDelete