Skip to content

Commit abc6ed2

Browse files
committed
refactor: replace Bloop with Bazel BSP for IDE support
Replace deprecated Bloop integration with modern Bazel BSP for Metals IDE support. Changes: - Remove scala_bloop.bzl and tools/deploy.py (deprecated Bloop implementation) - Remove blooplib target (used only for Bloop, caused CI failures) - Remove CI Bloop check (replaced by Smoketests job) - Add .bazelproject to configure BSP target selection - Fix MODULE.bazel: use standard @rules_python for BSP compatibility - Fix generate.bzl: remove allow_single_file from fir_library generator - Fix chisel_test: use @bazel-orfs label for external dependency compatibility - Update README with complete BSP setup instructions - Add .bsp/ and .bazelbsp/ to .gitignore Bazel BSP provides direct integration with Bazel, better accuracy, and active community support. Refs: http://scalameta.org/metals/docs/build-tools/bazel/
1 parent 002b3d6 commit abc6ed2

File tree

12 files changed

+69
-358
lines changed

12 files changed

+69
-358
lines changed

.bazelproject

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
targets:
2+
//chisel:all
3+
//sby:all
4+
5+
allow_manual_targets_sync: false
6+
7+
derive_targets_from_directories: false
8+
9+
enabled_rules:
10+
rules_scala
11+
rules_java
12+
rules_jvm

.github/workflows/ci.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,6 @@ jobs:
2929
run: |
3030
buildifier -lint warn -r .
3131
32-
bloop:
33-
name: Check Bloop
34-
runs-on: ubuntu-22.04
35-
env:
36-
DEBIAN_FRONTEND: "noninteractive"
37-
steps:
38-
- name: Checkout bazel-orfs
39-
uses: actions/checkout@v4
40-
41-
- name: Setup Bazel
42-
uses: bazel-contrib/setup-bazel@0.15.0
43-
with:
44-
bazelisk-cache: true
45-
disk-cache: ${{ github.workflow }}-${{ github.job }}
46-
repository-cache: true
47-
48-
- name: Run Bloop
49-
run: |
50-
bazel run :bloop
51-
5232
test-make-target:
5333
name: ${{ matrix.STAGE_TARGET }}
5434
runs-on: ubuntu-22.04

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ node_modules/
88
build.profile
99
.bloop/
1010
external
11+
12+
.bsp/
13+
.bazelbsp/

BUILD

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ load("@aspect_rules_js//js:defs.bzl", "js_binary")
44
#
55
# load("@bazel-orfs//tools/pin:pin.bzl", "pin_data")
66
load("@bazel-orfs//toolchains/scala:chisel.bzl", "chisel_library")
7-
8-
# Temporarily disabled during BCR rules_scala migration
9-
# load("@bazel-orfs//toolchains/scala:scala_bloop.bzl", "scala_bloop")
10-
load("@bazel_orfs_rules_python//python:defs.bzl", "py_binary")
11-
load("@bazel_orfs_rules_python//python:pip.bzl", "compile_pip_requirements")
127
load("@npm//:defs.bzl", "npm_link_all_packages")
8+
load("@rules_python//python:defs.bzl", "py_binary")
9+
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
1310
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
1411

