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 changing cmake versions with bzlmod #1224

Open
brianantony456 opened this issue Jul 11, 2024 · 1 comment
Open

Enable changing cmake versions with bzlmod #1224

brianantony456 opened this issue Jul 11, 2024 · 1 comment

Comments

@brianantony456
Copy link

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

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

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 ?

@jsharpe
Copy link
Member

jsharpe commented Jul 11, 2024

Yes - this PR: #1158 - but there are some issues with the design for the meson toolchain that needs addressing before that can land.

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

No branches or pull requests

2 participants