-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Qt toolchain #29
Draft
limdor
wants to merge
2
commits into
justbuchanan:master
Choose a base branch
from
limdor:qt_toolchain
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−22
Draft
Qt toolchain #29
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
############################# | ||
## Terminal output options ## | ||
############################# | ||
|
||
# Print debug information while finding toolchains for a rule | ||
build --toolchain_resolution_debug | ||
|
||
# If a command fails, print out the full command line | ||
build --verbose_failures | ||
|
||
# Display the subcommands used to generate each target | ||
# Uncomment to see the effect, if you have it allways enabled it will increase quite a log the logs | ||
# build --subcommands=pretty_print | ||
|
||
##################### | ||
## Caching options ## | ||
##################### | ||
|
||
# Enable disk cache | ||
build --disk_cache=~/.bazel/disk_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,37 +13,70 @@ def qt_autoconf_impl(repository_ctx): | |
repository_ctx: repository context | ||
""" | ||
os_name = repository_ctx.os.name.lower() | ||
is_linux_machine = False | ||
if os_name.find("windows") != -1: | ||
if os_name.find("windows") == -1 and os_name.find("linux") == -1: | ||
fail("Unsupported OS: %s" % os_name) | ||
is_linux_machine = os_name.find("windows") == -1 | ||
|
||
# Location of the different Qt artifacts on Linux system installed standalone as well as Windows | ||
# Qt includes | ||
# <location>/include | ||
# | ||
# Qt libraries | ||
# <location>/lib | ||
# | ||
# uic, rcc, moc | ||
# <location>/bin | ||
|
||
# Location of the different Qt artifacts on Linux system installed with apt | ||
# Qt includes | ||
# /usr/include/x86_64-linux-gnu/qt5 | ||
# | ||
# Qt libraries | ||
# /lib/x86_64-linux-gnu/ | ||
# /usr/lib/x86_64-linux-gnu/ | ||
# | ||
# uic, rcc, moc | ||
# /usr/bin/ | ||
|
||
# If QT_DIR is defined and it exists, we consider that it is a standalone installation | ||
# Only in the case that is linux and QT_DIR is not defined it is considerd a none standalone | ||
# installation | ||
qt_dir_path = _get_env_var(repository_ctx, "QT_DIR", None) | ||
is_standalone = qt_dir_path != None and repository_ctx.path(qt_dir_path).exists | ||
if not is_linux_machine: | ||
# Inside this folder, in Windows you can find include, lib and bin folder | ||
default_qt_path = "C:\\\\Qt\\\\5.9.9\\\\msvc2017_64\\\\" | ||
elif os_name.find("linux") != -1: | ||
is_linux_machine = True | ||
# In Linux, this is the equivalent to the include folder, the binaries are located in | ||
# /usr/bin/ | ||
# This would be the path if it has been installed using a package manager | ||
default_qt_path = "/usr/include/x86_64-linux-gnu/qt5" | ||
if not repository_ctx.path(default_qt_path).exists: | ||
default_qt_path = "/usr/include/qt" | ||
qt_prefix = default_qt_path | ||
if is_standalone: | ||
qt_prefix = qt_dir_path | ||
qt_includes = qt_prefix + "\\\\include" | ||
qt_libs = qt_prefix + "\\\\lib" | ||
qt_bins = qt_prefix + "\\\\bin" | ||
else: | ||
fail("Unsupported OS: %s" % os_name) | ||
|
||
if repository_ctx.path(default_qt_path).exists: | ||
print("Installation available on the default path: ", default_qt_path) | ||
if is_standalone: | ||
qt_prefix = qt_dir_path | ||
qt_includes = qt_prefix + "/include" | ||
qt_libs = qt_prefix + "/lib" | ||
qt_bins = qt_prefix + "/bin" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hello, curious about this part, how can we pass bin path to qt_toolchain rule to get moc, rcc and uic path? |
||
else: | ||
default_qt_include_path = "/usr/include/x86_64-linux-gnu/qt5" | ||
if repository_ctx.path(default_qt_include_path).exists: | ||
qt_includes = default_qt_include_path | ||
else: | ||
qt_includes = "/usr/include/qt" | ||
qt_libs = "/lib/x86_64-linux-gnu/" | ||
qt_bins = "/usr/bin/" | ||
|
||
qt_path = _get_env_var(repository_ctx, "QT_DIR", default_qt_path) | ||
if qt_path != default_qt_path: | ||
print("However QT_DIR is defined and will be used: ", qt_path) | ||
# In Linux in case that we have a standalone installation, we need to provide the path inside the include folder | ||
qt_path_with_include = qt_path + "/include" | ||
if is_linux_machine and repository_ctx.path(qt_path_with_include).exists: | ||
qt_path = qt_path_with_include | ||
print("Qt installation found in:") | ||
print("Qt includes: ", qt_includes) | ||
print("Qt libs: ", qt_libs) | ||
print("Qt bins: ", qt_bins) | ||
|
||
repository_ctx.file("BUILD", "# empty BUILD file so that bazel sees this as a valid package directory") | ||
repository_ctx.template( | ||
"local_qt.bzl", | ||
repository_ctx.path(Label("//:BUILD.local_qt.tpl")), | ||
{"%{path}": qt_path}, | ||
{"%{path}": qt_includes}, | ||
) | ||
|
||
qt_autoconf = repository_rule( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
QtSDK = provider( | ||
doc = "Contains information about the Qt SDK used in the toolchain", | ||
fields = { | ||
"qt_include_path": "Path where the Qt include files are located", | ||
"qt_lib_path": "Path where the Qt libraries are located", | ||
"rcc_path": "Path where the rcc binary is located", | ||
"moc_path": "Path where the moc binary is located", | ||
"uic_path": "Path where the uic binary is located", | ||
}, | ||
) | ||
|
||
def _qt_toolchain_impl(ctx): | ||
toolchain_info = platform_common.ToolchainInfo( | ||
qt_sdk = QtSDK( | ||
qt_include_path = ctx.attr.qt_include_path, | ||
qt_lib_path = ctx.attr.qt_lib_path, | ||
rcc_path = ctx.attr.rcc_path, | ||
moc_path = ctx.attr.moc_path, | ||
uic_path = ctx.attr.uic_path, | ||
), | ||
) | ||
return [toolchain_info] | ||
|
||
qt_toolchain = repository_rule( | ||
implementation = _qt_toolchain_impl, | ||
attrs = { | ||
"qt_include_path": attr.string(), | ||
"qt_lib_path": attr.string(), | ||
"rcc_path": attr.string(), | ||
"moc_path": attr.string(), | ||
"uic_path": attr.string(), | ||
}, | ||
) | ||
|
||
def declare_windows_toolchain(): | ||
toolchain_name = "qt_windows_amd64" | ||
toolchain_impl_name = toolchain_name + "_impl" | ||
qt_toolchain( | ||
name = toolchain_impl_name, | ||
tags = ["manual"], | ||
) | ||
native.toolchain( | ||
name = toolchain_name, | ||
exec_compatible_with = [ | ||
"@platforms//os:windows", | ||
"@platforms//cpu:x86_64", | ||
], | ||
target_compatible_with = [ | ||
"@platforms//os:windows", | ||
"@platforms//cpu:x86_64", | ||
], | ||
toolchain = ":" + toolchain_impl_name, | ||
) | ||
|
||
def declare_linux_toolchain(): | ||
toolchain_name = "qt_linux_amd64" | ||
toolchain_impl_name = toolchain_name + "_impl" | ||
qt_toolchain( | ||
name = toolchain_impl_name, | ||
) | ||
native.toolchain( | ||
name = toolchain_name, | ||
exec_compatible_with = [ | ||
"@platforms//os:linux", | ||
"@platforms//cpu:x86_64", | ||
], | ||
target_compatible_with = [ | ||
"@platforms//os:linux", | ||
"@platforms//cpu:x86_64", | ||
], | ||
toolchain = ":" + toolchain_impl_name, | ||
) | ||
|
||
def declare_toolchains(): | ||
declare_linux_toolchain() | ||
declare_windows_toolchain() | ||
native.register_toolchains(":qt_linux_amd64", ":qt_windows_amd64") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to not use https://docs.bazel.build/versions/main/skylark/lib/dict.html#get ? It is available at least from 1.0 onward.
Because this uses
QT_DIR
, I thinkrepository_rule()
down below should setenviron = ["QT_DIR"]
https://docs.bazel.build/versions/main/skylark/lib/globals.html#repository_ruleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it is right now you are right that get could be used. What happened is that the code evolved. Initially getting the variable was done in a case insensitive way this is why get could have not been used. This should be redone and make clear what behavior is wanted, here the full discussion: #17 (comment)