Skip to content

Commit 0313f04

Browse files
committed
migrate llvm dependency to bazelmod
1 parent b3e4630 commit 0313f04

File tree

7 files changed

+214
-154
lines changed

7 files changed

+214
-154
lines changed

MODULE.bazel

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,37 @@ bazel_dep(name = "rules_shell", version = "0.6.1")
4141
bazel_dep(name = "re2", version = "2025-08-12")
4242
bazel_dep(name = "isl", version = "0.27")
4343

44+
# LLVM dependency uses module extensions because none of these are in the BCR
45+
mlir_tutorial_deps = use_extension("//bazel:extensions.bzl", "llvm_deps")
46+
use_repo(
47+
mlir_tutorial_deps,
48+
"llvm-raw",
49+
"llvm_zlib",
50+
"llvm_zstd",
51+
)
52+
53+
# The subset of LLVM backend targets that should be compiled
54+
_LLVM_TARGETS = [
55+
"X86",
56+
# The bazel dependency graph for mlir-opt fails to load (at the analysis
57+
# step) without the NVPTX target in this list, because mlir/test:TestGPU
58+
# depends on the //llvm:NVPTXCodeGen target, which is not defined unless this
59+
# is included. @j2kun asked the LLVM maintiners for tips on how to fix this,
60+
# see https://github.com/llvm/llvm-project/issues/63135
61+
"NVPTX",
62+
# Needed for Apple M1 targets, see
63+
# https://github.com/j2kun/mlir-tutorial/issues/11
64+
"AArch64",
65+
]
66+
67+
# Configure LLVM project using use_repo_rule
68+
llvm_configure = use_repo_rule("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")
69+
70+
llvm_configure(
71+
name = "llvm-project",
72+
targets = _LLVM_TARGETS,
73+
)
74+
4475
# Yosys dependencies that are already on the bazel central registry.
4576
# abc can't be used in place because it changes the names of the targets from
4677
# abc-lib -> abc and abc -> abc_bin

MODULE.bazel.lock

Lines changed: 128 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

WORKSPACE.bzlmod

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,6 @@
22

33
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
44
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5-
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
6-
7-
# LLVM is pinned to the same commit used in the Google monorepo, and then
8-
# imported into this workspace as a git repository. Then the build files
9-
# defined in the LLVM monorepo are overlaid using llvm_configure in the setup
10-
# script below. This defines the @llvm-project which is used for llvm build
11-
# dependencies.
12-
load("//bazel:import_llvm.bzl", "import_llvm")
13-
14-
import_llvm("llvm-raw")
15-
16-
load("//bazel:setup_llvm.bzl", "setup_llvm")
17-
18-
setup_llvm("llvm-project")
19-
20-
# LLVM doesn't have proper support for excluding the optional llvm_zstd and
21-
# llvm_zlib dependencies but it is supposed to make LLVM faster, so why not
22-
# include it.
23-
# See https://reviews.llvm.org/D143344#4232172
24-
maybe(
25-
http_archive,
26-
name = "llvm_zstd",
27-
build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD",
28-
sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0",
29-
strip_prefix = "zstd-1.5.2",
30-
urls = [
31-
"https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz",
32-
],
33-
)
34-
35-
maybe(
36-
http_archive,
37-
name = "llvm_zlib",
38-
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD",
39-
sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731",
40-
strip_prefix = "zlib-ng-2.0.7",
41-
urls = [
42-
"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip",
43-
],
44-
)
455

466
# install dependencies for yosys/ABC circuit optimizers
477
http_archive(

bazel/BUILD

Whitespace-only changes.

bazel/BUILD.bazel

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22

33
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
44

5-
bzl_library(
6-
name = "import_llvm_bzl",
7-
srcs = ["import_llvm.bzl"],
8-
visibility = ["//visibility:private"],
9-
)
10-
11-
bzl_library(
12-
name = "setup_llvm_bzl",
13-
srcs = ["setup_llvm.bzl"],
14-
visibility = ["//visibility:private"],
15-
)
16-
175
bzl_library(
186
name = "lit_bzl",
197
srcs = ["lit.bzl"],

bazel/extensions.bzl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Module extensions for MLIR Tutorial dependencies."""
2+
3+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
4+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
6+
7+
def _llvm_deps_impl(_):
8+
"""Implementation of the llvm_deps module extension."""
9+
LLVM_COMMIT = "8f264586d7521b0e305ca7bb78825aa3382ffef7"
10+
11+
# Download LLVM/MLIR using a git repository
12+
new_git_repository(
13+
name = "llvm-raw",
14+
build_file_content = "# empty",
15+
commit = LLVM_COMMIT,
16+
init_submodules = False,
17+
remote = "https://github.com/llvm/llvm-project.git",
18+
patches = [
19+
# This patch file contains changes that are fixed in upstream LLVM
20+
# that are (usually) required to build HEIR, but are not included
21+
# as of the LLVM_COMMIT hash above (the fixes are still progressing
22+
# through the automated integration process). The patch file is
23+
# automatically generated, and should not be removed even if empty.
24+
"@heir//patches:llvm.patch",
25+
],
26+
patch_args = ["-p1"],
27+
)
28+
29+
# Optional LLVM dependencies for performance. Not required but the bazel
30+
# build has no way to omit them. See https://reviews.llvm.org/D143344#4232172
31+
maybe(
32+
http_archive,
33+
name = "llvm_zstd",
34+
build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD",
35+
sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0",
36+
strip_prefix = "zstd-1.5.2",
37+
urls = [
38+
"https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz",
39+
],
40+
)
41+
42+
maybe(
43+
http_archive,
44+
name = "llvm_zlib",
45+
build_file = "@llvm-raw//utils/bazel/third_party_build:zlib-ng.BUILD",
46+
sha256 = "e36bb346c00472a1f9ff2a0a4643e590a254be6379da7cddd9daeb9a7f296731",
47+
strip_prefix = "zlib-ng-2.0.7",
48+
urls = [
49+
"https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.0.7.zip",
50+
],
51+
)
52+
53+
llvm_deps = module_extension(
54+
implementation = _llvm_deps_impl,
55+
)

bazel/import_llvm.bzl

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)