Skip to content

Commit 735908f

Browse files
oharboeclaude
andcommitted
bazel: make BUILD files self-documenting per hzeller's review
Address hzeller's review feedback on PR #4208: 1. Replace opaque `orfs_design(designs = DESIGNS)` with explicit `orfs_design(config = "config.mk")` so BUILD files show what drives the build. The DESIGNS dict is baked into a generated wrapper in @orfs_designs//:designs.bzl. 2. Remove all `exports_files()` calls — the orfs_design macro now creates filegroups for design files (config, lef, lib, gds, verilog) with public visibility instead. 3. Source design BUILD files use `files("verilog")` macro which now creates filegroups without exports_files. The bazel-orfs API change is carried as a patch on the pinned commit; will be upstreamed to bazel-orfs once stable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
1 parent d308ca9 commit 735908f

98 files changed

Lines changed: 244 additions & 232 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ BAZEL_ORFS_REMOTE = "https://github.com/The-OpenROAD-Project/bazel-orfs.git"
4545
git_override(
4646
module_name = "bazel-orfs",
4747
commit = BAZEL_ORFS_COMMIT,
48+
patches = ["//bazel:0001-orfs_design-accept-config-mk-explicitly-drop-exports.patch"],
49+
patch_strip = 1,
4850
remote = BAZEL_ORFS_REMOTE,
4951
)
5052

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
diff --git a/private/designs.bzl b/private/designs.bzl
2+
index e0bbc6c..9abde05 100644
3+
--- a/private/designs.bzl
4+
+++ b/private/designs.bzl
5+
@@ -146,8 +146,28 @@ def _orfs_designs_impl(repository_ctx):
6+
"blocks": [],
7+
}
8+
9+
- # Generate designs.bzl
10+
- bzl_content = "DESIGNS = %s\n" % repr(designs)
11+
+ # Generate designs.bzl with both the raw DESIGNS dict (for backward
12+
+ # compatibility) and an orfs_design() wrapper that bakes in DESIGNS
13+
+ # so BUILD files can simply do:
14+
+ # load("@orfs_designs//:designs.bzl", "orfs_design")
15+
+ # orfs_design(config = "config.mk")
16+
+ bzl_content = '''"""Auto-generated design configurations from config.mk files."""
17+
+
18+
+load("@bazel-orfs//private:orfs_design.bzl", _orfs_design = "orfs_design")
19+
+
20+
+DESIGNS = %s
21+
+
22+
+def orfs_design(config = "config.mk", **kwargs):
23+
+ """Create orfs_flow() targets for this design.
24+
+
25+
+ Args:
26+
+ config: The config.mk file that drives this design.
27+
+ Makes the BUILD file self-documenting.
28+
+ **kwargs: Forwarded to the underlying orfs_design implementation
29+
+ (platform, design, mock_openroad, mock_yosys, user_arguments).
30+
+ """
31+
+ _orfs_design(config = config, designs = DESIGNS, **kwargs)
32+
+''' % repr(designs)
33+
repository_ctx.file("designs.bzl", bzl_content)
34+
repository_ctx.file("BUILD.bazel", "")
35+
36+
diff --git a/private/orfs_design.bzl b/private/orfs_design.bzl
37+
index cb607fc..51e88f7 100644
38+
--- a/private/orfs_design.bzl
39+
+++ b/private/orfs_design.bzl
40+
@@ -1,7 +1,10 @@
41+
"""Macro to create orfs_flow() targets from parsed config.mk data.
42+
43+
Call orfs_design() from a design's BUILD.bazel to auto-generate
44+
-orfs_flow() targets based on the design's config.mk.
45+
+orfs_flow() targets based on the design's config.mk:
46+
+
47+
+ load("@orfs_designs//:designs.bzl", "orfs_design")
48+
+ orfs_design(config = "config.mk")
49+
50+
The orfs_designs repository rule (designs.bzl) must be instantiated
51+
first to parse all config.mk files and generate the DESIGNS dict.
52+
@@ -44,22 +47,26 @@ def _convert_sources(sources, pkg):
53+
result[var] = converted
54+
return result
55+
56+
-def orfs_design(name = None, platform = None, design = None, designs = None, mock_openroad = None, mock_yosys = None, user_arguments = []): # buildifier: disable=unused-variable
57+
+def orfs_design(name = None, config = "config.mk", platform = None, design = None, designs = None, mock_openroad = None, mock_yosys = None, user_arguments = []): # buildifier: disable=unused-variable
58+
"""Create orfs_flow() targets for a design based on its parsed config.mk.
59+
60+
- Call this from a design's BUILD.bazel:
61+
- load("@bazel-orfs//:openroad.bzl", "orfs_design")
62+
- load("@orfs_designs//:designs.bzl", "DESIGNS")
63+
- orfs_design(designs = DESIGNS)
64+
+ Usage:
65+
+
66+
+ load("@orfs_designs//:designs.bzl", "orfs_design")
67+
+ orfs_design(config = "config.mk")
68+
69+
The platform and design are auto-detected from the package path
70+
(flow/designs/<platform>/<design>/).
71+
72+
Args:
73+
name: Unused, required by Bazel macro convention.
74+
+ config: The config.mk file that drives this design. Makes the
75+
+ BUILD file self-documenting about what configures the build.
76+
platform: Override platform (default: from package path).
77+
design: Override design nickname (default: from package path).
78+
designs: The DESIGNS dict from the orfs_designs repository rule.
79+
+ Supplied automatically by the generated wrapper in
80+
+ @orfs_designs//:designs.bzl.
81+
mock_openroad: Label for mock-openroad binary. When set, generates
82+
lint flow targets (variant="lint") alongside real flow targets.
83+
Example: "//mock/openroad/src/bin:openroad".
84+
@@ -74,16 +81,17 @@ def orfs_design(name = None, platform = None, design = None, designs = None, moc
85+
ORFS arguments.
86+
"""
87+
if designs == None:
88+
- fail("orfs_design() requires designs argument: pass DESIGNS from @orfs_designs//:designs.bzl")
89+
+ fail("orfs_design() requires designs: load orfs_design from @orfs_designs//:designs.bzl")
90+
91+
- native.exports_files(
92+
- native.glob(["*"]),
93+
- visibility = ["//visibility:public"],
94+
- )
95+
+ # Validate that the config file exists in this package
96+
+ if not native.glob([config], allow_empty = True):
97+
+ fail("orfs_design(): config file %s not found in %s" % (config, native.package_name()))
98+
99+
- # Create filegroups for wildcard source patterns (e.g. ADDITIONAL_LEFS)
100+
+ # Create filegroups for design files so they are accessible to
101+
+ # orfs_flow() rules without using exports_files().
102+
existing_rules = native.existing_rules()
103+
for fg_name, fg_glob in [
104+
+ ("design_config", ["*.mk", "*.sdc", "*.json", "*.cfg", "*.tcl", "*.def"]),
105+
("lef", ["*.lef"]),
106+
("lib", ["*.lib"]),
107+
("gds", ["*.gds.gz"]),

‎flow/BUILD.bazel‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
load("@bazel-orfs//:openroad.bzl", "orfs_pdk")
22

3-
# Export platform files so designs can reference them directly via
4-
# ADDITIONAL_LEFS, ADDITIONAL_LIBS, etc. from PLATFORM_DIR.
5-
exports_files(
6-
["scripts/variables.yaml"] + glob(["platforms/**"]),
7-
visibility = ["//visibility:public"],
8-
)
9-
103
# files shared between scripts/synth.sh and scripts/flow.sh steps
114
MAKEFILE_SHARED = [
125
"scripts/variables.json",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
load("//flow/designs:design.bzl", "design")
22

3-
design()
3+
design(config = "config.mk")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
load("//flow/designs:design.bzl", "design")
22

3-
design()
3+
design(config = "config.mk")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
load("//flow/designs:design.bzl", "design")
22

3-
design()
3+
design(config = "config.mk")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
load("//flow/designs:design.bzl", "design")
22

3-
design()
3+
design(config = "config.mk")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
load("//flow/designs:design.bzl", "design")
22

3-
design()
3+
design(config = "config.mk")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
load("//flow/designs:design.bzl", "design")
22

3-
design()
3+
design(config = "config.mk")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
load("//flow/designs:design.bzl", "design")
22

3-
design()
3+
design(config = "config.mk")

0 commit comments

Comments
 (0)