Skip to content

Commit bf40cc2

Browse files
authored
Bump Bazel version to 8.3.1, migrate to bzlmod and bump LLVM to latest (#49)
* Bump Bazel version to 8.3.1 and migrate to bzlmod * Bazel build and test all works * disable ccache for common build * keep only one line that needed by bzlmod * more edits * remove personal Claude dev * override LLVM target to speed up build * removed since upgraded to bzlmod * bump llvm to latest version * bringup TARGET selections to speed up build * import_llvm.bzl now in extensions.bzl * minor comments removed from extensions.bzl since import_llvm.bzl does not exist * remove empty bazel/BUILD * weird quirk that we need empty BUILD file to run * Bufferization to BufferizePass * update LLVM submodule version used by cmake flow and update CI to use latest file to get llvm commit hash * choose a CI passed LLVM version d9190f8141661bd6120dea61d28ae8940fd775d0
1 parent 1f785bd commit bf40cc2

File tree

19 files changed

+178
-299
lines changed

19 files changed

+178
-299
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
common --enable_bzlmod
12
common --action_env=BAZEL_CXXOPTS=-std=c++17
23
common --cxxopt='-std=c++17'
34
common --deleted_packages=externals

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.4.0
1+
8.3.1

.github/workflows/build_and_test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
with:
2020
path: |
2121
~/.cache/bazel
22-
# add import_llvm.bzl so that a new build occurs after an LLVM commit hash update
23-
key: ${{ runner.os }}-bazel-${{ hashFiles('bazel/import_llvm.bzl') }}-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE') }}
22+
# add extensions.bzl so that a new build occurs after an LLVM commit hash update
23+
key: ${{ runner.os }}-bazel-${{ hashFiles('extensions.bzl') }}-${{ hashFiles('.bazelversion', '.bazelrc', 'MODULE.bazel') }}
2424
restore-keys: |
25-
${{ runner.os }}-bazel-${{ hashFiles('bazel/import_llvm.bzl') }}
25+
${{ runner.os }}-bazel-${{ hashFiles('extensions.bzl') }}
2626
2727
- name: "Run `bazel build`"
2828
run: |

.github/workflows/build_and_test_cmake.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ jobs:
2727
with:
2828
path: |
2929
./externals/llvm-project
30-
key: ${{ runner.os }}-cmake-${{ hashFiles('bazel/import_llvm.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }}
30+
key: ${{ runner.os }}-cmake-${{ hashFiles('extensions.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }}
3131

3232
- name: Cache mlir-tutorial build
3333
id: cache-mlir-tutorial
3434
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # pin@v4.2.3
3535
with:
3636
path: |
3737
./build
38-
key: ${{ runner.os }}-cmake-${{ hashFiles('bazel/import_llvm.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }}
38+
key: ${{ runner.os }}-cmake-${{ hashFiles('extensions.bzl') }}-${{ hashFiles('**/CMakeLists.txt') }}
3939

4040
- name: Git config
4141
run: |
@@ -44,7 +44,7 @@ jobs:
4444
- name: Build LLVM
4545
if: steps.cache-llvm.outputs.cache-hit != 'true'
4646
run: |
47-
LLVM_COMMIT=$(grep LLVM_COMMIT ${GITHUB_WORKSPACE}/bazel/import_llvm.bzl | head -n 1 | cut -d'"' -f 2 )
47+
LLVM_COMMIT=$(grep 'commit = ' ${GITHUB_WORKSPACE}/extensions.bzl | head -n 1 | cut -d'"' -f 2)
4848
git submodule update --init --recursive
4949
cd externals/llvm-project
5050
git checkout ${LLVM_COMMIT}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ bazel-bin
33
bazel-mlir-tutorial
44
bazel-out
55
bazel-testlogs
6+
MODULE.bazel.lock
67

78
# cmake related files
89
# ignore the user specified CMake presets in subproject directories.

MODULE.bazel

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
###############################################################################
2+
# Bazel now uses Bzlmod by default to manage external dependencies.
3+
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
4+
#
5+
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
6+
###############################################################################
7+
8+
module(
9+
name = "mlir_tutorial",
10+
version = "1.0.0",
11+
repo_name = "mlir_tutorial",
12+
)
13+
14+
# Dependencies available in BCR
15+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
16+
bazel_dep(name = "rules_python", version = "1.2.0")
17+
bazel_dep(name = "platforms", version = "0.0.11")
18+
bazel_dep(name = "rules_cc", version = "0.1.1")
19+
bazel_dep(name = "rules_java", version = "8.12.0")
20+
bazel_dep(name = "protobuf", version = "30.1")
21+
bazel_dep(name = "rules_proto", version = "7.1.0")
22+
bazel_dep(name = "rules_pkg", version = "1.1.0")
23+
bazel_dep(name = "re2", version = "2024-07-02.bcr.1")
24+
bazel_dep(name = "abseil-cpp", version = "20250512.1")
25+
bazel_dep(name = "or-tools", version = "9.12")
26+
bazel_dep(name = "eigen", version = "4.0.0-20241125.bcr.2")
27+
bazel_dep(name = "highs", version = "1.11.0")
28+
bazel_dep(name = "pcre2", version = "10.46-DEV")
29+
bazel_dep(name = "glpk", version = "5.0.bcr.4")
30+
bazel_dep(name = "bliss", version = "0.73")
31+
bazel_dep(name = "scip", version = "9.2.0.bcr.3")
32+
bazel_dep(name = "zlib-ng", version = "2.0.7")
33+
34+
# Hedron's Compile Commands Extractor for Bazel
35+
# https://github.com/hedronvision/bazel-compile-commands-extractor
36+
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
37+
git_override(
38+
module_name = "hedron_compile_commands",
39+
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
40+
commit = "0e990032f3c5a866e72615cf67e5ce22186dcb97",
41+
# Replace the commit hash (above) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main).
42+
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
43+
)
44+
45+
# Use module extensions for LLVM and other dependencies that aren't in BCR
46+
mlir_tutorial_deps = use_extension("//:extensions.bzl", "mlir_tutorial_deps")
47+
use_repo(mlir_tutorial_deps,
48+
"llvm-raw",
49+
"llvm_zstd",
50+
"llvm_zlib"
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+
llvm_configure(
70+
name = "llvm-project",
71+
targets = _LLVM_TARGETS,
72+
)
73+
74+
# Configure Python dependencies
75+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
76+
python.toolchain(python_version = "3.13")
77+
use_repo(python, "python_3_13")
78+
79+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
80+
pip.parse(
81+
hub_name = "mlir_tutorial_pip_deps",
82+
python_version = "3.13",
83+
requirements_lock = "//:requirements.txt",
84+
)
85+
use_repo(pip, "mlir_tutorial_pip_deps")

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ the tutorial series and explained in the first article,
3030
The CMake build is maintained, but was added at article 10 (Dialect Conversion)
3131
and will not be explained in the articles.
3232

33+
**Note**: This project has been upgraded to Bazel 8.3.1 and migrated to use
34+
Bzlmod for dependency management, replacing the traditional WORKSPACE file
35+
approach. Dependencies are now managed through `MODULE.bazel` using the
36+
Bazel Central Registry (BCR) where possible.
37+
3338
### Prerequisites
3439

3540
Install Bazelisk via instructions at
@@ -39,6 +44,9 @@ This should create the `bazel` command on your system.
3944
You should also have a modern C++ compiler on your system, either `gcc` or
4045
`clang`, which Bazel will detect.
4146

47+
**Bazel Version**: This project requires Bazel 8.3.1 or newer. The specific
48+
version is pinned in `.bazelversion`.
49+
4250
### Build and test
4351

4452
Run
@@ -48,6 +56,19 @@ bazel build ...:all
4856
bazel test ...:all
4957
```
5058

59+
### Dependency Management
60+
61+
The project uses Bzlmod (MODULE.bazel) for dependency management:
62+
63+
- **Core dependencies**: Managed through Bazel Central Registry (BCR)
64+
- rules_python, rules_java, protobuf, abseil-cpp, or-tools, etc.
65+
- **LLVM dependencies**: Managed through custom module extension
66+
- LLVM/MLIR source code via git repository
67+
- **Development tools**: hedron_compile_commands via git_override
68+
69+
This approach provides better dependency resolution, versioning, and
70+
compatibility compared to the legacy WORKSPACE approach.
71+
5172
## CMake build
5273

5374
CMake is one of two supported build systems for this tutorial. The other is

0 commit comments

Comments
 (0)