I'm trying to build a Vala program with flatpak. I need to connect to a mysql-server and thats why i need to bundle libmysqlclient
with my flatpak.
Thats why I added mysql_config
to my meson.build file.
project('zeiterfassunggtk', ['c', 'vala'], version: '0.1.0',
meson_version: '>= 0.40.0',
)
i18n = import('i18n')
mysql_config = find_program('mysql_config')
mysql_vapi = meson.get_compiler('vala').find_library('mysql')
mysql_dep = declare_dependency(c_args: run_command([mysql_config, '--cflags']).stdout().split(),
link_args: run_command([mysql_config, '--libs']).stdout().split(),
dependencies: [mysql_vapi])
subdir('data')
subdir('src')
subdir('po')
meson.add_install_script('build-aux/meson/postinstall.py')
The problem now ist that mysql_config is not available in the flatpak runtime. So I need to bundle it with my flatpak.
The Flatpak documentation however was not very helpful for me.
Modules
The module list specifies each of the modules that are to be built as part of the build process. One of these modules is the application itself, and other modules are dependencies and libraries that are bundled as part of the Flatpak. While simple applications may only specify one or two modules, and therefore have short modules sections, some applications can bundle numerous modules and therefore have lengthy modules sections.
GNOME Dictionary’s modules section is short, since it just contains the application itself, and looks like:
"modules": [ { "name": "gnome-dictionary", "sources": [ { "type": "archive", "url": "https://download.gnome.org/sources/gnome-dictionary/3.26/gnome-dictionary-3.26.0.tar.xz", "sha256": "387ff8fbb8091448453fd26dcf0b10053601c662e59581097bc0b54ced52e9ef" } ] } ]
As can be seen, each listed module has a name (which can be freely assigned) and a list of sources. Each source has a type, and available types include:
archive - .tar or .zip archive files git - Git repositories bzr - Bazaar repositories file - local file (these are copied into the source directory) dir - local directory (these are copied into the source directory) script - an array of shell commands (these are put in a shellscript file) shell - an array of shell commands that are run during source extraction patch - a patch (are applied to the source directory) extra-data - data that can be downloaded at install time; this can include archive or package files
Different properties are available for each source type, which are listed in the Flatpak Builder Command Reference.
Can someone tell me how to add libmysqlclient
to my flatpak and how to use mysql_config
to set the correct compiler flags for my flatpak.
This is my manifest (the gnome-builder default):
{
"app-id" : "org.gnome.Zeiterfassunggtk",
"runtime" : "org.gnome.Platform",
"runtime-version" : "3.28",
"sdk" : "org.gnome.Sdk",
"command" : "zeiterfassunggtk",
"finish-args" : [
"--share=network",
"--share=ipc",
"--socket=x11",
"--socket=wayland",
"--filesystem=xdg-run/dconf",
"--filesystem=~/.config/dconf:ro",
"--talk-name=ca.desrt.dconf",
"--env=DCONF_USER_CONFIG_DIR=.config/dconf"
],
"build-options" : {
"cflags" : "-O2 -g",
"cxxflags" : "-O2 -g",
"env" : {
"V" : "1"
}
},
"cleanup" : [
"/include",
"/lib/pkgconfig",
"/man",
"/share/doc",
"/share/gtk-doc",
"/share/man",
"/share/pkgconfig",
"/share/vala",
"*.la",
"*.a"
],
"modules" : [
{
"name" : "zeiterfassunggtk",
"buildsystem" : "meson",
"config-opts" : [
"--libdir=lib"
],
"builddir" : true,
"sources" : [
{
"type" : "git",
"url" : "file:///home/g.zehetner/Projekte/ZeiterfassungGtk"
}
]
}
]
}
Flatpak aims to distribute applications on Linux by using containerization technologies. This allows Flatpak to be independent of current distributions like Ubuntu and Fedora. It seems, however, the person creating a Flatpak needs to develop some of the skills of a distribution packager. Dependencies for a Flatpak are placed in the
modules
section of manifest and these will be built and included in the Flatpak. What follows is untested so some details may be missing, but it aims to give an overview of the ideas to help. There are a few options:libmariadb
MariaDB is a fork of MySQL. Forked by the community after concerns over Oracle Corporation's acquisition of MySQL. I've listed this first because it seems the easiest option, at least in the longer term.
MariaDB has releases of
mariadb-connector-c
on GitHub. For some reason GitHub doesn't show checksums for these releases. So the MariaDB Foundation's download section is a better option here.mariadb-connector-c
can connect to both MariaDB and MySQL.From looking at the source code the build system for
mariadb-connector-c
is CMake. There are options in the CMakeLists.txt file likeWITH_SSL
that you may need, but the manifest snippet below ignores the use ofconfig-opts
. This Flatpak GitHub issue may have a relevant example on how to useconfig-opts
for a CMake build.So we have a source release, a checksum and we know the build system. By adding something like this to the
modules
section of your manifest you should be able to include a build ofmariadb-connector-c
in your Flatpak:This also misses out the
cleanup
key.The main problem is getting this to work with your Vala application. The
pkg-config
file is calledlibmariadb.pc
. So your VAPI will need to be renamed tolibmariadb.vapi
. You can copy themysql.vapi
from/usr/share/
to your local application source directory and rename is aslibmariadb.vapi
. You will need to adjust yourmeson.build
to include that as a VAPI search directory and you should no longer need to search formysql_config
.pkg-config
will do the job ofmysql_config
instead.It looks like MySQL C header files remain a part of
maria-connector-c
. Fingers crossed it will just work. There are additional symbols in C headers that are MariaDB specific. If you want to modify the VAPI read Writing a VAPI Manually. Please consider submitting your enhancements to the Vala mainline repository afterwards.mysqlclient
MySQL appears to require the download of the server just to build the client. I started with this page, titled Download Connector/C (libmysqlclient). This advises the Linux 'Client Utilities Package is available from the MySQL Community Server download page'. The Download MySQL Community Server page does not mention 'Client Utilities Package' and only allows the download of a 300MiB+ package of the server and C client. That was why I suggested the
libmariadb
option may be the better one in the longer term. There is also a page MySQL Connector/C (Archived Versions), where the archived version is a 8.7M download. Using the old version may be a better option to start with.The Flatpak manifest would be similar to the one for
libmariadb
. The MySQL source is available from GitHub and also uses CMake.MySQL 8's
CMakeLists.txt
file does show thepkg-config
file ismysqlclient.pc
. So the Vala VAPI should really bemysqlclient.vapi
. Contributions to the Vala repository are welcome to fix this. By using thepkg-config
name you should no longer need to findmysql_config
inmeson.build
.I also did a search of the Flathub repository to see if any other projects were using
mysqlclient
orlibmariadb
in their manifests. Nothing was found.The Cardboard and Tape Option
If you want a rough, prototype, solution then Flatpak does provide a
simple
build type. This allows commands to be run, likecp
. So a quicker option may be to copy your local MySQL client files to the Flatpak. This would at least allow you to progress with development and come back to implementing a robust solution for the final release. See this GitHub issue and the LibreOffice Flathub manifest for examples ofsimple
builds. Also the Flatpak file structure is documented in Requirement and Conventions and in the typical filesystem inside a Flatpak sandbox.