Qt Console app with cc_import rule (Windows)

684 views
Skip to first unread message

den....@gmail.com

unread,
Feb 18, 2018, 8:57:53 AM2/18/18
to bazel-discuss
Hi all,

I'm trying to build simple Qt console app with using of new cc_import rule, bazel 0.10.1 on Windows 10.

Firstly, I tried to build it with cc_library rule.
My WORKSPACE, BUILD and main.cpp files are:

new_local_repository(
name = "qt",
path = "C:/Qt/5.9.2/msvc2017_64",
build_file_content = """
cc_library(
name = "QtCore",
srcs = ["lib/Qt5Core.lib"],
includes = ["include/"],
visibility = ["//visibility:public"],
)
"""
)

cc_binary(
name = "hello-qt-console",
srcs = [
"main.cpp",
],
deps = [
"@qt//:QtCore"
]
)

#include <QtCore/QCoreApplication>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

return a.exec();
}

It compiles fine, but does not copy the "C:\Qt\5.9.2\msvc2017_64\bin\Qt5Core.dll" to the output dir.

So I wanted to try new cc_import rule, but I cannot make this work.
Now my WORKSPACE file is:

new_local_repository(
name = "qt",
path = "C:/Qt/5.9.2/msvc2017_64",
build_file_content = """
cc_import(
name = "QtCore",
hdrs = glob(["include/QtCore/*"]),
interface_library = "lib/Qt5Core.lib",
shared_library = "bin/Qt5Core.dll",
visibility = ["//visibility:public"]
)
"""
)

But I'm getting such errors for all header files without extensions in "C:\Qt\5.9.2\msvc2017_64\include\QtCore" folder:
ERROR: D:/labs/bazel/helloqtconsole/output/external/qt/BUILD.bazel:4:12: in hdrs attribute of cc_import rule @qt//:QtCore: file '@qt//:include/QtCore/QException' is misplaced here (expected .h, .hh, .hpp, .ipp, .hxx or .inc)
ERROR: D:/labs/bazel/helloqtconsole/output/external/qt/BUILD.bazel:4:12: in hdrs attribute of cc_import rule @qt//:QtCore: '@qt//:include/QtCore/QException' does not produce any cc_import hdrs files (expected .h, .hh, .hpp, .ipp, .hxx or .inc)

There are header files with ".h" extension in "C:\Qt\5.9.2\msvc2017_64\include\QtCore" folder so I tried to changes my WORKSPACE and main.cpp files like this:

new_local_repository(
name = "qt",
path = "C:/Qt/5.9.2/msvc2017_64",
build_file_content = """
cc_import(
name = "QtCore",
hdrs = glob(["include/QtCore/*.h"]),
interface_library = "lib/Qt5Core.lib",
shared_library = "bin/Qt5Core.dll",
visibility = ["//visibility:public"]
)
"""
)

#include <QtCore/qcoreapplication.h>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

return a.exec();
}

After this I'm getting this error:
ERROR: D:/labs/bazel/helloqtconsole/BUILD:1:1: C++ compilation of rule '//:hello-qt-console' failed (Exit 2)
main.cpp(1): fatal error C1083: Cannot open include file: 'QtCore/qcoreapplication.h': No such file or directory

In my last attempt I tried to change path for "qcoreapplication.h" file in my main.cpp file like this:

#include <include/QtCore/qcoreapplication.h>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

return a.exec();
}

And now I'm getting this:
ERROR: D:/labs/bazel/helloqtconsole/BUILD:1:1: C++ compilation of rule '//:hello-qt-console' failed (Exit 2)
D:\labs\bazel\helloqtconsole\output\execroot\__main__\external\qt\include/QtCore/qcoreapplication.h(43): fatal error C1083: Cannot open include file: 'QtCore/qglobal.h': No such file or directory .

I think that something wrong with my paths, but I don't want to change anything in Qt's header files.

Could someone help me with constructing right WORKSPACE file with cc_import rule and without changes to Qt library?

Thanks.

Yun Peng

unread,
Feb 28, 2018, 8:50:56 PM2/28/18
to den....@gmail.com, bazel-discuss
Hi

The problems is cc_import doesn't support the "includes" attribute yet. So as a work around I think you can combine cc_library and cc_import to solve this problem. The BUILD file content would be:

cc_library(
    name = "QtCore_headers",

    hdrs = glob(["include/QtCore/*.h"]),
    includes = ["include/"],
    visibility = ["//visibility:public"],
)

cc_import(
    name = "QtCore_lib",

    interface_library = "lib/Qt5Core.lib",
    shared_library = "bin/Qt5Core.dll",
    visibility = ["//visibility:public"]
)

cc_library(
    name = "QtCore",
    deps = [
         "QtCore_headers",
         "QtCore_lib",
    ],
    visibility = ["//visibility:public"], 
)

Please let me know if this works for you.

Cheers,
Yun


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/b10afe5f-afb3-447b-a86f-e51ac896ed0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

den....@gmail.com

unread,
Mar 1, 2018, 5:43:22 AM3/1/18
to bazel-discuss
Hi Yun,

It works!
Thank you so much for help.

Yun, sorry for bothering, could you tell the release date (or build number) when cc_import will support the "includes" attribute?

Thanks again!

Best regards,
Denis

четверг, 1 марта 2018 г., 4:50:56 UTC+3 пользователь Yun Peng написал:

Marcel Hlopko

unread,
Mar 6, 2018, 3:11:41 AM3/6/18
to den....@gmail.com, bazel-discuss
Hi,
 
we don't plan to add more features to cc_import as it is right now, we first want to rewrite it in Skylark and only then extend it. We will ping https://github.com/bazelbuild/bazel/issues/4748 with updates.


For more options, visit https://groups.google.com/d/optout.
--
-- 
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

den....@gmail.com

unread,
Mar 6, 2018, 3:29:52 AM3/6/18
to bazel-discuss
вторник, 6 марта 2018 г., 11:11:41 UTC+3 пользователь Marcel Hlopko написал:
Thank you for reply, Marcel.
Reply all
Reply to author
Forward
0 new messages