Flatpak 捆绑 libmysqlclient

Flatpak bundle libmysqlclient

我正在尝试使用 flatpak 构建 Vala 程序。我需要连接到 mysql 服务器,这就是为什么我需要将 libmysqlclient 与我的 flatpak 捆绑在一起。

这就是我将 mysql_config 添加到 meson.build 文件的原因。

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')

现在的问题是 mysql_config 在 flatpak 运行时不可用。所以我需要将它与我的 flatpak 捆绑在一起。

然而,Flatpak 文档对我帮助不大。

Flatpak Documentation

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.

谁能告诉我如何将 libmysqlclient 添加到我的 flatpak 以及如何使用 mysql_config 为我的 flatpak 设置正确的编译器标志。

这是我的清单(gnome-builder 默认值):

{
    "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 旨在通过使用容器化技术在 Linux 上分发应用程序。这允许 Flatpak 独立于当前的发行版,如 Ubuntu 和 Fedora。然而,创建 Flatpak 的人似乎需要培养分发打包者的一些技能。 Flatpak 的依赖项位于清单的 modules 部分,这些将被构建并包含在 Flatpak 中。以下内容未经测试,因此可能会遗漏一些细节,但它旨在概述这些想法以提供帮助。有几个选项:

libmariadb

MariaDB 是 MySQL 的一个分支。在对 Oracle Corporation 收购 MySQL 表示担忧后,由社区分叉。我把它列在第一位是因为它似乎是最简单的选择,至少从长远来看是这样。

MariaDB 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 是一个更好的选择。 mariadb-connector-c 可以连接到 MariaDB 和 MySQL。

通过查看源代码,mariadb-connector-c 的构建系统是 CMake。 CMakeLists.txt file like WITH_SSL that you may need, but the manifest snippet below ignores the use of config-opts. This Flatpak GitHub issue 中的选项可能有关于如何使用 config-opts 进行 CMake 构建的相关示例。

所以我们有一个源代码版本、一个校验和并且我们知道构建系统。通过将类似这样的内容添加到清单的 modules 部分,您应该能够在 Flatpak 中包含 mariadb-connector-c 的构建:

{
  "name": "mariadb-connector-c",
  "buildsystem": "cmake",
  "sources": [
    {
      "type": "archive",
      "url": "https://downloads.mariadb.org/f/connector-c-3.0.8/mariadb-connector-c-3.0.8-src.tar.gz",
      "sha256": "2ca368fd79e87e80497a5c9fd18922d8316af8584d87cecb35bd5897cb1efd05"
    }
  ]
}

这也遗漏了 cleanup 键。

主要问题是让它与您的 Vala 应用程序一起使用。 pkg-config 文件称为 libmariadb.pc。因此您的 VAPI 需要重命名为 libmariadb.vapi。您可以将 mysql.vapi/usr/share/ 复制到本地应用程序源目录并重命名为 libmariadb.vapi。您将需要调整 meson.build 以将其作为 VAPI 搜索目录包括在内,您应该不再需要搜索 mysql_configpkg-config 将完成 mysql_config 的工作。

看起来 MySQL C header 文件仍然是 maria-connector-c 的一部分。祈祷它会起作用。 C headers 中还有一些特定于 MariaDB 的附加符号。如果您想修改 VAPI,请稍后阅读 Writing a VAPI Manually. Please consider submitting your enhancements to the Vala mainline repository

mysqlclient

MySQL 似乎需要下载服务器才能构建客户端。我从这个标题为 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) 的页面开始,其中存档版本是 8.7M 下载。使用旧版本可能是更好的选择。

Flatpak 清单与 libmariadb 的清单类似。 MySQL source is available from GitHub 也使用 CMake。

MySQL 8 的 CMakeLists.txt 文件确实显示 pkg-config 文件是 mysqlclient.pc。所以 Vala VAPI 真的应该是 mysqlclient.vapi。欢迎对 Vala 存储库的贡献来解决这个问题。通过使用 pkg-config 名称,您将不再需要在 meson.build.

中查找 mysql_config

我还搜索了 Flathub repository 以查看是否有任何其他项目在其清单中使用 mysqlclientlibmariadb。什么都没找到。

纸板和胶带选项

如果您想要一个粗略的原型解决方案,那么 Flatpak 确实提供了 simple 构建类型。这允许命令为 运行,如 cp。因此,一个更快的选择可能是将本地 MySQL 客户端文件复制到 Flatpak。这至少可以让您在开发方面取得进展并返回到为最终版本实施可靠的解决方案。看到这个 GitHub issue and the LibreOffice Flathub manifest for examples of simple builds. Also the Flatpak file structure is documented in Requirement and Conventions and in the typical filesystem inside a Flatpak sandbox.