Vertexwahn / rules_qt6

Bazel rules for Qt6
https://vertexwahn.de/page/open_source/
Apache License 2.0
30 stars 8 forks source link

Add support for macOS 11 and 12 #7

Closed Vertexwahn closed 1 year ago

Vertexwahn commented 2 years ago

Problem description

bazel run --config=macos //:Qt6HelloWorld

Results in:

main.cpp:1:10: fatal error: 'QtCore/QThread' file not found
#include <QtCore/QThread>
        ^~~~~~~~~~~~~~~~
1 error generated.

Expected result

  1. A window similar to this should pop up:

Windows10

This should also work with macOS Monterey 12.3.1 (x86 Intel) (or newer if available)

  1. The build job build_and_test_macos should turn green https://github.com/Vertexwahn/rules_qt6/blob/f0221dda34851d6c1284f75343257539ff947d34/.github/workflows/bazel_build.yml#L59

Currently, the build status is red since the macOS 11 build does not work. macOS 11 or the newest available version of macOS in GitHub workflow should result in a green build

Hints

The file qt_6.2.4_mac_desktop_clang_64.BUILD needs some modification to find the path of Qt in macOS.

Similar problem described here.

bedbad commented 2 years ago

It's good to figure out how to build Qt on Macos as external bazel dependency at all. Installing it manually or through package manager defeats the purpose - you can just copy-paste shared libs + headers to include and link paths and get the same result.

Vertexwahn commented 2 years ago

@bedbad

I added prebuild Qt 6.4.0 for macOS (Intel) here: https://vertexwahn.de/lfs/v1/qt_6.4.0_mac_desktop_clang_64.tar.xz

The problem here I do not understand how to reference in this archive all the Qt headers and libraries.

Current try:

qt_6.4.0_mac_desktop_clang_64.BUILD:

load("@rules_qt//:qt_libraries.bzl", "QT_LIBRARIES")

[
    cc_library(
        name = "qt_%s_mac" % name,
        hdrs = glob(["lib/%s.framework/**" % include_folder]),
        includes = [
            "include",
            "include/QtCore",
        ],
        linkopts = ["-Flib"] + [
            "-framework %s" % library_name.replace("6", ""),  # macOS qt libs do not contain a 6 - e.g. instead of Qt6Core the lib is called QtCore
        ],
        target_compatible_with = ["@platforms//os:osx", "@platforms//cpu:x86_64"],
        visibility = ["//visibility:public"],
    )
    for name, include_folder, library_name, _ in QT_LIBRARIES
]

cc_library(
    name = "qt_hdrs",
    hdrs = glob(["include/**"]),
    includes = [
        "include",
    ],
    visibility = ["//visibility:public"],
)

filegroup(
    name = "uic",
    srcs = ["libexec/uic"],
    visibility = ["//visibility:public"],
)

filegroup(
    name = "moc",
    srcs = ["libexec/moc"],
    visibility = ["//visibility:public"],
)

filegroup(
    name = "rcc",
    srcs = ["libexec/rcc"],
    visibility = ["//visibility:public"],
)

filegroup(
    name = "plugin_files",
    srcs = glob(["plugins/**/*"]),
    visibility = ["//visibility:public"],
)

filegroup(
    name = "qml_files",
    srcs = glob(["qml/**/*"]),
    visibility = ["//visibility:public"],
)

This gives the error:

hello_world/hello_world.cpp:1:10: fatal error: 'QtCore/QThread' file not found
#include <QtCore/QThread>
         ^~~~~~~~~~~~~~~~

I am happy about every support...

Vertexwahn commented 1 year ago

Rules work on macOS when Qt is preinstalled. To get rules working with a non-preinstallation on macOS there is a separate issue.