Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.6.1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build
llvm-project
llvm-build
bazel-*
MODULE.bazel.lock
87 changes: 87 additions & 0 deletions BZLMOD_MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Bzlmod Migration Guide

This repository has been migrated to use Bazel's bzlmod system with Bazel version 7.6.1.

## What Changed

### Bazel Version
- Updated `.bazelversion` files to 7.6.1 for both root and stablehlo workspaces

### Module Configuration
- Added `MODULE.bazel` files for both root (mlir-hlo) and stablehlo workspaces
- Configured module dependencies from Bazel Central Registry:
- `bazel_skylib` (1.3.0)
- `rules_cc` (0.0.9)
- `rules_python` (0.30.0)
- `rules_shell` (0.2.0)
- `apple_support` (1.5.0)
- `zlib` (1.3.1.bcr.3) - Used by LLVM
- `zstd` (1.5.6) - Used by LLVM

### LLVM Dependencies (Hybrid Approach)
Since LLVM doesn't support bzlmod natively, we use `WORKSPACE.bzlmod` files to manage the LLVM project dependency:
- `llvm-raw`: The raw LLVM source archive
- `llvm-project`: Configured LLVM project via `llvm_configure`

Note: `zlib` and `zstd` are now managed through the Bazel Central Registry (BCR) in MODULE.bazel files with repo_name mappings (`llvm_zlib` and `llvm_zstd`) for LLVM compatibility.

### File Structure
```
mlir-hlo/
├── .bazelversion (7.6.1)
├── MODULE.bazel (bzlmod dependencies)
├── WORKSPACE.bzlmod (LLVM dependencies)
├── WORKSPACE (kept for compatibility)
├── .gitignore (excludes MODULE.bazel.lock files)
└── stablehlo/
├── .bazelversion (7.6.1)
├── MODULE.bazel (bzlmod dependencies)
├── WORKSPACE.bzlmod (LLVM dependencies)
└── WORKSPACE.bazel (kept for compatibility)
```

### Lock Files
`MODULE.bazel.lock` files are generated by Bazel to ensure reproducible builds but are excluded from version control via `.gitignore`. They will be regenerated automatically when you run Bazel commands.

## Building

The migration is transparent to users. Build commands remain the same:

```bash
# From root workspace
bazel build //path/to:target

# From stablehlo workspace
cd stablehlo && bazel build //:target
```

## Benefits of Bzlmod

1. **Dependency Management**: Automatic version resolution through Bazel Central Registry
2. **Better Isolation**: Each workspace can have its own module configuration
3. **Reproducibility**: MODULE.bazel.lock files ensure reproducible builds
4. **Future-proof**: Bzlmod is the default in Bazel 7.x and beyond
5. **Centralized Dependencies**: Common dependencies like zlib and zstd are managed through BCR

## Hybrid Approach

We use a hybrid approach (bzlmod + WORKSPACE.bzlmod) because:
- LLVM doesn't have a MODULE.bazel file
- WORKSPACE.bzlmod is the recommended way to handle non-bzlmod dependencies in Bazel 7.x
- This allows gradual migration as more dependencies adopt bzlmod
- Common dependencies (zlib, zstd) are managed through BCR when possible

## Verification

To verify the migration:

```bash
# Check Bazel version
bazel --version # Should show 7.6.1

# View module dependency graph
bazel mod graph

# Test LLVM dependency resolution
bazel build --nobuild @llvm-project//llvm:Support
```
33 changes: 33 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2020 The OpenXLA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
module(
name = "mlir-hlo",
version = "0.0.0",
)

bazel_dep(name = "apple_support", version = "1.5.0", repo_name = "build_bazel_apple_support")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_python", version = "0.30.0")
bazel_dep(name = "rules_shell", version = "0.2.0")

# LLVM dependencies - using BCR modules with repo_name for LLVM compatibility
bazel_dep(name = "zlib", version = "1.3.1.bcr.3", repo_name = "llvm_zlib")
bazel_dep(name = "zstd", version = "1.5.6", repo_name = "llvm_zstd")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
is_default = True,
python_version = "3.10",
)
32 changes: 32 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2020 The OpenXLA Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# WORKSPACE.bzlmod for dependencies that don't support bzlmod yet (LLVM)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

LLVM_COMMIT = "ca84f2aa3be6e46a4dccb1bec56b93f2bb3d8ef0"
LLVM_SHA256 = "5cea44df2e0c3dcb6119c2ca5d7a900001e93ec43369ed1b58eb4ed4d4c9f9f0"

http_archive(
name = "llvm-raw",
build_file_content = "# empty",
sha256 = LLVM_SHA256,
strip_prefix = "llvm-project-" + LLVM_COMMIT,
urls = ["https://github.com/llvm/llvm-project/archive/{commit}.tar.gz".format(commit = LLVM_COMMIT)],
)

load("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")

llvm_configure(name = "llvm-project")
2 changes: 1 addition & 1 deletion stablehlo/.bazelversion
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
7.0.2
7.6.1
# Copyright 2023 The StableHLO Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
7 changes: 7 additions & 0 deletions stablehlo/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@
###############################################################################
module(name = "stablehlo")

bazel_dep(name = "apple_support", version = "1.5.0", repo_name = "build_bazel_apple_support")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_python", version = "0.30.0")
bazel_dep(name = "rules_shell", version = "0.2.0")

# LLVM dependencies - using BCR modules with repo_name for LLVM compatibility
bazel_dep(name = "zlib", version = "1.3.1.bcr.3", repo_name = "llvm_zlib")
bazel_dep(name = "zstd", version = "1.5.6", repo_name = "llvm_zstd")

python = use_extension("@rules_python//python/extensions:python.bzl", "python")

Expand Down
Loading