Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mrkkrp
Copy link

@mrkkrp mrkkrp commented Jan 12, 2024

There seem to be no way to override the default cmake (or ninja) version with a tag, although it looks like that was the original intention behind the bzlmod extension. The problem is

  • The root module is explicitly skipped because of the conditional if not mod.is_root:
  • The use_repo and register_toolchains invocations in MODULE.bazel of rules_foreign_cc have to mention the default version of cmake because it is part of the repository name that provides the toolchain (why?) and so MODULE.bazel is incompatible in the case of an override by the user.

This PR resolves both these issues.

Copy link

google-cla bot commented Jan 12, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@mrkkrp mrkkrp force-pushed the bzlmod-customizable-cmake-ninja-versions branch 3 times, most recently from 3bc61ce to b80bdab Compare January 12, 2024 14:13
@mrkkrp mrkkrp marked this pull request as draft January 12, 2024 14:18
@mrkkrp mrkkrp force-pushed the bzlmod-customizable-cmake-ninja-versions branch from b80bdab to 8cf1aa9 Compare January 12, 2024 14:22
@mrkkrp mrkkrp marked this pull request as ready for review January 12, 2024 14:25
Copy link
Collaborator

@jsharpe jsharpe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on this. I think how I would like to see this fixed is in a similar way to #1105 where the toolchains are moved into a hub repo which can be generated with all the user requested toolchain versions in it which should remove the need for the use_repo call to need to bring the repos into scope in the parent module.

for mod in module_ctx.modules:
if not mod.is_root:
Copy link
Collaborator

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

Copy link
Author

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?

Comment on lines +37 to +38
elif cmake_versions_count > 1:
fail("More than one cmake version requested: {}".format(mod.tags.cmake))
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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 break in the "then" clause). Also, there can only be one version per module, so this should be very close to the old logic with the exception that the user can actually configure the versions.

@jsharpe
Copy link
Collaborator

jsharpe commented Jan 12, 2024

Good catch on this. I think how I would like to see this fixed is in a similar way to #1105 where the toolchains are moved into a hub repo which can be generated with all the user requested toolchain versions in it which should remove the need for the use_repo call to need to bring the repos into scope in the parent module.

Actually I have to say I didn't get as far with #1105 as I'd remembered and had only moved the toolchains so that I can register them via :all rather than listing individually. My intentions were to move it into a generated repo to remove the need for the use_repo calls.

@mrkkrp mrkkrp force-pushed the bzlmod-customizable-cmake-ninja-versions branch from 8cf1aa9 to 75fc4d2 Compare January 15, 2024 09:30
@mrkkrp
Copy link
Author

mrkkrp commented Jan 29, 2024

@jsharpe Is there anything I can do to help this progress? What do you think about my replies above?

This demonstrates that the way it is organized right now, `rules_foreign_cc`
does not allow its users to opt for a non-default version of cmake.
Avoid hardcoding cmake and ninja versions in repository names that the
bzlmod extension produces.
@mrkkrp mrkkrp force-pushed the bzlmod-customizable-cmake-ninja-versions branch from 75fc4d2 to e0f5959 Compare January 29, 2024 13:24
@jsharpe
Copy link
Collaborator

jsharpe commented Feb 1, 2024

@jsharpe Is there anything I can do to help this progress? What do you think about my replies above?

Apologies the limiting factor here is my time availability to work on this as I only maintain this in my spare time.
I think really the approach we should take is to generate a hub repo that references all the other versioned repos in the same way that rules_python does so that we can generically register all the toolchains via a //:all target. I've started to work on this in #1158 but haven't found enough time to completely feed through all the refactoring required for this. If you have bandwidth available to pick up that refactoring of the generated toolchains then that'd be great..

@mrkkrp
Copy link
Author

mrkkrp commented Feb 5, 2024

I think really the approach we should take is to generate a hub repo that references all the other versioned repos in the same way that rules_python does so that we can generically register all the toolchains via a //:all target.

But if there is only one version of a given tool that is selected in the end, does it make a difference whether its repo name includes the version or it is generic? In any case, this patch solved our immediate problem and we don't think that we will have much more time to contribute to a more elaborate redesign.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants