Skip to content

Commit

Permalink
#775: Switch to Qt6 in Linux
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yukawa authored and hiroyuki-komatsu committed Aug 18, 2023
1 parent 5e7a418 commit 7b0fc71
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 17 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion docker/ubuntu22.04/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions docker/ubuntu22.04/qt6-core-pkgconfig/Qt6Core.pc
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions docker/ubuntu22.04/qt6-core-pkgconfig/Qt6Gui.pc
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions docker/ubuntu22.04/qt6-core-pkgconfig/Qt6Platform.pc
Original file line number Diff line number Diff line change
@@ -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}
13 changes: 13 additions & 0 deletions docker/ubuntu22.04/qt6-core-pkgconfig/Qt6Widgets.pc
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions docs/build_mozc_in_docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/bazel/pkg_config_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ cc_library(
"""

EXPORTS_FILES_TEMPLATE = """
exports_files(glob(["bin/*"]))
exports_files(glob(["libexec/*"]))
"""

def _exec_pkg_config(repo_ctx, flag):
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/bazel/qt.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
),
)
Expand All @@ -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"],
),
)
Expand All @@ -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"],
),
)
Expand Down

0 comments on commit 7b0fc71

Please sign in to comment.