Skip to content
Closed
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
50 changes: 42 additions & 8 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ module(
)

bazel_dep(name = "bazel-orfs")

# To bump version, run: bazelisk run @bazel-orfs//:bump
git_override(
module_name = "bazel-orfs",
commit = "f8a4b694b37c8f5322323eba9a9ae37f9541ee17",
commit = "2dbd8f0fa9c1f1cc4bf5d52f680b9116fb204219",
remote = "https://github.com/The-OpenROAD-Project/bazel-orfs.git",
)

Expand All @@ -34,14 +32,50 @@ use_repo(pip, "orfs-pip")

orfs = use_extension("@bazel-orfs//:extension.bzl", "orfs_repositories")

# To bump version, run: bazelisk run @bazel-orfs//:bump
# Use docker image for yosys/klayout, local files for scripts and PDKs
orfs.default(
image = "docker.io/openroad/orfs:v3.0-3273-gedf3d6bf",
# Use local files instead of docker image
image = "docker.io/openroad/orfs:26Q1-755-g7a3f3d5eb",
makefile = "//flow:makefile",
makefile_yosys = "//flow:makefile_yosys",
pdk = "//flow:asap7",
sha256 = "f5692c6325ebcf27cc348e033355ec95c82c35ace1af7e72a0d352624ada143e",
sha256 = "933f0179ba7feca829768ab2daebe6c1b8b458bf656ef4becc251887725ac7be",
variables_yaml = "//flow:scripts/variables.yaml",
)
use_repo(orfs, "com_github_nixos_patchelf_download")
use_repo(orfs, "docker_orfs")

# Uncomment to build OpenROAD from source instead of using the ORFS image.
# This is useful to test the latest OpenROAD before the ORFS image is updated.
# See: https://github.com/The-OpenROAD-Project/bazel-orfs/blob/main/docs/openroad.md
#
# bazel_dep(name = "openroad")
# git_override(
# module_name = "openroad",
# commit = "02507977b328194de770f321d89e3dae9d954a6d",
# init_submodules = True,
# patch_strip = 1,
# patches = ["@bazel-orfs//:openroad-llvm-root-only.patch", "@bazel-orfs//:openroad-visibility.patch"],
# remote = "https://github.com/The-OpenROAD-Project/OpenROAD.git",
# )
# bazel_dep(name = "qt-bazel")
# git_override(
# module_name = "qt-bazel",
# commit = "df022f4ebaa4130713692fffd2f519d49e9d0b97",
# remote = "https://github.com/The-OpenROAD-Project/qt_bazel_prebuilts",
# )
# bazel_dep(name = "toolchains_llvm", version = "1.5.0")

# Auto-generate orfs_flow() targets from config.mk files
orfs_designs = use_repo_rule("//bazel:designs.bzl", "orfs_designs")

orfs_designs(
name = "orfs_designs",
designs_dir = "//flow/designs:BUILD.bazel",
platforms = [
"asap7",
"gf180",
"ihp-sg13g2",
"nangate45",
"sky130hd",
"sky130hs",
],
)
4,201 changes: 301 additions & 3,900 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")

py_library(
name = "config_mk_parser_lib",
srcs = ["config_mk_parser.py"],
visibility = ["//visibility:public"],
)

py_binary(
name = "config_mk_parser",
srcs = ["config_mk_parser.py"],
visibility = ["//visibility:public"],
)

py_binary(
name = "config_mk_lint",
srcs = ["config_mk_parser.py"],
args = [
"--lint",
"--all",
"flow/designs",
],
visibility = ["//visibility:public"],
)

py_test(
name = "config_mk_parser_test",
srcs = ["config_mk_parser_test.py"],
data = glob(["../flow/designs/**/config.mk"]) + glob(["../flow/designs/src/**/*.mk"]),
deps = [":config_mk_parser_lib"],
)
123 changes: 91 additions & 32 deletions bazel/README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,119 @@
# OpenROAD-flow-scripts and Bazel integration

`bazel-orfs` is a Bazel package containing the definitions and logic governing the build process of ORFS designs.
The module uses the `openroad/orfs` docker image to extract the flow scripts with dependencies, builds the Bazel environment around them and defines the methods of calling the ORFS Makefiles with selected designs.
Think in Make, test with Make, get Bazel performance, caching, and parallelism.

## Run examples
## How it works

`flow/BUILD.bazel` contains definitions for various flows to serve as examples.
`config.mk` is the canonical DSL for defining ORFS designs. The Bazel integration
auto-generates `orfs_flow()` targets from these config.mk files using a Python parser,
so you never need to maintain separate BUILD files for your designs.

