bazel-contrib / bazel-contrib/rules_foreign_cc

Enable changing cmake versions with bzlmod

Open
#1,224 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
737
Forks
270
PR merge metrics
No merged PRs in 30d

Description

Current it is not possible to change the cmake versions with bzlmod.

We were able to change the cmake version by patching MODULE.bazel and using archive_override

## Patch
```java
diff --git a/MODULE.bazel b/MODULE.bazel
index da990d8..a1a116a 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -13,7 +13,7 @@ bazel_dep(name = "rules_python", version = "0.20.0")
tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools")
use_repo(
tools,
- "cmake_3.23.2_toolchains",
+ # "cmake_3.23.2_toolchains",
"cmake_src",
"gnumake_src",
"meson_src",
@@ -32,6 +32,6 @@ register_toolchains(
"@rules_foreign_cc//toolchains:preinstalled_automake_toolchain",
"@rules_foreign_cc//toolchains:preinstalled_m4_toolchain",
"@rules_foreign_cc//toolchains:preinstalled_pkgconfig_toolchain",
- "@cmake_3.23.2_toolchains//:all",
+ # "@cmake_3.23.2_toolchains//:all",
"@ninja_1.11.1_toolchains//:all",
)
diff --git a/foreign_cc/extensions.bzl b/foreign_cc/extensions.bzl
index 23fd14b..5319b55 100644
--- a/foreign_cc/extensions.bzl
+++ b/foreign_cc/extensions.bzl
@@ -29,7 +29,7 @@ def _init(module_ctx):
}

for mod in module_ctx.modules:
- if not mod.is_root:
+ if mod.is_root:
for toolchain in mod.tags.cmake:
versions["cmake"] = toolchain.version

```
## content in MODULE.bazel
```java
bazel_dep(name = "rules_foreign_cc", version = "0.11.1")

# We patch MODULE.bazel, hence we cannot depend on bcr & have to use archive_override
archive_override(
module_name = "rules_foreign_cc",
integrity = "sha256-SzPWLPEJvMzyhrMO1xIRKcw0z09O2dihHzjZEI9AunQ=",
patch_strip = 1,
patches = [
"//:/0002-Enable-CMake-Version-Overwrite-with-Bzlmod.patch",
],
strip_prefix = "rules_foreign_cc-0.11.1",
urls = [
"https://github.com/bazelbuild/rules_foreign_cc/releases/download/0.11.1/rules_foreign_cc-0.11.1.tar.gz",
],
)

tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools")

tools.cmake(version = "3.26.4")
use_repo(tools, "cmake_3.26.4_toolchains")
```

**Version:** rules_foreign_cc-0.10.1

Are there any plans to support this out of the box ? Is there perhaps a better way to do this ?

Contributor guide

Open the contributing guide

Research direction

Start by reading foreign_cc/extensions.bzl and the rules_foreign_cc entries in MODULE.bazel, including the shown archive_override workaround. Verify that a root module can select CMake 3.26.4 through tools.cmake, expose the matching cmake_3.26.4_toolchains repository, and register the resulting toolchain without patching the dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake
Domain
build-system
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.