From d74966af8fa5049c4157ce29ceef2d809669beca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Harboe?= Date: Mon, 18 May 2026 06:40:17 +0200 Subject: [PATCH] bazel: enable Blender 3D-viewer targets via bazel-orfs bump + addon workaround MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two pieces, bundled because they only make sense together: 1. Bump bazel-orfs ce6efd9 -> 3a5ddd7 (~80 commits of upstream main). This pulls in the orfs_blender() rule plus the layerstack-trim `_LAYER_PRESETS` heuristic in render_gds.py. The previously vendored //bazel:0001-orfs_design-add-user_sources.patch is now upstream as of 5b65b4e so it goes away. 2. Flip `blender = True` once in flow/designs/design.bzl's design() funnel so every design routes through the same blender-supported branch. Designs whose PDK has no BlenderGDS stackup (asap7, nangate45, ...) silently no-op via the upstream `blender_supports_pdk` predicate. A small vendored patch on render_gds.py works around a real bug in the BlenderGDS addon (`UnboundLocalError: pdk_info` inside import_gdsii's custom-config branch); routing the trimmed YAML through `addon.PDK_CONFIGS[pdk]['config_path']` instead of `gdsii_use_custom_config = True` avoids the bug. TODO: upstream the fix to aesc-silicon/BlenderGDS and drop this patch. End-to-end on sky130hd/microwatt (a 562 MB merged GDS), the trim heuristic produces a 123 MB GLB and a 158 MB self-contained HTML viewer in ~71 s of wall time once synth/place/route are cached. gcd-class designs already fit under the addon's full default layerstack so the preset is a no-op for them. Usage: bazelisk run //flow/designs/sky130hd/gcd:gcd_final_blender_html opens the resulting model-viewer page in the default browser via xdg-open. Signed-off-by: Øyvind Harboe Signed-off-by: Øyvind Harboe --- MODULE.bazel | 14 +- bazel/0001-orfs_design-add-user_sources.patch | 153 ------------------ flow/designs/design.bzl | 1 + ..._CONFIGS-not-gdsii_use_custom_config.patch | 49 ++++++ patches/bazel-orfs/BUILD.bazel | 8 + 5 files changed, 65 insertions(+), 160 deletions(-) delete mode 100644 bazel/0001-orfs_design-add-user_sources.patch create mode 100644 patches/bazel-orfs/0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch create mode 100644 patches/bazel-orfs/BUILD.bazel diff --git a/MODULE.bazel b/MODULE.bazel index 8441a582f1..126de82d6f 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -36,22 +36,22 @@ git_override( bazel_dep(name = "bazel-orfs", dev_dependency = True) bazel_dep(name = "bazel-orfs-verilog", dev_dependency = True) -BAZEL_ORFS_COMMIT = "ce6efd96dfe39a9c4ef244f8712386f071545d77" +BAZEL_ORFS_COMMIT = "3a5ddd7eb48c363717e65903ae4573d528327fd3" BAZEL_ORFS_REMOTE = "https://github.com/The-OpenROAD-Project/bazel-orfs.git" # To bump version, run: bazelisk run @bazel-orfs//:bump +# +# `patches =` keeps small bazel-orfs fixes vendored in this repo while +# we iterate, instead of round-tripping every change through a +# bazel-orfs PR + pin bump. When a patch lands upstream, drop the +# entry here and bump BAZEL_ORFS_COMMIT. git_override( module_name = "bazel-orfs", commit = BAZEL_ORFS_COMMIT, patch_strip = 1, patches = [ - # Adds orfs_design(user_sources=[VAR,...]) / orfs_flow(user_sources={...}) - # so design-private SOURCE_VARS path hooks (e.g. SDC_FILE_EXTRA in - # flow/designs/asap7/mock-cpu) bypass the variables.yaml validator - # without polluting the ORFS-wide variable schema. Drop once upstream - # bazel-orfs lands the user_sources= API. - "//bazel:0001-orfs_design-add-user_sources.patch", + "//patches/bazel-orfs:0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch", ], remote = BAZEL_ORFS_REMOTE, ) diff --git a/bazel/0001-orfs_design-add-user_sources.patch b/bazel/0001-orfs_design-add-user_sources.patch deleted file mode 100644 index d22eaef7cf..0000000000 --- a/bazel/0001-orfs_design-add-user_sources.patch +++ /dev/null @@ -1,153 +0,0 @@ -From 58df356479d6d9f04aa0bc3ac3676d3b89d26813 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?=C3=98yvind=20Harboe?= -Date: Thu, 14 May 2026 18:48:12 +0200 -Subject: [PATCH] orfs_design/orfs_flow: add user_sources= for design-private - path hooks -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Symmetric to user_arguments=, but for source-typed (path-label) vars: -a variable that the config_mk_parser classifies as a SOURCE_VAR (path -staged into the sandbox via _map_source_file) but that is read only -by user-supplied .tcl/.mk and has no entry in ORFS variables.yaml. - -Today such a variable bumps into check_variables(sources.keys()) in -orfs_flow and fails the load phase, even though the file itself is -staged correctly. user_arguments= doesn't help because it pops from -arguments, not sources. - -The motivating case is SDC_FILE_EXTRA — set by -flow/designs/asap7/mock-cpu/config.mk and source'd from that design's -io.tcl, with no ORFS-side consumer. SDC_FILE_EXTRA is in this file's -SOURCE_VARS list, so its value is path-staged; making it work without -declaring it as a global ORFS variable is what user_sources= is for. - -API: -- orfs_design() gains user_sources=[VAR, ...]. Each named var is - popped from sources and forwarded as orfs_flow(user_sources={...}). -- orfs_flow() gains user_sources={VAR: [label, ...]}. Merged into - sources before _orfs_pass so files are still staged, but the key - set skips check_variables. Same shadowing guard as user_arguments=: - collision with a known ORFS variable fails fast. - -Mirrors user_arguments= in both surface and intent. - -Signed-off-by: Øyvind Harboe ---- - private/flow.bzl | 19 +++++++++++++++++-- - private/orfs_design.bzl | 19 ++++++++++++++++++- - 2 files changed, 35 insertions(+), 3 deletions(-) - -diff --git a/private/flow.bzl b/private/flow.bzl -index fd9001f..b59d059 100644 ---- a/private/flow.bzl -+++ b/private/flow.bzl -@@ -171,6 +171,7 @@ def orfs_flow( - verilog_files = [], - macros = [], - sources = {}, -+ user_sources = {}, - stage_sources = {}, - stage_arguments = {}, - renamed_inputs = {}, -@@ -213,6 +214,12 @@ def orfs_flow( - validating against ORFS variables.yaml. Use for vars read only by user-supplied .tcl/.mk - (e.g. ARRAY_COLS in a project's MACRO_PLACEMENT_TCL). Keys that collide with known ORFS - variables are rejected — route those through 'arguments' instead. -+ user_sources: dictionary of project-specific source-typed (path-label) env vars to expose -+ to every stage without validating against ORFS variables.yaml. The path is still staged -+ into the sandbox like a normal source — only the variable name skips the validator. -+ Use for path hooks read only by user-supplied .tcl/.mk (e.g. an extra-SDC hook -+ source'd from the design's own io.tcl). Keys that collide with known ORFS variables -+ are rejected — route those through 'sources' instead. - extra_arguments: dictionary keyed by ORFS stages with lists of .json argument file labels. - These .json files are merged into the stage config, providing computed arguments - that flow through OrfsInfo to subsequent stages. -@@ -269,6 +276,14 @@ def orfs_flow( - ) + - "Use arguments= for ORFS variables; reserve user_arguments= for project-specific env vars.", - ) -+ shadowed_srcs = sorted([k for k in user_sources if k in ALL_VARIABLE_TO_STAGES]) -+ if shadowed_srcs: -+ fail( -+ "user_sources contains known ORFS variable(s): {shadowed}. ".format( -+ shadowed = ", ".join(shadowed_srcs), -+ ) + -+ "Use sources= for ORFS variables; reserve user_sources= for project-specific path hooks.", -+ ) - if abstract_stage and last_stage: - fail("abstract_stage and last_stage are mutually exclusive") - if variant == "base": -@@ -281,7 +296,7 @@ def orfs_flow( - top = top, - verilog_files = verilog_files, - macros = macros, -- sources = sources, -+ sources = sources | user_sources, - stage_sources = stage_sources, - stage_arguments = stage_arguments, - renamed_inputs = renamed_inputs, -@@ -319,7 +334,7 @@ def orfs_flow( - top = top, - verilog_files = verilog_files, - macros = macros, -- sources = sources, -+ sources = sources | user_sources, - stage_sources = stage_sources, - stage_arguments = stage_arguments, - renamed_inputs = {}, -diff --git a/private/orfs_design.bzl b/private/orfs_design.bzl -index 554da44..d53d4bd 100644 ---- a/private/orfs_design.bzl -+++ b/private/orfs_design.bzl -@@ -47,7 +47,7 @@ def _convert_sources(sources, pkg): - result[var] = converted - return result - --def orfs_design(name = None, config = "config.mk", platform = None, design = None, designs = None, mock_openroad = None, mock_yosys = None, user_arguments = [], local_arguments = []): # buildifier: disable=unused-variable -+def orfs_design(name = None, config = "config.mk", platform = None, design = None, designs = None, mock_openroad = None, mock_yosys = None, user_arguments = [], user_sources = [], local_arguments = []): # buildifier: disable=unused-variable - """Create orfs_flow() targets for a design based on its parsed config.mk. - - Usage: -@@ -79,6 +79,13 @@ def orfs_design(name = None, config = "config.mk", platform = None, design = Non - Routed through orfs_flow(user_arguments=...) to bypass the - variables.yaml validator instead of being checked as known - ORFS arguments. -+ user_sources: List of source-typed variable names (vars in -+ SOURCE_VARS) that are project-specific path hooks read only -+ by user-supplied .tcl/.mk, not by ORFS itself (e.g. a -+ per-design extra-SDC hook source'd from the design's own -+ io.tcl). Routed through orfs_flow(user_sources=...) so the -+ file is still staged into the sandbox, but the variable -+ name bypasses the variables.yaml validator. - local_arguments: List of variable names that are only used for - $(VAR) expansion within the same config.mk and are not read - by ORFS or by any user .tcl/.mk (e.g. VERILOG_FILES_BLACKBOX, -@@ -195,6 +202,15 @@ def orfs_design(name = None, config = "config.mk", platform = None, design = Non - if var in arguments: - user_args[var] = arguments.pop(var) - -+ # Same idea for source-typed (path-label) project-specific knobs: -+ # variables that are in SOURCE_VARS (so the parser staged the path -+ # as a label) but are read only by user .tcl/.mk and have no -+ # variables.yaml entry. -+ user_srcs = {} -+ for var in user_sources: -+ if var in sources: -+ user_srcs[var] = sources.pop(var) -+ - # Default SYNTH_NUM_PARTITIONS to a static value so that the action graph - # is identical across machines and remote cache hits are possible. Users - # who prefer local parallelism over caching can pass NUM_CPUS explicitly. -@@ -213,6 +229,7 @@ def orfs_design(name = None, config = "config.mk", platform = None, design = Non - arguments = arguments, - user_arguments = user_args, - sources = sources, -+ user_sources = user_srcs, - macros = macros if macros else [], - stage_data = {"synth": extra_data} if extra_data else {}, - tags = tags, --- -2.51.0 - diff --git a/flow/designs/design.bzl b/flow/designs/design.bzl index 09e0f99d0d..b4efc0b1d0 100644 --- a/flow/designs/design.bzl +++ b/flow/designs/design.bzl @@ -74,6 +74,7 @@ def design(config = "config.mk", user_arguments = [], user_sources = [], local_a user_arguments = user_arguments, user_sources = user_sources, local_arguments = local_arguments, + blender = True, ) def files(group, extra_srcs = None): diff --git a/patches/bazel-orfs/0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch b/patches/bazel-orfs/0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch new file mode 100644 index 0000000000..c67b99cffa --- /dev/null +++ b/patches/bazel-orfs/0001-render_gds-monkey-patch-PDK_CONFIGS-not-gdsii_use_custom_config.patch @@ -0,0 +1,49 @@ +From 0010e181efa28210dbf7839e6e6131139cc705bd Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=98yvind=20Harboe?= +Date: Mon, 18 May 2026 00:06:14 +0200 +Subject: [PATCH] render_gds: monkey-patch PDK_CONFIGS instead of + gdsii_use_custom_config + +The addon's gdsii_use_custom_config=True branch in import_gdsii skips +initialising pdk_info and addon_dir, both of which are still used a +few lines later to resolve color_path -- so any non-default +layerstack YAML trips UnboundLocalError inside the addon. + +Patch the addon's PDK_CONFIGS dict at runtime instead, pointing the +selected PDK's config_path entry at our trimmed YAML. The else +branch then fires normally, pdk_info is set, color_path resolves, +and Path's absolute-RHS semantic makes addon_dir / Path(abs_path) +evaluate to the absolute path. +--- + tools/blendergds/render_gds.py | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/tools/blendergds/render_gds.py b/tools/blendergds/render_gds.py +index cbe116c..b53da1e 100644 +--- a/tools/blendergds/render_gds.py ++++ b/tools/blendergds/render_gds.py +@@ -289,11 +289,19 @@ def main(): + # in seconds rather than 5-7 minutes + 16 GB RSS. No-op for + # PDKs without a preset and for designs whose full stack is + # already small enough. ++ # We can't go through the addon's `gdsii_use_custom_config = True` ++ # path: that branch in `import_gdsii` skips initialising ++ # `pdk_info` and `addon_dir`, both of which are still used ++ # afterwards to resolve `color_path` -- so a custom YAML trips ++ # `UnboundLocalError: pdk_info` inside the addon. Instead, ++ # monkey-patch PDK_CONFIGS[pdk]['config_path'] to point at the ++ # trimmed YAML (absolute path -- `addon_dir / Path("/abs")` ++ # evaluates to the absolute path in pathlib, so the else branch ++ # in the addon picks it up correctly). + trimmed = _trim_layerstack(addon, addon_root, args.pdk, tmp) + if trimmed is not None: + yaml_path, kept_layers, missing = trimmed +- bpy.context.scene.gdsii_use_custom_config = True +- bpy.context.scene.gdsii_config_path = str(yaml_path) ++ addon.PDK_CONFIGS.setdefault(args.pdk, {})["config_path"] = str(yaml_path) + _log_phase( + "layerstack-trimmed", + extra=( +-- +2.51.0 + diff --git a/patches/bazel-orfs/BUILD.bazel b/patches/bazel-orfs/BUILD.bazel new file mode 100644 index 0000000000..d5bfbcbe26 --- /dev/null +++ b/patches/bazel-orfs/BUILD.bazel @@ -0,0 +1,8 @@ +"""Vendored patches applied on top of the bazel-orfs git_override pin. + +These are small fixes we keep here to reduce churn while iterating; +when they land upstream, drop the entry from MODULE.bazel and bump +BAZEL_ORFS_COMMIT instead. +""" + +exports_files(glob(["*.patch"]))