[llvm] [Bazel] Add support for Bzlmod (PR #88927)

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 16 14:24:39 PDT 2024


================
@@ -0,0 +1,127 @@
+# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+load("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")
+load(":vulkan_sdk.bzl", "vulkan_sdk_setup")
+load(":configure.bzl", "llvm_configure", "DEFAULT_TARGETS")
+
+def _llvm_configure_extension_impl(ctx):
+    targets = []
+    patches = []
+    commit = ""
+    sha256 = ""
+
+    for module in ctx.modules:
+
+        # Aggregate targets and patches across imports.
+        for config in module.tags.configure:
+            for target in config.targets:
+                if target not in targets:
+                    targets.append(target)
+            for patch in config.patches:
+                if patch not in patches:
+                    patches.append(patch)
+
+        # Use the first nonempty commit/sha configuration, starting from the
+        # top-level import and working down to the MODULE.bazel of the
+        # llvm-project-overlay itself, which does not specify these values.
+        # This way in-tree builds will always use the current sources and not
+        # fetch the llvm repository from a hardcoded commit.
+        if module.tags.configure != [] and commit == "":
+            commit = module.tags.configure[0].commit
+            sha256 = module.tags.configure[0].sha256
+
+    if commit == "":
+        if patches != []:
+            fail("""Cannot apply patches when `commit` is unspecified. Patches
+                 would modify some unknown version of the LLVM sources, making
+                 the build irreproducible.
+                 """,
+            )
+        new_local_repository(
+            name = "llvm-raw",
+            path = "../../",
+            build_file_content = "#Empty.",
+        )
+    else:
+        http_archive(
+            name = "llvm-raw",
+            build_file_content = "# Empty.",
+            sha256 = sha256,
+            strip_prefix = "llvm-project-" + commit,
+            urls = [
+                "https://github.com/llvm/llvm-project/archive/{}.tar.gz".format(
+                    commit,
+                ),
+            ],
+            patches = patches,
+            patch_args = ["-p1"],
+        )
+
+    # Fall back to the default targets if all configurations of this extension
+    # omit the `target` attribute.
+    if targets == []:
+        targets = DEFAULT_TARGETS
+
+    llvm_configure(name = "llvm-project", targets = targets)
+
+    http_archive(
+        name = "llvm_zlib",
----------------
keith wrote:

i wondered what we would do with these, should we drop the llvm specific one and use the one coming from bzlmod in this case instead? that seems like the ideal version of this type of dependency resolution. that way there is only 1 zlib-ng linked in (same thought for the others here)

https://github.com/llvm/llvm-project/pull/88927


More information about the llvm-commits mailing list