Skip to content

Commit 963cabe

Browse files
oharboeclaude
andcommitted
Add orfs_design() macro and auto-generated targets from config.mk
config.mk is the single source of truth for design configuration. A repository rule parses all config.mk files and generates a DESIGNS dict. Each design's BUILD.bazel calls orfs_design() which creates orfs_flow() targets with properly routed stage arguments. Key components: - bazel/designs.bzl: repo rule that watches config.mk files via repository_ctx.read() and re-parses on changes - bazel/orfs.bzl: orfs_design() macro with BLOCKS support, label filtering for Tier 2 designs, rules-base.json auto-detection - MODULE.bazel: local bazel-orfs, docker image for yosys/klayout, local scripts/PDKs, configurable variables_yaml Incremental caching verified: changing CORE_UTILIZATION rebuilds only floorplan+place (2 actions), synthesis is cached (11 cache hits). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent 7f93e18 commit 963cabe

88 files changed

Lines changed: 682 additions & 215 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎MODULE.bazel‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ module(
88

99
bazel_dep(name = "bazel-orfs")
1010

11-
# To bump version, run: bazelisk run @bazel-orfs//:bump
12-
git_override(
11+
local_path_override(
1312
module_name = "bazel-orfs",
14-
commit = "f8a4b694b37c8f5322323eba9a9ae37f9541ee17",
15-
remote = "https://github.com/The-OpenROAD-Project/bazel-orfs.git",
13+
path = "../bazel-orfs",
1614
)
1715

1816
bazel_dep(name = "rules_python", version = "1.2.0")
@@ -34,14 +32,29 @@ use_repo(pip, "orfs-pip")
3432

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

37-
# To bump version, run: bazelisk run @bazel-orfs//:bump
35+
# Use docker image for yosys/klayout, local files for scripts and PDKs
3836
orfs.default(
39-
image = "docker.io/openroad/orfs:v3.0-3273-gedf3d6bf",
40-
# Use local files instead of docker image
37+
image = "docker.io/openroad/orfs:26Q1-755-g7a3f3d5eb",
38+
sha256 = "933f0179ba7feca829768ab2daebe6c1b8b458bf656ef4becc251887725ac7be",
4139
makefile = "//flow:makefile",
4240
makefile_yosys = "//flow:makefile_yosys",
4341
pdk = "//flow:asap7",
44-
sha256 = "f5692c6325ebcf27cc348e033355ec95c82c35ace1af7e72a0d352624ada143e",
42+
variables_yaml = "//flow:scripts/variables.yaml",
4543
)
46-
use_repo(orfs, "com_github_nixos_patchelf_download")
4744
use_repo(orfs, "docker_orfs")
45+
46+
# Auto-generate orfs_flow() targets from config.mk files
47+
orfs_designs = use_repo_rule("//bazel:designs.bzl", "orfs_designs")
48+
orfs_designs(
49+
name = "orfs_designs",
50+
designs_dir = "//flow/designs:BUILD.bazel",
51+
platforms = [
52+
"asap7",
53+
"gf180",
54+
"ihp-sg13g2",
55+
"nangate45",
56+
"sky130hd",
57+
"sky130hs",
58+
],
59+
)
60+

‎bazel/designs.bzl‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
"""Repository rule that parses config.mk files and generates a .bzl with design configs.
2+
3+
The generated .bzl file contains a DESIGNS dict that orfs_design() reads
4+
to create orfs_flow() targets with properly routed stage arguments.
5+
6+
Each config.mk is read via repository_ctx.read() so that Bazel watches
7+
them and re-fetches the repo when any config.mk changes.
8+
"""
9+
10+
def _find_config_files(repository_ctx, designs_dir, platforms):
11+
"""Walk designs_dir to find all config.mk files."""
12+
configs = []
13+
for platform in platforms:
14+
platform_dir = designs_dir + "/" + platform
15+
# List design directories under this platform
16+
result = repository_ctx.execute(["find", platform_dir, "-name", "config.mk", "-type", "f"])
17+
if result.return_code == 0:
18+
for line in result.stdout.strip().split("\n"):
19+
if line:
20+
configs.append(line)
21+
return configs
22+
23+
def _orfs_designs_impl(repository_ctx):
24+
parser_path = repository_ctx.path(repository_ctx.attr._parser)
25+
designs_path = repository_ctx.path(repository_ctx.attr.designs_dir)
26+
designs_dir = str(designs_path.dirname)
27+
28+
python = repository_ctx.which("python3") or repository_ctx.which("python")
29+
if not python:
30+
fail("python3 not found in PATH")
31+
32+
# Read every config.mk to register them as watched inputs.
33+
# When any config.mk changes, Bazel will re-fetch this repo.
34+
config_files = _find_config_files(
35+
repository_ctx,
36+
designs_dir,
37+
repository_ctx.attr.platforms,
38+
)
39+
for config_file in config_files:
40+
repository_ctx.read(config_file)
41+
42+
platforms_arg = ",".join(repository_ctx.attr.platforms)
43+
result = repository_ctx.execute(
44+
[python, str(parser_path), "--all", designs_dir, "--platforms", platforms_arg, "--json"],
45+
timeout = 120,
46+
)
47+
48+
if result.return_code != 0:
49+
fail("config_mk_parser.py failed (dir=%s):\nstdout: %s\nstderr: %s" % (designs_dir, result.stdout, result.stderr))
50+
51+
if not result.stdout or not result.stdout.strip():
52+
fail("config_mk_parser.py produced no output (dir=%s, stderr=%s)" % (designs_dir, result.stderr))
53+
54+
configs = json.decode(result.stdout)
55+
56+
# Build a dict keyed by "platform/design_nickname"
57+
designs = {}
58+
for config in configs:
59+
platform = config.get("platform", "")
60+
nickname = config.get("design_nickname", "")
61+
name = config.get("design_name", "") or nickname
62+
if not name or not platform or not nickname:
63+
continue
64+
65+
key = "%s/%s" % (platform, nickname)
66+
designs[key] = {
67+
"name": name,
68+
"platform": platform,
69+
"verilog_files": config.get("verilog_files", []),
70+
"sources": config.get("sources", {}),
71+
"arguments": config.get("arguments", {}),
72+
"blocks": config.get("blocks", []),
73+
}
74+
75+
# Also add block_configs as separate entries
76+
for block_config in config.get("block_configs", []):
77+
bp = block_config.get("platform", platform)
78+
bn = block_config.get("design_nickname", "")
79+
bname = block_config.get("design_name", "") or bn
80+
if not bname or not bn:
81+
continue
82+
bkey = "%s/%s" % (bp, bn)
83+
designs[bkey] = {
84+
"name": bname,
85+
"platform": bp,
86+
"verilog_files": block_config.get("verilog_files", []),
87+
"sources": block_config.get("sources", {}),
88+
"arguments": block_config.get("arguments", {}),
89+
"blocks": [],
90+
}
91+
92+
# Generate designs.bzl
93+
bzl_content = 'DESIGNS = %s\n' % repr(designs)
94+
repository_ctx.file("designs.bzl", bzl_content)
95+
repository_ctx.file("BUILD.bazel", "")
96+
97+
orfs_designs = repository_rule(
98+
implementation = _orfs_designs_impl,
99+
attrs = {
100+
"designs_dir": attr.label(
101+
mandatory = True,
102+
),
103+
"platforms": attr.string_list(
104+
default = ["asap7", "sky130hd", "sky130hs", "nangate45", "ihp-sg13g2"],
105+
),
106+
"module_name": attr.string(
107+
default = "orfs",
108+
),
109+
"_parser": attr.label(
110+
default = Label("//bazel:config_mk_parser.py"),
111+
allow_single_file = True,
112+
),
113+
},
114+
)

‎bazel/orfs.bzl‎

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
"""Macro to create orfs_flow() targets from parsed config.mk data."""
2+
3+
load("@bazel-orfs//:openroad.bzl", "orfs_flow")
4+
load("@orfs_designs//:designs.bzl", "DESIGNS")
5+
6+
def _convert_sources(sources, pkg):
7+
"""Convert absolute source labels to relative when in the current package.
8+
9+
Filters out unresolvable labels (unresolved Make variables, invalid paths).
10+
"""
11+
result = {}
12+
for var, labels in sources.items():
13+
converted = []
14+
for label in labels:
15+
# Skip unresolved Make variables
16+
if "$(" in label or "${" in label:
17+
continue
18+
# Skip invalid paths like //./
19+
if "//." in label:
20+
continue
21+
# Skip platform paths — already included in PDK
22+
if "//flow/platforms/" in label:
23+
continue
24+
# Skip partial patterns and directory refs
25+
if "*" in label or "))" in label:
26+
continue
27+
# Skip empty targets (trailing colon with no name)
28+
if label.endswith(":"):
29+
continue
30+
if label.startswith("//" + pkg + ":"):
31+
label = ":" + label.split(":")[1]
32+
converted.append(label)
33+
if converted:
34+
result[var] = converted
35+
return result
36+
37+
def orfs_design(platform = None, design = None):
38+
"""Create orfs_flow() targets for a design based on its parsed config.mk.
39+
40+
Call this from a design's BUILD.bazel:
41+
load("//bazel:orfs.bzl", "orfs_design")
42+
orfs_design()
43+
44+
The platform and design are auto-detected from the package path
45+
(flow/designs/<platform>/<design>/).
46+
47+
Args:
48+
platform: Override platform (default: from package path).
49+
design: Override design nickname (default: from package path).
50+
"""
51+
pkg = native.package_name() # e.g., "flow/designs/asap7/gcd"
52+
parts = pkg.split("/")
53+
54+
if not platform and len(parts) >= 3:
55+
platform = parts[2] # "asap7"
56+
if not design and len(parts) >= 4:
57+
design = parts[3] # "gcd"
58+
59+
key = "%s/%s" % (platform, design)
60+
if key not in DESIGNS:
61+
fail("No parsed config.mk for %s. Run the linter: " +
62+
"python3 bazel/config_mk_parser.py --lint flow/designs/%s/config.mk" % (key, key))
63+
64+
config = DESIGNS[key]
65+
name = config["name"]
66+
sources = _convert_sources(config["sources"], pkg)
67+
68+
# Auto-detect rules-base.json if present in the package
69+
if "RULES_JSON" not in sources and native.glob(["rules-base.json"], allow_empty = True):
70+
sources["RULES_JSON"] = [":rules-base.json"]
71+
72+
# Handle BLOCKS: create sub-macro orfs_flow() targets
73+
macros = []
74+
for block_name in config.get("blocks", []):
75+
block_key = "%s/%s" % (platform, "%s_%s" % (design, block_name))
76+
77+
# Sub-macro config may use <design>_<block> or just <block> as nickname
78+
block_config = DESIGNS.get(block_key)
79+
if not block_config:
80+
# No parsed config for this block — skip
81+
# (block may use block.mk or other non-standard config)
82+
continue
83+
84+
block_verilog = [
85+
vf for vf in block_config["verilog_files"]
86+
if "$(" not in vf and "${" not in vf and "//." not in vf and not vf.endswith(":")
87+
]
88+
block_sources = _convert_sources(block_config["sources"], pkg)
89+
orfs_flow(
90+
name = block_config["name"],
91+
abstract_stage = "cts",
92+
verilog_files = block_verilog,
93+
pdk = "//flow:" + platform,
94+
arguments = block_config["arguments"],
95+
sources = block_sources,
96+
)
97+
macros.append(":%s_generate_abstract" % block_config["name"])
98+
99+
# Filter verilog_files: skip unresolved Make variables and invalid labels
100+
verilog_files = []
101+
for vf in config["verilog_files"]:
102+
# Skip unresolved Make variables and partial patterns
103+
if "$(" in vf or "${" in vf or "*" in vf or "))" in vf:
104+
continue
105+
# Skip invalid paths
106+
if "//." in vf or vf.endswith(":"):
107+
continue
108+
# Skip platform paths — already in PDK
109+
if "//flow/platforms/" in vf:
110+
continue
111+
# Skip directory references (VERILOG_INCLUDE_DIRS)
112+
if vf.endswith(":include") or "/include" in vf.split(":")[-1]:
113+
continue
114+
verilog_files.append(vf)
115+
116+
orfs_flow(
117+
name = name,
118+
verilog_files = verilog_files,
119+
pdk = "//flow:" + platform,
120+
arguments = config["arguments"],
121+
sources = sources,
122+
macros = macros if macros else [],
123+
)

‎flow/designs/BUILD.bazel‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports_files(["BUILD.bazel"])
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("//bazel:orfs.bzl", "orfs_design")
2+
3+
exports_files(glob(["*"]))
4+
5+
orfs_design()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("//bazel:orfs.bzl", "orfs_design")
2+
3+
exports_files(glob(["*"]))
4+
5+
orfs_design()

‎flow/designs/asap7/aes/BUILD.bazel‎

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,5 @@
1-
load("@bazel-orfs//:openroad.bzl", "orfs_flow", "orfs_synth")
1+
load("//bazel:orfs.bzl", "orfs_design")
22

3-
BLACKBOXES = [
4-
"aes_sbox",
5-
"aes_key_expand_128",
6-
"aes_cipher_top",
7-
]
3+
exports_files(glob(["*"]))
84

9-
[orfs_synth(
10-
name = "{name}_netlist_synth".format(name = name),
11-
arguments = {
12-
"SDC_FILE": "$(location :constraint.sdc)",
13-
"SYNTH_BLACKBOXES": " ".join([b for b in BLACKBOXES if b != name]),
14-
},
15-
data = [":constraint.sdc"],
16-
module_top = name,
17-
variant = "netlist",
18-
verilog_files = ["//flow/designs/src/aes:verilog"],
19-
) for name in BLACKBOXES]
20-
21-
[filegroup(
22-
name = "{name}_netlist".format(name = name),
23-
srcs = ["{name}_netlist_synth".format(name = name)],
24-
output_group = "1_synth.v",
25-
) for name in BLACKBOXES]
26-
27-
filegroup(
28-
name = "netlists",
29-
srcs = [":{}_netlist".format(name) for name in BLACKBOXES],
30-
)
31-
32-
orfs_flow(
33-
name = "aes_cipher_top",
34-
arguments = {
35-
"ABC_AREA": "1",
36-
"CORE_UTILIZATION": "40",
37-
"CORE_ASPECT_RATIO": "1",
38-
"CORE_MARGIN": "2",
39-
"PLACE_DENSITY": "0.65",
40-
"TNS_END_PERCENT": "100",
41-
},
42-
sources = {
43-
"SDC_FILE": [":constraint.sdc"],
44-
"SYNTH_NETLIST_FILES": [":netlists"],
45-
},
46-
top = "aes_cipher_top",
47-
)
5+
orfs_design()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("//bazel:orfs.bzl", "orfs_design")
2+
3+
exports_files(glob(["*"]))
4+
5+
orfs_design()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("//bazel:orfs.bzl", "orfs_design")
2+
3+
exports_files(glob(["*"]))
4+
5+
orfs_design()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("//bazel:orfs.bzl", "orfs_design")
2+
3+
exports_files(glob(["*"]))
4+
5+
orfs_design()

0 commit comments

Comments
 (0)