From 52d6aac7269265d72c82d2b3b15b19643da5f206 Mon Sep 17 00:00:00 2001 From: iphydf Date: Wed, 8 Jan 2025 19:17:37 +0000 Subject: [PATCH] feat: Add qtremoteobjects to the bazel build. This allows us to do IPC/RPC in qtox. --- .bazelrc | 1 + WORKSPACE | 1 + third_party/qt.BUILD | 17 ++++++ third_party/qt/build_defs.bzl | 72 ++++++++++++++++++++++-- third_party/qt/qtremoteobjects.dev.BUILD | 19 +++++++ third_party/qt/qtremoteobjects.out.BUILD | 9 +++ 6 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 third_party/qt/qtremoteobjects.dev.BUILD create mode 100644 third_party/qt/qtremoteobjects.out.BUILD diff --git a/.bazelrc b/.bazelrc index f54d8902..52b0481c 100644 --- a/.bazelrc +++ b/.bazelrc @@ -411,6 +411,7 @@ build --per_file_copt='moc_.*\\.cpp$@-Wno-extra-semi-stmt' build --per_file_copt='moc_.*\\.cpp$@-Wno-gnu-zero-variadic-macro-arguments' build --per_file_copt='moc_.*\\.cpp$@-Wno-redundant-parens' build --per_file_copt='moc_.*\\.cpp$@-Wno-undefined-reinterpret-cast' +build --per_file_copt='moc_.*\\.cpp$@-Wno-header-hygiene' # TODO(iphydf): Fix these soon. build --per_file_copt='//c-toxcore/toxcore:Messenger.c@-Wno-error=unused-but-set-variable' diff --git a/WORKSPACE b/WORKSPACE index d01c0e46..b9eaed89 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -826,6 +826,7 @@ apple_support_dependencies() QT_LIBS = [ "base", + "remoteobjects", "svg", ] diff --git a/third_party/qt.BUILD b/third_party/qt.BUILD index 1fe92b65..b5615480 100644 --- a/third_party/qt.BUILD +++ b/third_party/qt.BUILD @@ -8,6 +8,14 @@ "uic", ]] +[alias( + name = name, + actual = "@qt6.qtremoteobjects//:libexec/%s" % name, + visibility = ["//visibility:public"], +) for name in [ + "repc", +]] + [alias( name = name, actual = "bin/%s" % name, @@ -45,6 +53,14 @@ alias( "Xml", ]] +[alias( + name = "qt_" + mod.lower(), + actual = "@qt6.qtremoteobjects//:" + mod.lower(), + visibility = ["//visibility:public"], +) for mod in [ + "RemoteObjects", +]] + [alias( name = "qt_" + mod.lower(), actual = "@qt6.qtsvg//:" + mod.lower(), @@ -63,6 +79,7 @@ filegroup( ":qt_network", ":qt_opengl", ":qt_printsupport", + ":qt_remoteobjects", ":qt_svg", ":qt_test", ":qt_widgets", diff --git a/third_party/qt/build_defs.bzl b/third_party/qt/build_defs.bzl index 2fdc2c7b..30cff699 100644 --- a/third_party/qt/build_defs.bzl +++ b/third_party/qt/build_defs.bzl @@ -7,7 +7,7 @@ This file defines three macros: - qt_moc, generates .cpp or .moc files for Qt MOC .h or .cpp files. """ -# Qt UI compiler rule. +# Qt UI compiler rule (uic). # ========================================================= load("@build_bazel_rules_apple//apple:macos.bzl", "macos_application") @@ -56,7 +56,7 @@ qt_uic = rule( implementation = _qt_uic_impl, ) -# Qt language translation compiler rule. +# Qt language translation compiler rule (lconvert). # ========================================================= def _qt_lconvert_impl(ctx): @@ -104,7 +104,7 @@ qt_lconvert = rule( implementation = _qt_lconvert_impl, ) -# Qt resource compiler rule. +# Qt resource compiler rule (rcc). # ========================================================= def _qt_rcc_impl(ctx): @@ -162,7 +162,7 @@ qt_rcc = rule( implementation = _qt_rcc_impl, ) -# Qt MOC compiler rule. +# Qt MOC compiler rule (moc). # ========================================================= def _qt_moc_impl(ctx): @@ -196,6 +196,9 @@ def _qt_moc_impl(ctx): ] outs = [] + # Current project's bin_dir. + bin_dir = ctx.bin_dir.path + "/" + ctx.label.package.split("/")[0] + "/" + for src in srcs: if src.extension == "h": out = ctx.actions.declare_file( @@ -220,7 +223,7 @@ def _qt_moc_impl(ctx): # If we're compiling for a .h file, we #include it in the resulting # moc_$name.cpp. if src.path[src.path.rindex("."):] == ".h": - arguments.append("-f" + src.path) + arguments.append("-f" + src.path.removeprefix(bin_dir)) # moc $src -o $out arguments.extend([src.path, "-o", out.path]) @@ -269,6 +272,65 @@ qt_moc = rule( implementation = _qt_moc_impl, ) +# Qt Remote Objects Compiler rule (repc). +# ========================================================= + +def _qt_repc_impl(ctx): + repc = ctx.executable._repc + type = ctx.attr.type + + srcs = [ + src + for tgt in ctx.attr.srcs + for src in tgt.files.to_list() + ] + outs = [] + + for src in srcs: + out = ctx.actions.declare_file("rep_%s_%s.h" % (src.basename[:-4], type), sibling = src) + outs.append(out) + + arguments = [ + "-o", + type, + src.path, + out.path, + ] + + # Execute repc. + ctx.actions.run( + arguments = arguments, + executable = repc.path, + inputs = [src], + mnemonic = "CompileREPC", + outputs = [out], + progress_message = "Generating Qt Remote Objects source for " + src.basename, + tools = [repc], + ) + + return DefaultInfo(files = depset(outs)) + +qt_repc = rule( + attrs = { + "srcs": attr.label_list( + allow_files = [".rep"], + doc = "The .rep files to compile.", + ), + "type": attr.string( + values = ["source", "replica"], + doc = "The type of the generated file (source/replica).", + ), + "_repc": attr.label( + default = Label("@qt//:repc"), + executable = True, + cfg = "exec", + allow_single_file = True, + ), + }, + output_to_genfiles = True, + implementation = _qt_repc_impl, +) + # Qt binary, making sure we can `bazel run` it. # ========================================================= diff --git a/third_party/qt/qtremoteobjects.dev.BUILD b/third_party/qt/qtremoteobjects.dev.BUILD new file mode 100644 index 00000000..6c36e16f --- /dev/null +++ b/third_party/qt/qtremoteobjects.dev.BUILD @@ -0,0 +1,19 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +exports_files([ + "libexec/repc", +]) + +[cc_library( + name = mod.lower(), + hdrs = glob(["include/Qt%s/**" % mod]), + defines = ["QT_%s_LIB" % mod.upper()], + includes = [ + "include", + "include/Qt" + mod, + ], + visibility = ["//visibility:public"], + deps = ["@qt6.qtremoteobjects.out//:" + mod.lower()], +) for mod in [ + "RemoteObjects", +]] diff --git a/third_party/qt/qtremoteobjects.out.BUILD b/third_party/qt/qtremoteobjects.out.BUILD new file mode 100644 index 00000000..6f17c545 --- /dev/null +++ b/third_party/qt/qtremoteobjects.out.BUILD @@ -0,0 +1,9 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +[cc_library( + name = mod.lower(), + srcs = glob(["lib/libQt6%s.so*" % mod]), + visibility = ["//visibility:public"], +) for mod in [ + "RemoteObjects", +]]