#775: Switch to Qt6 in Linux

With this commit, Linux build starts linking to Qt6.

Here are things needed to use Qt6 in Ubuntu 22.04.

 * Qt6 uses 'libexec' rather than 'bin' to host tools like 'uic'.
 * Qt6 requires 'libgl-dev' in Ubuntu 22.04.
 * Ubuntu 22.04 uses Qt 6.2.4, where you cannot use pkg-config for Qt6
   due to QTBUG-86080 [1]. This commit works around it by injecting
   files like Qt6Core.pc files with 'PKG_CONFIG_PATH' environment
   variable.

 [1]: https://bugreports.qt.io/browse/QTBUG-86080

PiperOrigin-RevId: 558016590
This commit is contained in:
Yohei Yukawa
2023-08-18 03:52:17 +00:00
committed by Hiroyuki Komatsu
parent 5e7a4182d4
commit 7b0fc713f0
10 changed files with 76 additions and 17 deletions

View File

@ -26,12 +26,15 @@ jobs:
- name: Setup
run: |
sudo apt-get update
sudo apt-get install -y libibus-1.0-dev qtbase5-dev
sudo apt-get install -y libibus-1.0-dev qt6-base-dev libgl-dev
echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
#
# Unset the Android NDK setting to skip the unnecessary configuration.
echo "ANDROID_NDK_HOME=" >> $GITHUB_ENV
#
# Work around https://bugreports.qt.io/browse/QTBUG-86080 for Ubuntu 22.04
echo "PKG_CONFIG_PATH=${PWD}/docker/ubuntu22.04/qt6-core-pkgconfig:${PKG_CONFIG_PATH}" >> $GITHUB_ENV
- name: bazel build
working-directory: ./src
@ -59,12 +62,15 @@ jobs:
- name: Setup
run: |
sudo apt-get update
sudo apt-get install -y libibus-1.0-dev qtbase5-dev
sudo apt-get install -y libibus-1.0-dev qt6-base-dev libgl-dev
echo "CC=clang" >> $GITHUB_ENV
echo "CXX=clang++" >> $GITHUB_ENV
#
# Unset the Android NDK setting to skip the unnecessary configuration.
echo "ANDROID_NDK_HOME=" >> $GITHUB_ENV
#
# Work around https://bugreports.qt.io/browse/QTBUG-86080 for Ubuntu 22.04
echo "PKG_CONFIG_PATH=${PWD}/docker/ubuntu22.04/qt6-core-pkgconfig:${PKG_CONFIG_PATH}" >> $GITHUB_ENV
- name: bazel test
working-directory: ./src

View File

@ -40,7 +40,7 @@ RUN apt upgrade -y
## Common packages for linux build environment
RUN apt-get install -y clang libc++-dev libc++abi-dev python3 pkg-config git curl bzip2 unzip make ninja-build
## Packages for linux desktop version
RUN apt-get install -y libibus-1.0-dev libglib2.0-dev qtbase5-dev
RUN apt-get install -y libibus-1.0-dev libglib2.0-dev qt6-base-dev libgl-dev
## Packages for misc tools
RUN apt-get install -y nano
@ -59,6 +59,8 @@ RUN useradd --create-home --shell /bin/bash --base-dir /home mozc_builder
USER mozc_builder
RUN mkdir -p /home/mozc_builder/work
WORKDIR /home/mozc_builder/work
## Work around https://bugreports.qt.io/browse/QTBUG-86080 for Ubuntu 22.04
ENV PKG_CONFIG_PATH="/home/mozc_builder/work/mozc/docker/ubuntu22.04/qt6-core-pkgconfig:${PKG_CONFIG_PATH}"
## For Android NDK
RUN curl -LO https://dl.google.com/android/repository/android-ndk-r25c-linux.zip && unzip android-ndk-r25c-linux.zip && rm android-ndk-r25c-linux.zip

View File

@ -0,0 +1,13 @@
prefix=/usr
exec_prefix=${prefix}
bindir=${prefix}/lib/qt6/bin
libexecdir=${prefix}/lib/qt6/libexec
libdir=${prefix}/lib/x86_64-linux-gnu
includedir=${prefix}/include/x86_64-linux-gnu/qt6
Name: Qt6 Core
Description: Qt Core module
Version: 6.2.4
Libs: -L${libdir} -lQt6Core
Cflags: -I${includedir}/QtCore -I${includedir} -DQT_CORE_LIB
Requires: Qt6Platform

View File

@ -0,0 +1,13 @@
prefix=/usr
exec_prefix=${prefix}
bindir=${prefix}/lib/qt6/bin
libexecdir=${prefix}/lib/qt6/libexec
libdir=${prefix}/lib/x86_64-linux-gnu
includedir=${prefix}/include/x86_64-linux-gnu/qt6
Name: Qt6 Gui
Description: Qt Gui module
Version: 6.2.4
Libs: -L${libdir} -lQt6Gui
Cflags: -I${includedir}/QtGui -I${includedir} -DQT_GUI_LIB
Requires: Qt6Core

View File

