Skip to content

Commit 163df18

Browse files
oharboeclaude
andcommitted
bazel: carry OpenROAD-SYN bazel-orfs support as git_override patches
Four patches on the pinned BAZEL_ORFS_COMMIT, to be upstreamed once the status-suite churn settles: - 0001: SYNTH_USE_SYN engine selection in the synth stage rule; declare logs/1_synth.json in both engine modes (generate_metadata previously never saw synth__* metrics in bazel); orfs_test honors its cmd attr. - 0002: synthesis-only flows (last_stage="synth") get the same metadata/test/update_rules/update chain as full flows, gated on RULES_JSON — with FLOW_VARIANT=syn this selects rules-syn.json. - 0003: orfs_update copies only rules.json (cp of the stage's whole DefaultInfo broke bazelisk run <design>_update for everyone). - 0004: orfs_design(extra=) caller hook so ORFS's config.mk DSL layer owns the OpenROAD-SYN status policy. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent d909283 commit 163df18

6 files changed

Lines changed: 499 additions & 0 deletions

‎MODULE.bazel‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,20 @@ BAZEL_ORFS_COMMIT = "6ebadeb4be5c9ada103081c9a5e668c014126616"
106106
BAZEL_ORFS_REMOTE = "https://github.com/The-OpenROAD-Project/bazel-orfs.git"
107107

108108
# To bump version, run: bazelisk run @bazel-orfs//:bump
109+
#
110+
# The patches carry OpenROAD-SYN support (SYNTH_USE_SYN engine selection,
111+
# synthesis-only metadata/test chain, orfs_design extension hook) until
112+
# they are upstreamed; see patches/bazel-orfs/BUILD.bazel.
109113
git_override(
110114
module_name = "bazel-orfs",
111115
commit = BAZEL_ORFS_COMMIT,
116+
patch_strip = 1,
117+
patches = [
118+
"//patches/bazel-orfs:0001-synth-support-OpenROAD-SYN-engine-SYNTH_USE_SYN-1-an.patch",
119+
"//patches/bazel-orfs:0002-flow-emit-metadata-test-update-chain-for-synthesis-o.patch",
120+
"//patches/bazel-orfs:0003-update-copy-only-rules.json-in-the-orfs_update-scrip.patch",
121+
"//patches/bazel-orfs:0004-design-caller-extension-hook-for-per-design-status-t.patch",
122+
],
112123
remote = BAZEL_ORFS_REMOTE,
113124
)
114125

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?=C3=98yvind=20Harboe?= <oyvind.harboe@zylin.com>
3+
Date: Thu, 16 Jul 2026 16:14:51 +0200
4+
Subject: [PATCH 1/4] synth: support OpenROAD-SYN engine (SYNTH_USE_SYN=1) and
5+
declare 1_synth.json
6+
7+
SYNTH_USE_SYN=1 in the merged arguments switches the synthesis stage from
8+
the yosys flow to OpenROAD's built-in synthesizer: a single do-1_synth
9+
action (synth_syn.tcl) consuming the staged Verilog sources directly.
10+
Yosys canonicalization outputs are stubbed (lint-mode precedent) so the
11+
provider tail is engine-agnostic. Parallel/hierarchical yosys synthesis
12+
vars are ignored in SYN mode, matching the Makefile.
13+
14+
Also declare logs/1_synth.json (written by flow.sh's openroad -metrics)
15+
in both engine modes and surface it via LoggingInfo.jsons: without it,
16+
generate_metadata never saw any synth__* metrics and metadata-check
17+
failed on rules-base.json's synth rules.
18+
19+
orfs_test: honor the existing cmd attr instead of hardcoding
20+
metadata-check.
21+
22+
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
23+
---
24+
private/rules.bzl | 176 ++++++++++++++++++++++++++++++++++------------
25+
1 file changed, 131 insertions(+), 45 deletions(-)
26+
27+
diff --git a/private/rules.bzl b/private/rules.bzl
28+
index 2c77c53..00925d4 100644
29+
--- a/private/rules.bzl
30+
+++ b/private/rules.bzl
31+
@@ -573,8 +573,9 @@ if [ ! -e external ]; then
32+
# Needed as of Bazel >= 8
33+
ln -sf $(realpath $(pwd)/..) external
34+
fi
35+
-{make} --file {makefile} {moreargs} metadata-check
36+
+{make} --file {makefile} {moreargs} {cmd}
37+
""".format(
38+
+ cmd = ctx.attr.cmd,
39+
make = ctx.executable._make.short_path,
40+
makefile = ctx.file._makefile.path,
41+
moreargs = environment_string(
42+
@@ -744,9 +745,14 @@ orfs_run_executable = rule(
43+
44+
CANON_OUTPUT = "1_1_yosys_canonicalize.rtlil"
45+
SYNTH_OUTPUTS = ["1_2_yosys.v", "1_2_yosys.sdc", "1_synth.sdc", "mem.json"]
46+
+
47+
+# Outputs of the OpenROAD-SYN synthesis flow (SYNTH_USE_SYN=1). synth_syn.tcl
48+
+# always writes the ODB, the canonicalized SDC and a gate-level Verilog
49+
+# netlist (LEC input); none of the yosys-flow files exist in this mode.
50+
+SYN_OUTPUTS = ["1_synth.odb", "1_synth.sdc", "1_synth.v"]
51+
SYNTH_REPORTS = ["synth_stat.txt", "synth_mocked_memories.txt"]
52+
53+
-def _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs, synth_reports, num_partitions, save_odb, all_arguments = {}):
54+
+def _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs, synth_jsons, synth_reports, num_partitions, save_odb, all_arguments = {}):
55+
"""Parallel synthesis: keep → kept-json → N partitions → merge.
56+
57+
Yosys is not deterministic when using host threads, so SYNTH_NUM_PARTITIONS
58+
@@ -1101,7 +1107,12 @@ def _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs,
59+
if save_odb:
60+
odb_commands = [_make_cmd(ctx)] + generation_commands(
61+
[synth_outputs["1_synth.odb"]],
62+
- )
63+
+ ) + [
64+
+ # flow.sh writes logs/1_synth.json during do-1_synth; guarantee a
65+
+ # parseable declared output either way (genMetrics json.load()s it).
66+
+ "[ -s {p} ] || echo '{{}}' > {p}".format(p = f.path)
67+
+ for f in synth_jsons
68+
+ ]
69+
ctx.actions.run_shell(
70+
arguments = [
71+
"--file",
72+
@@ -1123,7 +1134,7 @@ def _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs,
73+
deps_inputs(ctx),
74+
],
75+
),
76+
- outputs = [synth_outputs["1_synth.odb"], synth_outputs["1_synth.sdc"]],
77+
+ outputs = [synth_outputs["1_synth.odb"], synth_outputs["1_synth.sdc"]] + synth_jsons,
78+
tools = yosys_and_flow_tools,
79+
)
80+
81+
@@ -1152,41 +1163,55 @@ def _yosys_impl(ctx):
82+
),
83+
)
84+
85+
+ # Engine selection: SYNTH_USE_SYN=1 in the merged arguments switches the
86+
+ # synthesis stage from the yosys flow to OpenROAD's built-in synthesizer
87+
+ # (the Makefile's synth_syn path). Analysis-time only: the value must
88+
+ # come through arguments/stage_arguments, not extra_arguments .json files.
89+
+ use_syn = all_arguments.get("SYNTH_USE_SYN") == "1"
90+
+
91+
canon_logs = declare_artifacts(ctx, "logs", ["1_1_yosys_canonicalize.log"])
92+
93+
canon_output = declare_artifact(ctx, "results", CANON_OUTPUT)
94+
95+
- # SYNTH_NETLIST_FILES will not create an .rtlil file or reports, so we need
96+
- # an empty placeholder in that case.
97+
- commands = [_make_cmd(ctx)] + generation_commands(
98+
- canon_logs + [canon_output],
99+
- )
100+
+ if use_syn:
101+
+ # OpenROAD-SYN has no yosys canonicalization; stub its outputs
102+
+ # (lint-mode precedent) so the provider/deploy tail below is
103+
+ # identical in both engine modes. genMetrics.py treats the empty
104+
+ # RTLIL like a missing file when hashing.
105+
+ for f in canon_logs + [canon_output]:
106+
+ ctx.actions.write(output = f, content = "")
107+
+ else:
108+
+ # SYNTH_NETLIST_FILES will not create an .rtlil file or reports, so we need
109+
+ # an empty placeholder in that case.
110+
+ commands = [_make_cmd(ctx)] + generation_commands(
111+
+ canon_logs + [canon_output],
112+
+ )
113+
114+
- ctx.actions.run_shell(
115+
- arguments = [
116+
- "--file",
117+
- ctx.file._makefile_yosys.path,
118+
- "yosys-dependencies",
119+
- "do-yosys-canonicalize",
120+
- ],
121+
- command = EXPAND_VERILOG_DIRS + " && ".join(commands),
122+
- env = config_overrides(
123+
- ctx,
124+
- verilog_arguments(ctx.files.verilog_files) |
125+
- yosys_environment(ctx) |
126+
- config_environment(config),
127+
- ),
128+
- inputs = depset(
129+
- [config] + ctx.files.verilog_files + ctx.files.extra_configs,
130+
- transitive = [
131+
- data_inputs(ctx),
132+
- pdk_inputs(ctx),
133+
- deps_inputs(ctx),
134+
+ ctx.actions.run_shell(
135+
+ arguments = [
136+
+ "--file",
137+
+ ctx.file._makefile_yosys.path,
138+
+ "yosys-dependencies",
139+
+ "do-yosys-canonicalize",
140+
],
141+
- ),
142+
- outputs = [canon_output] + canon_logs,
143+
- tools = yosys_inputs(ctx),
144+
- )
145+
+ command = EXPAND_VERILOG_DIRS + " && ".join(commands),
146+
+ env = config_overrides(
147+
+ ctx,
148+
+ verilog_arguments(ctx.files.verilog_files) |
149+
+ yosys_environment(ctx) |
150+
+ config_environment(config),
151+
+ ),
152+
+ inputs = depset(
153+
+ [config] + ctx.files.verilog_files + ctx.files.extra_configs,
154+
+ transitive = [
155+
+ data_inputs(ctx),
156+
+ pdk_inputs(ctx),
157+
+ deps_inputs(ctx),
158+
+ ],
159+
+ ),
160+
+ outputs = [canon_output] + canon_logs,
161+
+ tools = yosys_inputs(ctx),
162+
+ )
163+
164+
num_partitions = int(all_arguments.get("SYNTH_NUM_PARTITIONS", "0"))
165+
if num_partitions == 0 and all_arguments.get("SYNTH_KEEP_MODULES"):
166+
@@ -1194,31 +1219,92 @@ def _yosys_impl(ctx):
167+
# when NUM_CPUS-based auto-detection hasn't run (direct orfs_synth call).
168+
kept_count = len(all_arguments["SYNTH_KEEP_MODULES"].split(" "))
169+
num_partitions = max(1, kept_count)
170+
+ if use_syn:
171+
+ # Parallel/hierarchical synthesis is a yosys-flow concept; the
172+
+ # Makefile's SYNTH_USE_SYN path ignores SYNTH_KEEP_MODULES and
173+
+ # SYNTH_NUM_PARTITIONS (e.g. asap7/swerv_wrapper carries both
174+
+ # with SYNTH_USE_SYN=1), so never take the partitioned branch.
175+
+ num_partitions = 0
176+
177+
save_odb = ctx.attr.save_odb
178+
-
179+
- synth_logs = declare_artifacts(ctx, "logs", ["1_2_yosys.log", "1_2_yosys_metrics.log"] + (["1_synth.log"] if save_odb else []))
180+
-
181+
- synth_outputs = {}
182+
- for output in SYNTH_OUTPUTS + (["1_synth.odb"] if save_odb else []):
183+
- synth_outputs[output] = declare_artifact(ctx, "results", output)
184+
+ if use_syn and not save_odb:
185+
+ fail("SYNTH_USE_SYN=1 always writes 1_synth.odb; save_odb=False is " +
186+
+ "not supported in " + str(ctx.label))
187+
+
188+
+ # logs/1_synth.json: metrics that flow.sh's `openroad -metrics` writes
189+
+ # during do-1_synth. Declared so generate_metadata (which merges
190+
+ # logs/1_*.json via genMetrics.py) sees the synth__* metrics.
191+
+ if use_syn:
192+
+ synth_logs = declare_artifacts(ctx, "logs", ["1_synth.log"])
193+
+ synth_jsons = declare_artifacts(ctx, "logs", ["1_synth.json"])
194+
+ synth_outputs = {o: declare_artifact(ctx, "results", o) for o in SYN_OUTPUTS}
195+
+ else:
196+
+ synth_logs = declare_artifacts(ctx, "logs", ["1_2_yosys.log", "1_2_yosys_metrics.log"] + (["1_synth.log"] if save_odb else []))
197+
+ synth_jsons = declare_artifacts(ctx, "logs", ["1_synth.json"] if save_odb else [])
198+
+ synth_outputs = {}
199+
+ for output in SYNTH_OUTPUTS + (["1_synth.odb"] if save_odb else []):
200+
+ synth_outputs[output] = declare_artifact(ctx, "results", output)
201+
202+
synth_reports = declare_artifacts(ctx, "reports", SYNTH_REPORTS)
203+
204+
variables = declare_artifact(ctx, "results", "1_synth.vars")
205+
206+
+ # Ensure declared metrics .json outputs exist and are parseable even if
207+
+ # make did not write them; genMetrics.py json.load()s every 1_*.json, so
208+
+ # the fallback must be "{}" rather than a touched empty file.
209+
+ json_fallback = [
210+
+ "[ -s {p} ] || echo '{{}}' > {p}".format(p = f.path)
211+
+ for f in synth_jsons
212+
+ ]
213+
+
214+
if ctx.attr.lint:
215+
# Lint mode: only canonicalization runs; stub remaining synth outputs.
216+
for f in synth_outputs.values() + synth_logs + synth_reports + [variables]:
217+
ctx.actions.write(output = f, content = "")
218+
+ for f in synth_jsons:
219+
+ ctx.actions.write(output = f, content = "{}")
220+
+ elif use_syn:
221+
+ # OpenROAD-SYN synthesis: one openroad invocation (synth_syn.tcl via
222+
+ # do-1_synth) consumes the staged Verilog sources directly, so
223+
+ # VERILOG_FILES is set from ctx.files.verilog_files exactly like the
224+
+ # yosys canonicalize action does. Uses the full flow makefile
225+
+ # filegroup (synth_syn.tcl sources load.tcl etc.), no yosys tools.
226+
+ commands = [_make_cmd(ctx)] + generation_commands(
227+
+ synth_logs + synth_reports,
228+
+ ) + json_fallback
229+
+ ctx.actions.run_shell(
230+
+ arguments = [
231+
+ "--file",
232+
+ ctx.file._makefile.path,
233+
+ "do-1_synth",
234+
+ ],
235+
+ command = EXPAND_VERILOG_DIRS + " && ".join(commands),
236+
+ env = config_overrides(
237+
+ ctx,
238+
+ verilog_arguments(ctx.files.verilog_files) |
239+
+ flow_environment(ctx) |
240+
+ config_environment(config),
241+
+ ),
242+
+ inputs = depset(
243+
+ [config] + ctx.files.verilog_files + ctx.files.extra_configs,
244+
+ transitive = [
245+
+ data_inputs(ctx),
246+
+ pdk_inputs(ctx),
247+
+ deps_inputs(ctx),
248+
+ ],
249+
+ ),
250+
+ outputs = synth_outputs.values() + synth_logs + synth_jsons + synth_reports,
251+
+ tools = flow_inputs(ctx),
252+
+ progress_message = "OpenROAD-SYN synthesis for %s" % module_top(ctx),
253+
+ )
254+
elif num_partitions > 0:
255+
- _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs, synth_reports, num_partitions, save_odb, all_arguments)
256+
+ _yosys_parallel_synth(ctx, config, canon_output, synth_outputs, synth_logs, synth_jsons, synth_reports, num_partitions, save_odb, all_arguments)
257+
else:
258+
# SYNTH_NETLIST_FILES will not create an .rtlil file or reports, so we need
259+
# an empty placeholder in that case.
260+
commands = [_make_cmd(ctx)] + generation_commands(
261+
synth_logs + synth_outputs.values() + synth_reports,
262+
- )
263+
+ ) + json_fallback
264+
ctx.actions.run_shell(
265+
arguments = [
266+
"--file",
267+
@@ -1242,7 +1328,7 @@ def _yosys_impl(ctx):
268+
deps_inputs(ctx),
269+
],
270+
),
271+
- outputs = synth_outputs.values() + synth_logs + synth_reports,
272+
+ outputs = synth_outputs.values() + synth_logs + synth_jsons + synth_reports,
273+
tools = depset(transitive = [yosys_inputs(ctx), flow_inputs(ctx)]),
274+
)
275+
276+
@@ -1324,7 +1410,7 @@ def _yosys_impl(ctx):
277+
exe,
278+
config = config_short,
279+
make = make,
280+
- genfiles = [config_short] + outputs + canon_logs + synth_logs,
281+
+ genfiles = [config_short] + outputs + canon_logs + synth_logs + synth_jsons,
282+
)
283+
284+
# Collect all files needed for deployment (tools, PDK, stage inputs).
285+
@@ -1364,7 +1450,7 @@ def _yosys_impl(ctx):
286+
name = ctx.attr.name + "_deps",
287+
)
288+
289+
- _runfiles_files = [config_short, make] + outputs + canon_logs + synth_logs + ctx.files.extra_configs
290+
+ _runfiles_files = [config_short, make] + outputs + canon_logs + synth_logs + synth_jsons + ctx.files.extra_configs
291+
_runfiles_common = depset(
292+
transitive = [
293+
deps_inputs(ctx),
294+
@@ -1444,7 +1530,7 @@ def _yosys_impl(ctx):
295+
logs = depset(canon_logs + synth_logs),
296+
reports = depset(synth_reports),
297+
drcs = depset([]),
298+
- jsons = depset([]),
299+
+ jsons = depset(synth_jsons),
300+
),
301+
]
302+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?=C3=98yvind=20Harboe?= <oyvind.harboe@zylin.com>
3+
Date: Thu, 16 Jul 2026 16:16:38 +0200
4+
Subject: [PATCH 2/4] flow: emit metadata/test/update chain for synthesis-only
5+
flows
6+
7+
When last_stage="synth", orfs_flow() now emits the same
8+
generate_metadata -> test -> update_rules -> update target chain as the
9+
full flow, fed directly from the synth stage and gated on RULES_JSON.
10+
With FLOW_VARIANT-scoped rules (rules-<variant>.json) this enables
11+
synthesis-only QoR gates such as rules-syn.json for the OpenROAD-SYN
12+
status suite.
13+
14+
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
15+
---
16+
private/flow.bzl | 45 +++++++++++++++++++++++++++++++++++++++++++++
17+
1 file changed, 45 insertions(+)
18+
19+
diff --git a/private/flow.bzl b/private/flow.bzl
20+
index aa8f3e3..0cedbe0 100644
21+
--- a/private/flow.bzl
22+
+++ b/private/flow.bzl
23+
@@ -829,3 +829,48 @@ def _orfs_pass(
24+
logs = [rules_name],
25+
**_strip_tool_kwargs(**update_kwargs)
26+
)
27+
+ elif steps[-1].stage == "synth" and start_stage <= 1 and not mock_area:
28+
+ # Synthesis-only flow (last_stage = "synth"): emit the same
29+
+ # metadata → test → update_rules → update chain as the full flow,
30+
+ # fed straight from the synth stage. genMetrics.py tolerates a
31+
+ # synthesis-only tree (no 2_floorplan.sdc, no stage 2..6 logs).
32+
+ # Gated on RULES_JSON like the full-flow test: without rules
33+
+ # there is nothing for metadata-check to check.
34+
+ test_args = get_stage_args(
35+
+ TEST_STAGE_IMPL.stage,
36+
+ stage_arguments,
37+
+ arguments,
38+
+ sources,
39+
+ )
40+
+ if "RULES_JSON" in test_args:
41+
+ do_step(
42+
+ GENERATE_METADATA_STAGE_IMPL,
43+
+ steps[-1],
44+
+ data = [
45+
+ # Stage synth's logs (1_synth.log, 1_synth.json) via
46+
+ # data_runfiles; source_inputs deliberately omits
47+
+ # LoggingInfo.logs, and genMetrics.py reads both.
48+
+ _step_name(name, variant, "synth"),
49+
+ ],
50+
+ kwargs = kwargs,
51+
+ )
52+
+ do_step(
53+
+ TEST_STAGE_IMPL,
54+
+ GENERATE_METADATA_STAGE_IMPL,
55+
+ kwargs = kwargs | {"tags": []} | test_kwargs,
56+
+ )
57+
+ rules_name = do_step(
58+
+ UPDATE_RULES_IMPL,
59+
+ GENERATE_METADATA_STAGE_IMPL,
60+
+ kwargs = kwargs,
61+
+ more_kwargs = kwargs,
62+
+ )
63+
+ update_kwargs = dict(kwargs)
64+
+ update_kwargs.pop("substeps", None)
65+
+ update_kwargs.pop("lint", None)
66+
+ orfs_update(
67+
+ name = _step_name(name, variant, "update"),
68+
+ rules_json = sources["RULES_JSON"][0],
69+
+ logs = [rules_name],
70+
+ **_strip_tool_kwargs(**update_kwargs)
71+
+ )

0 commit comments

Comments
 (0)