Skip to main content

使用GitHub Actions编译Qt Creator插件

Comments

翻译自Building Qt Creator plugins with GitHub Actions

原文作者:Cristian Adam

翻译:Richard Lin

Qt Creator是一个跨平台、高度模块化的Qt/C++应用程序。

您在编译Qt Creator插件时需要:

  • C++编译器
  • Qt SDK
  • Qt Creator SDK

许多插件开发者可能还不知道Qt Creator有SDK。(使用SDK)开发Qt Creator插件时就不需要编译整个Qt Creator。另外,对于大多数C++开发者来说,要在三个平台(Windows、Linux、macOS)上编译、测试和调试插件并不简单。

GitHub Actions

GitHub Actions是GitHub提供的一个CI/CD基础功能,它可以运行在所有三个平台上!GitHub上也托管了一些Qt Creator插件的代码仓库,所以我准备尝试构建Doxygen 插件(在我采用了GitHub Actions script的fork版本上)。

GitHub Actions目前提供以下虚拟机(runners):

  • Ubuntu 16.04 LTS
  • Ubuntu 18.04 LTS
  • Windows Server 2016
  • Windows Server 2019
  • macOS 10.15

Qt SDK初始没有安装到runners上。这不是问题,因为我们希望用相同的版本的Qt和Qt Creator。

开发者可以一次在一个平台上开发,也可以同时在多个平台开发一个应用(矩阵模式)

先决条件

由于GitHub提供了虚拟机和C++编译器,所以开发者只需要获得Qt库和Qt Creator SDKs,然后就可以开始“编译”。

我决定编写脚本实现自动下载、解压文件和编译,脚本文件在三个文件中:CMake(通过-P命令行参数进入脚本模式)。

我从download.Qt.io下载了Qt SDK和Qt Creator二进制文件、源代码和SDK。

编译插件

为了配置插件,开发者需要运行

qmake doxygen.pro CONFIG+=release QTC_SOURCE="$ENV{GITHUB_WORKSPACE}/qtcreator" QTC_BUILD="$ENV{GITHUB_WORKSPACE}/qtcreator"

编译也很简单,运行

make -j<number of cores> jom

最后,我们将拥有一个动态链接库(.dll、.so、.dynlib),它将发布给用户。

触发GitHub Actions

执行git push后,将编译插件,每次编译的工作临时文件都会被储存。这看起来像这样:

github-actions-push

如果我们用git tag -a v0.4.7-qtc-4.11 -m "Release v0.4.7-qtc-4.11"命令标记一次提交,然后用git push originv0.4.7-qtc-4.11命令提交。这将触发release编译,中间文件将被上载到该release。这看起来像:

github-actions-push-with-tag

新创建release如下:

github-actions-release

它能否实际运行?

GitHub Actions在平台和编译器上与编译Qt和Qt Creator的条件有一些不同:

  • Visual C++ 2019 vs Visual C++ 2017
  • Red Hat 7.2 vs Ubuntu 18.04

而实践证明Qt Creator能够在三个平台上加载插件!

qtc-4.11-doxygen-macos

qtc-4.11-doxygen-windows

qtc-4.11-doxygen-linux

源代码!

您需要复制一个Yaml文件到qtcreator doxygen/.github/workflows/build_qmake.yml

源码如下:

请任意复制和修改脚本,来发布自己的Qt Creator插件!

Blog Topics

Comments

Subscribe to our blog

Try Qt 6.11 Now!

Download the latest release here: www.qt.io/download

Qt 6.11 is now available, with new features and improvements for application developers and device creators.

We're Hiring

Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.