@ -0,0 +1,12 @@
prefix=/usr
exec_prefix=${prefix}
bindir=${prefix}/lib/qt6/bin
libexecdir=${prefix}/lib/qt6/libexec
libdir=${prefix}/lib/x86_64-linux-gnu
includedir=${prefix}/include/x86_64-linux-gnu/qt6
mkspecsdir=${prefix}/lib/x86_64-linux-gnu/qt6/mkspecs
Name: Qt6 Platform
Description: Qt Platform module
Version: 6.2.4
Cflags: -I${mkspecsdir}/linux-g++ -I${includedir}

View File

@ -0,0 +1,13 @@
prefix=/usr
exec_prefix=${prefix}
bindir=${prefix}/lib/qt6/bin
libexecdir=${prefix}/lib/qt6/libexec
libdir=${prefix}/lib/x86_64-linux-gnu
includedir=${prefix}/include/x86_64-linux-gnu/qt6
Name: Qt6 Widgets
Description: Qt Widgets module
Version: 6.2.4
Libs: -L${libdir} -lQt6Widgets
Cflags: -I${includedir}/QtWidgets -I${includedir} -DQT_WIDGETS_LIB
Requires: Qt6Core Qt6Gui

View File

@ -143,8 +143,9 @@ Note: This section is not about our officially supported build process.
* Python: 3.7 or later
* Ibus: 1.5.4 or later
* Qt5: 5.12 or later
* libglib
* libglib
* Qt6: 6.2.5 or later, or Qt 6.2.x with working around [QTBUG-86080](https://bugreports.qt.io/browse/QTBUG-86080) by yourself
* libgl
You may also need other libraries.
See the configurations of

View File

@ -118,7 +118,7 @@ new_local_repository(
# Qt for Linux
pkg_config_repository(
name = "qt_linux",
packages = ["Qt5Core", "Qt5Gui", "Qt5Widgets"],
packages = ["Qt6Core", "Qt6Gui", "Qt6Widgets"],
)
# Qt for macOS

View File

@ -75,7 +75,7 @@ cc_library(
"""
EXPORTS_FILES_TEMPLATE = """
exports_files(glob(["bin/*"]))
exports_files(glob(["libexec/*"]))
"""
def _exec_pkg_config(repo_ctx, flag):
@ -107,10 +107,9 @@ def _pkg_config_repository_impl(repo_ctx):
}
build_file_data = BUILD_TEMPLATE.format(**data)
# host_bins
host_bins = _exec_pkg_config(repo_ctx, "--variable=host_bins")
if len(host_bins) == 1:
repo_ctx.symlink(host_bins[0], "bin")
libexecdir = _exec_pkg_config(repo_ctx, "--variable=libexecdir")
if len(libexecdir) == 1:
repo_ctx.symlink(libexecdir[0], "libexec")
build_file_data += EXPORTS_FILES_TEMPLATE
repo_ctx.file("BUILD.bazel", build_file_data)

View File

@ -82,12 +82,12 @@ def mozc_qt_moc(name, srcs, outs):
outs = outs,
cmd = mozc_select(
default = "$(location //third_party/qt:moc) -p $$(dirname $<) -o $@ $(SRCS)",
oss_linux = "$(location @qt_linux//:bin/moc) -p $$(dirname $<) -o $@ $(SRCS)",
oss_linux = "$(location @qt_linux//:libexec/moc) -p $$(dirname $<) -o $@ $(SRCS)",
oss_macos = "$(location @qt_mac//:bin/moc) -p $$(dirname $<) -o $@ $(SRCS)",
),
tools = mozc_select(
default = ["//third_party/qt:moc"],
oss_linux = ["@qt_linux//:bin/moc"],
oss_linux = ["@qt_linux//:libexec/moc"],
oss_macos = ["@qt_mac//:bin/moc"],
),
)
@ -99,12 +99,12 @@ def mozc_qt_uic(name, srcs, outs):
outs = outs,
cmd = mozc_select(
default = "$(location //third_party/qt:uic) -o $@ $(SRCS)",
oss_linux = "$(location @qt_linux//:bin/uic) -o $@ $(SRCS)",
oss_linux = "$(location @qt_linux//:libexec/uic) -o $@ $(SRCS)",
oss_macos = "$(location @qt_mac//:bin/uic) -o $@ $(SRCS)",
),
tools = mozc_select(
default = ["//third_party/qt:uic"],
oss_linux = ["@qt_linux//:bin/uic"],
oss_linux = ["@qt_linux//:libexec/uic"],
oss_macos = ["@qt_mac//:bin/uic"],
),
)
@ -116,12 +116,12 @@ def mozc_qt_rcc(name, qrc_name, qrc_file, srcs, outs):
outs = outs,
cmd = mozc_select(
default = "$(location //third_party/qt:rcc) -o $@ -name " + qrc_name + " " + qrc_file,
oss_linux = "$(location @qt_linux//:bin/rcc) -o $@ -name " + qrc_name + " $(location " + qrc_file + ")",
oss_linux = "$(location @qt_linux//:libexec/rcc) -o $@ -name " + qrc_name + " $(location " + qrc_file + ")",
oss_macos = "$(location @qt_mac//:bin/rcc) -o $@ -name " + qrc_name + " $(location " + qrc_file + ")",
),
tools = mozc_select(
default = ["//third_party/qt:rcc"],
oss_linux = ["@qt_linux//:bin/rcc"],
oss_linux = ["@qt_linux//:libexec/rcc"],
oss_macos = ["@qt_mac//:bin/rcc"],
),
)