-
Notifications
You must be signed in to change notification settings - Fork 248
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
Enable users to customize cmake and ninja versions with bzlmod #1157
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,22 +23,31 @@ def _init(module_ctx): | |
register_built_pkgconfig_toolchain = True, | ||
) | ||
|
||
versions = { | ||
"cmake": _DEFAULT_CMAKE_VERSION, | ||
"ninja": _DEFAULT_NINJA_VERSION, | ||
} | ||
cmake_version = _DEFAULT_CMAKE_VERSION | ||
ninja_version = _DEFAULT_NINJA_VERSION | ||
|
||
# Traverse all modules starting from the root one (the first in | ||
# module_ctx.modules). The first occurrence of cmake or ninja tag wins. | ||
# Multiple versions requested from the same module are rejected. | ||
for mod in module_ctx.modules: | ||
if not mod.is_root: | ||
for toolchain in mod.tags.cmake: | ||
versions["cmake"] = toolchain.version | ||
cmake_versions_count = len(mod.tags.cmake) | ||
if cmake_versions_count == 1: | ||
cmake_version = mod.tags.cmake[0].version | ||
break | ||
elif cmake_versions_count > 1: | ||
fail("More than one cmake version requested: {}".format(mod.tags.cmake)) | ||
Comment on lines
+37
to
+38
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. I think we should be able to support registering more than one version of cmake in a build. We should probably generate a version specific constraint that we apply to the toolchain targets so that a user can select a version constraint that way if they desire. 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. We do support declaring more than one version of cmake, but each such declaration should be in a different module. Here we simply guard against multiple declarations in the same module. 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. By removing the version number from the generated names though you will get duplicate definitions if a module defines one version and then the root requests a different version. This is also the rationale for restricting definitions to the root module at least for the time being. 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. While we do allow specifying several versions of cmake/ninja, only one version wins—the one closest to the root module (see |
||
|
||
for toolchain in mod.tags.ninja: | ||
versions["ninja"] = toolchain.version | ||
for mod in module_ctx.modules: | ||
ninja_versions_count = len(mod.tags.ninja) | ||
if ninja_versions_count == 1: | ||
ninja_version = mod.tags.ninja[0].version | ||
break | ||
elif ninja_versions_count > 1: | ||
fail("More than one ninja version requested: {}".format(mod.tags.ninja)) | ||
|
||
prebuilt_toolchains( | ||
cmake_version = versions["cmake"], | ||
ninja_version = versions["ninja"], | ||
cmake_version = cmake_version, | ||
ninja_version = ninja_version, | ||
register_toolchains = False, | ||
) | ||
|
||
|
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.
We need to maintain this check - only the root module should declare the versions of the tooling.
Good catch though on this being inverted; this should be
if mod.is_root
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.
The way it is written in this PR, we allow any module to declare a version of the tooling but the module that is closest to the root has the precedence. Is there a reason to strictly limit these version declarations to the root module only?