It is recommended to run the utility [Bazelisk](https://github.com/bazelbuild/bazelisk) to manage the version of `bazel` installed on the system.
Details on installation can be found in the `bazel-orfs` [README](https://github.com/The-OpenROAD-Project/bazel-orfs?tab=readme-ov-file#requirements)
```
config.mk --> config_mk_parser.py --> orfs_flow() targets --> Bazel build
```

The `bazel-orfs` package defines the rules that drive the ORFS Makefile-based flow
through Bazel, giving you:

- **Caching**: unchanged stages are not re-run
- **Parallelism**: independent designs and stages build concurrently
- **Reproducibility**: hermetic builds with pinned tool versions
- **Zero-docker mode**: everything runs from local sources, no Docker image required

## Quick start

The flow can be ran with the following call structure:
Install [Bazelisk](https://github.com/bazelbuild/bazelisk), then:

```bash
bazel build <target_name>_<stage_name>
# Build GCD synthesis for ASAP7
bazel build @orfs_designs//asap7/gcd:gcd_synth

# Build full RTL-to-GDSII flow
bazel build //flow/designs/asap7/gcd:gcd_final

# Build for a different PDK
bazel build //flow/designs/sky130hd/gcd:gcd_final
```

## Adding a new design

Just create a `config.mk` file in `flow/designs/<platform>/<design>/`:

```makefile
export PLATFORM = asap7
export DESIGN_NAME = my_design
export VERILOG_FILES = $(sort $(wildcard $(DESIGN_HOME)/src/$(DESIGN_NAME)/*.v))
export SDC_FILE = $(DESIGN_HOME)/$(PLATFORM)/$(DESIGN_NAME)/constraint.sdc
export CORE_UTILIZATION = 50
```

For example, to run the stage `final`, along with all the dependent stages, call:
Bazel targets auto-appear at `//flow/designs/<platform>/<design>:<design_name>_<stage>`.

## Incremental caching

Bazel only re-runs stages whose inputs changed. The variable metadata from
`flow/scripts/variables.yaml` defines which ORFS variables affect which stages.

For example, if you modify only `CORE_UTILIZATION` in
`flow/designs/asap7/gcd/config.mk`, then:

```bash
bazel build gcd_final
bazel build //flow/designs/asap7/gcd:gcd_place
```

Details on usage and defining of the flows are presented in the Usage section of the `bazel-orfs` [README](https://github.com/The-OpenROAD-Project/bazel-orfs?tab=readme-ov-file#usage)
This re-runs from floorplan onward but **skips synthesis entirely** — because
`variables.yaml` defines `CORE_UTILIZATION` as only affecting floorplan and
later stages, not synthesis. The cached synthesis result is reused.

## Dependency version management
## config.mk DSL

In the flow scipts, the `bazel-orfs` version is defined as
The config.mk DSL is a restricted subset of Make. Supported features:

```starlark
bazel_dep(name = "bazel-orfs")
git_override(
module_name = "bazel-orfs",
commit = "<Hash of the default bazel-orfs commit>",
remote = "https://github.com/The-OpenROAD-Project/bazel-orfs.git",
)
| Feature | Example |
|---------|---------|
| Variable assignment | `export VAR = value` |
| Conditional default | `export VAR ?= value` |
| Clear/immediate | `export VAR :=` |
| Line continuations | `export FILES = a.v \`<br>` b.v` |
| Path variables | `$(DESIGN_HOME)`, `$(PLATFORM)`, `$(DESIGN_NAME)`, `$(DESIGN_NICKNAME)` |
| Glob patterns | `$(sort $(wildcard $(DESIGN_HOME)/src/$(DESIGN_NAME)/*.v))` |
| Hierarchical blocks | `export BLOCKS = sub_macro1 sub_macro2` |

Run the linter to check your config.mk for unsupported features:

```bash
python3 bazel/config_mk_parser.py --lint flow/designs/asap7/gcd/config.mk
```
However, as the referenced documentation shows, the git-based dependency can be overridden with a local repository.
First, remove the `git_override` call entirely and replace it with a `local_path_override` call following this convention:

## Zero-docker mode

The default configuration uses no Docker image. All tools, scripts, PDKs, and
flow infrastructure come from the local repository:

- **Scripts**: `//flow:makefile` and `//flow:makefile_yosys`
- **PDKs**: `//flow:asap7`, `//flow:sky130hd`, etc.
- **OpenROAD**: built from `tools/OpenROAD/` or system-installed

To switch to a Docker-based configuration, set the `image` attribute:

```starlark
local_path_override(
module_name = "bazel-orfs",
path = "/replace/with/path/to/local/orfs/repository"
orfs.default(
image = "docker.io/openroad/orfs:tag",
sha256 = "the-hash",
)
```

`bazel-orfs` sets a default version of the docker image used to create the Bazel environment.
This selection can be overridden by a following snippet inserted below the `bazel-orfs` declaration and override.
## Dependency version management

`bazel-orfs` is referenced in `MODULE.bazel`. To use a local checkout:

```starlark
orfs = use_extension("@bazel-orfs//:extension.bzl", "orfs_repositories")
orfs.default(
image = "tag-name",
sha256 = "the-hash",
local_path_override(
module_name = "bazel-orfs",
path = "/path/to/local/bazel-orfs",
)
```

Substitute `tag-name` with the tag of the version needed and `the-hash` with the digest corresponding to the selected tag (without the `sha256:` prefix).
Details on usage and flow definitions are in the `bazel-orfs`
[README](https://github.com/The-OpenROAD-Project/bazel-orfs?tab=readme-ov-file#usage).

Loading
Loading