Allow configuring meson, make and pkgconfig versions via bzlmod exten…#1158
Allow configuring meson, make and pkgconfig versions via bzlmod exten…#1158jsharpe wants to merge 14 commits intobazel-contrib:mainfrom
Conversation
4190892 to
db70d73
Compare
61213e6 to
289b9c6
Compare
foreign_cc/meson.bzl
Outdated
| main = "@meson_src//:meson.py", | ||
| data = ["@meson_src//:runtime"], | ||
| main = "@meson_1.1.1_src//:meson.py", | ||
| data = ["@meson_1.1.1_src//:runtime"], |
There was a problem hiding this comment.
@jheaff1 any ideas how I could avoid this hardcoded version number?
I want the end user to not have to do use_repo(tools, "meson_src") if they're using this macro which they currently have to; maybe we should make the toolchain variants have to be declared via a module extension and then generate this toolchain into the toolchain_hub e.g.
tools.meson(version = "1.1.1")
tools.meson(version = "1.1.1", requirements = ["@pypi__numpy"])
?
There was a problem hiding this comment.
I'm far from an expert on bzlmod (just started trying to port our stuff) but my observed-so-far impression of best practice here is that use_all_repos is the best you can do: #1420
(If you reuse the same repo name for multiple different versions, my observation is that it causes bazel to delete/recreate the repo; this isn't necessarily a problem for development on HEAD, but if you maintain multiple support branches, it avoids the need for bazel to do extra work when you switch between them if the repo name contains the version).
|
@jheaff1 @UebelAndre One part of this I'm yet to design is what the module extension should look like for selecting between preinstalled tools and prebuilt / built from source tools. Any ideas? The extension API currently looks like this: we could do something like: but very much open to ideas on this. |
69ccaa7 to
bf9f34b
Compare
bf9f34b to
727f549
Compare
e83ede3 to
b6938f8
Compare
|
Out of curiosity, did this PR die? I was hoping to use a new version of Cmake but it looks like this PR was abandoned. |
Not dead, its still on my todo list but haven't had the time to work through all the failures in CI! |
|
Ah wow, truthfully I was not expecting this thread to get revived, I really appreciate you taking a look! I would love to understand how to use your work when it lands. No pressure, but thanks for your effort, and I look forward to it landing! |
| # "//toolchains/private:cmake_tool", | ||
| # "//toolchains/private:make_tool", | ||
| # "//toolchains/private:meson_tool", | ||
| # "//toolchains/private:ninja_tool", | ||
| # "//toolchains/private:pkgconfig_tool", |
There was a problem hiding this comment.
Need a strategy to handle these targets - maybe these tests should be generated in the toolchain hub now?
bcde8ef to
a46e12e
Compare
a46e12e to
d43bd4a
Compare
66062e6 to
2cf53a8
Compare
2cf53a8 to
7c6201b
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the toolchain registration code to allow configuring versions for meson, make, and pkgconfig via the bzlmod extension. Key changes include:
- Removal of the register_toolchains parameter from prebuilt toolchain functions and corresponding documentation updates.
- Consolidation and renaming of built toolchain functions (e.g. cmake_toolchain, make_toolchain, meson_toolchain, pkgconfig_toolchain) for a clearer separation from preinstalled toolchains.
- Updates to dependencies and module registration in repositories and extension files for version configuration support.
Reviewed Changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| toolchains/private/BUILD.bazel | Removed built toolchain targets for make, cmake, ninja, meson, pkgconfig |
| toolchains/prebuilt_toolchains.py | Updated function signatures to remove register_toolchains parameter and renamed helper functions |
| toolchains/built_toolchains.bzl | Refactored built toolchain functions and updated toolchain registration logic |
| toolchains/BUILD.bazel | Removed legacy toolchain registrations |
| test/* | Updated workspace and build files to align with new version defaults |
| foreign_cc/* | Updated dependency defaults and registration, added new hub repo rule, and adjusted meson references |
| examples/MODULE.bazel and MODULE.bazel | Updated version numbers and repository usage |
Comments suppressed due to low confidence (2)
toolchains/prebuilt_toolchains.py:202
- The function signature for prebuilt_toolchains was updated to remove the register_toolchains parameter. Please update the corresponding docstring/comments to reflect this change.
def prebuilt_toolchains(cmake_version, ninja_version):
foreign_cc/extensions.bzl:40
- [nitpick] Consider adding an inline comment explaining the distinction between the prebuilt (e.g. cmake_toolchains) and built (e.g. cmake_toolchains_src) toolchain registration functions to improve code clarity.
for mod in module_ctx.modules:
| if len(rctx.attr.toolchain_names) != len(rctx.attr.toolchain_types): | ||
| fail("toolchain_names and toolchain_types must have the same length.") | ||
|
|
||
| toolchains = ["toolchain(name = '{}', toolchain = '{}', toolchain_type = '{}')".format(name, target, type) for (name, target, type) in zip(rctx.attr.toolchain_names, rctx.attr.toolchain_target, rctx.attr.toolchain_types)] |
There was a problem hiding this comment.
[nitpick] Ensure that the generated BUILD file handles any special characters in toolchain names, targets, or types correctly to avoid malformed BUILD definitions.
|
Came over here from #1418 (comment); I'm definitely not an expert on bzlmod, but in the (internal) repo I'm currently converting to bzlmod, this MR appears to work (and is slightly easier if you combine it with #1420) |
| "@python_3_12//:all", | ||
| "@prebuilt_cmake_toolchains//:all", | ||
| "@prebuilt_ninja_toolchains//:all", | ||
| "@rules_foreign_cc_framework_toolchains//:all", |
There was a problem hiding this comment.
I'm actually wondering if some of these should be marked as dev_dependencies instead; If I were building my own cmake, for example, i definitely wouldn't want the prebuilt toolchain to be registered at all. To give you an idea of what we do today in our workspace file (pre-migration to bzlmod, since bzlmod can't match this yet...)
rules_foreign_cc_dependencies(
cmake_version = "3.31.7",
make_version = "4.4.1",
ninja_version = NINJA_VERSION,
register_built_pkgconfig_toolchain = False,
register_preinstalled_tools = False,
)
register_toolchains(
"//thirdparty:pkgconfig_noop_toolchain",
"//thirdparty:autoconf_noop_toolchain",
"//thirdparty:automake_noop_toolchain",
"//thirdparty:m4_noop_toolchain",
)To avoid host divergence, we disable every host tool we can and replace them with noop versions (the automake one sets ACLOCAL=false AUTOMAKE=false, for example).
The infrastructural framework toolchains make sense to register unconditionally, I think, but it seems like anything that is affected by configuration at all should only be registered from the root module. (I also should reiterate that I don't really have any idea what "good" looks like for bzlmod, and you shouldn't necessarily take anything I say about it as informed :))
…sion