1512
# Reenable when we add test back in
@@ -545,21 +542,3 @@ sh_binary(
545542
# tags = ["manual"],
546543
# )
547544

548-
# This library lists all the scala files we will be editing in vscode via bloop
549-
chisel_library(
550-
name = "blooplib",
551-
srcs = [
552-
"//chisel:chiselfiles",
553-
"//sby:chiselfiles",
554-
"//toolchains/scala:chiselfiles",
555-
],
556-
deps = [
557-
"@maven//:org_scalatest_scalatest_2_13",
558-
],
559-
)
560-
561-
# Set up bloop (temporarily disabled during migration to BCR rules_scala)
562-
# scala_bloop(
563-
# name = "bloop",
564-
# src = "blooplib",
565-
# )

MODULE.bazel

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,18 @@ load_json_file(
6767
bazel_dep(
6868
name = "rules_python",
6969
version = "1.6.3",
70-
# reduce namespace collisions by prefixing with bazel_orfs
71-
repo_name = "bazel_orfs_rules_python",
7270
)
7371

7472
python = use_extension(
75-
"@bazel_orfs_rules_python//python/extensions:python.bzl",
73+
"@rules_python//python/extensions:python.bzl",
7674
"python",
7775
)
7876
python.toolchain(
7977
ignore_root_user_error = True,
8078
python_version = "3.13",
8179
)
8280

83-
pip = use_extension("@bazel_orfs_rules_python//python/extensions:pip.bzl", "pip")
81+
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
8482
pip.parse(
8583
hub_name = "bazel-orfs-pip",
8684
python_version = "3.13",

generate.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ def _fir_library_impl(ctx):
88
fir = ctx.actions.declare_file(ctx.attr.name + ".fir")
99

1010
args = ctx.actions.args()
11-
args.add("-jar", ctx.file.generator)
1211
args.add_all([ctx.expand_location(opt, ctx.attr.data) for opt in ctx.attr.opts])
1312
args.add("-o", fir)
1413
ctx.actions.run(
@@ -39,7 +38,6 @@ fir_library = rule(
3938
allow_files = True,
4039
),
4140
"generator": attr.label(
42-
allow_single_file = True,
4341
cfg = "exec",
4442
executable = True,
4543
mandatory = True,

pythonwrapper/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@bazel_orfs_rules_python//python:defs.bzl", "py_binary")
1+
load("@rules_python//python:defs.bzl", "py_binary")
22

33
# FIXME emulate python3 and get venv we need from within orfs make
44
py_binary(

toolchains/scala/README.md

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ The project uses **BCR rules_scala 7.1.5** from Bazel Central Registry as the un
99
- Automatically includes Chisel 7.2.0 and its dependencies
1010
- Pre-configures Scala compiler options for Chisel
1111
- Sets up Verilator and firtool for hardware simulation (tests only)
12-
- Maintains API compatibility with existing BUILD files
1312

1413
## Usage
1514

@@ -80,51 +79,68 @@ The `chisel_test` rule includes workarounds for BCR verilator compatibility:
8079
2. **Path resolution**: Automatically sets `VERILATOR_ROOT`, `VERILATOR_BIN`, and `PATH`
8180
3. **Forward compatibility**: Workarounds are conditional and will automatically disable when BCR verilator is fixed
8281

83-
These workarounds are based on previous fixes (commits 0a3c114, c58bf7d) and ensure tests work without manual configuration.
82+
## IDE Support with Bazel BSP
8483

85-
## Migration from Custom Toolchain
84+
This project uses [Bazel BSP](https://github.com/JetBrains/bazel-bsp) (Build Server Protocol) for IDE integration with Metals.
8685

87-
This project was migrated from a custom Scala toolchain (~1500 lines) to BCR rules_scala (~250 lines of wrappers) in early 2025. The Chisel API remained unchanged, requiring no modifications to BUILD files.
86+
### Quick Setup
8887

89-
### Benefits of BCR Migration
88+
1. **Install Bazel BSP**:
89+
```bash
90+
cs install bsp
91+
```
9092

91-
- **Reduced maintenance**: No custom toolchain to maintain
92-
- **Standard compliance**: Uses Bazel community standard
93-
- **Easy upgrades**: Can upgrade rules_scala independently
94-
- **Community support**: Can get help from wider Bazel community
93+
2. **Initialize BSP**:
94+
```bash
95+
cd /path/to/bazel-orfs-local
96+
bsp
97+
```
9598

96-
### What Changed
99+
3. **Configure targets** (`.bazelproject` in project root):
100+
```
101+
targets:
102+
//:blooplib
103+
//chisel:all
104+
//sby:all
97105
98-
**Deleted**:
99-
- Custom Scala toolchain implementation (`impl/`, `args/`, `tools/`, etc.)
100-
- Custom `scala_library`, `scala_binary` rule definitions
106+
allow_manual_targets_sync: false
107+
derive_targets_from_directories: false
101108
102-
**Preserved**:
103-
- Chisel wrapper API (`chisel_*` rules)
104-
- All BUILD files using Chisel rules
109+
enabled_rules:
110+
rules_scala
111+
rules_java
112+
rules_jvm
113+
```
105114

106-
**Modified**:
107-
- `MODULE.bazel`: Uses BCR rules_scala 7.1.5
108-
- `toolchains/scala/chisel.bzl`: Simplified to thin wrappers
115+
4. **Build project first**:
116+
```bash
117+
bazel build //chisel:codegenlib //chisel:applicationlib
118+
```
109119

110-
## Bloop Integration (Disabled)
120+
5. **Open in VSCode** and Metals will auto-connect to BSP
111121

112-
The bloop integration for IDE support is temporarily disabled during the BCR migration:
122+
### Troubleshooting
113123

114-
```python
115-
# Temporarily disabled in BUILD file
116-
# load("@bazel-orfs//toolchains/scala:scala_bloop.bzl", "scala_bloop")
117-
# scala_bloop(name = "bloop", src = "blooplib")
118-
```
124+
**No targets found**:
125+
- Verify `.bazelproject` exists in project root
126+
- Check targets: `bazel query "//chisel:all"`
127+
- Rebuild BSP index: VSCode → "Metals: Import Build"
128+
129+
**Metals doesn't connect**:
130+
- Ensure `bsp` is in PATH: `which bsp`
131+
- Check `.bsp/bazelbsp.json` exists
132+
- Restart: VSCode → "Metals: Restart Build Server"
119133

120-
To re-enable in the future, the `scala_bloop` rule needs to be updated to work with BCR rules_scala.
134+
**No IntelliSense**:
135+
- Wait for initial indexing (check status bar)
136+
- Verify build succeeds: `bazel build //chisel:codegenlib`
137+
- Check logs: VSCode → Output → Metals
121138

122-
## Files
139+
### Resources
123140

124-
- **chisel.bzl**: Main implementation of `chisel_binary`, `chisel_library`, `chisel_test`
125-
- **scala_bloop.bzl**: Bloop integration (currently disabled)
126-
- **BUILD.bazel**: Example usage (empty after migration)
127-
- **README.md**: This file
141+
- [Metals Bazel Documentation](http://scalameta.org/metals/docs/build-tools/bazel/)
142+
- [Bazel BSP Server](https://github.com/JetBrains/bazel-bsp)
143+
- [BSP Protocol Specification](https://build-server-protocol.github.io/)
128144

129145
## See Also
130146

toolchains/scala/chisel.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def chisel_test(name, **kwargs):
235235
"@circt//:bin/firtool",
236236
"@verilator//:bin/verilator",
237237
"@verilator//:verilator_includes",
238-
"//toolchains/verilator:verilator_includer",
238+
"@bazel-orfs//toolchains/verilator:verilator_includer",
239239
] + kwargs.pop("data", [])
240240

241241
# Create the underlying scala_test target

0 commit comments

Comments
 (0)