Skip to content

Klayout dependency#4001

Merged
maliberty merged 7 commits into
The-OpenROAD-Project:masterfrom
Pinata-Consulting:klayout-dependency
Mar 17, 2026
Merged

Klayout dependency#4001
maliberty merged 7 commits into
The-OpenROAD-Project:masterfrom
Pinata-Consulting:klayout-dependency

Conversation

@oharboe

@oharboe oharboe commented Mar 15, 2026

Copy link
Copy Markdown
Collaborator

Make KLayout an optional dependency

KLayout is only needed for GDS generation, DRC, and LVS. Most ORFS
use cases — education, architectural exploration, CI testing, OpenROAD
development — never need GDS output. This PR decouples KLayout so that
make finish and do-finish / do-final complete without it.

What changes

  • finish / do-finish no longer depend on GDS generation
  • New make gds / do-gds target for explicit GDS generation
    (follows existing pattern: place/do-place, finish/do-finish, gds/do-gds)
  • check-klayout guard on all KLayout-dependent targets with a
    helpful error message when KLayout is missing
  • do-klayout / do-klayout_wrap sed-based XML manipulation replaced
    with util/generate_klayout_tech.py (stdlib, no KLayout dependency)
  • def2stream.py refactored into a testable merge_gds() function
    with guarded import pya
  • 34 new unit tests using unittest.mock — run without KLayout
  • CI path triggers widened to flow/util/*.py and flow/test/test_*.py

Backwards compatibility

  • make finish gds produces GDS exactly as before
  • do-gds is unchanged — bazel-orfs can call it from a new
    orfs_gds() rule
  • All existing scripts that run make finish will complete without
    KLayout; they simply no longer attempt GDS generation

bazel-orfs

do-final no longer requires KLayout in the toolchain. A separate
orfs_gds() Bazel rule calling do-gds makes KLayout an optional
dependency configured in MODULE.bazel.

Test plan

  • cd flow/test && python -m unittest test_generate_klayout_tech test_def2stream test_convertDrc (34 tests, no KLayout)
  • make finish DESIGN_CONFIG=designs/nangate45/gcd/config.mk completes without KLayout
  • make gds DESIGN_CONFIG=designs/nangate45/gcd/config.mk fails with helpful message when KLayout is missing
  • make finish gds DESIGN_CONFIG=designs/nangate45/gcd/config.mk produces GDS when KLayout is installed

@oharboe oharboe force-pushed the klayout-dependency branch from 1fcd565 to 4d38cb9 Compare March 15, 2026 08:13
@oharboe

oharboe commented Mar 15, 2026

Copy link
Copy Markdown
Collaborator Author

@hzeller @maliberty TL;DR merge this and only users and developers who need klayout have to install it.

@oharboe oharboe force-pushed the klayout-dependency branch from 4d38cb9 to 73b906f Compare March 15, 2026 08:22
@oharboe oharboe requested a review from maliberty March 15, 2026 08:22
oharboe and others added 4 commits March 15, 2026 09:31
KLayout is a heavy end-user GUI tool that was previously required to
complete the ORFS flow. The `finish` target depended on GDS_FINAL_FILE
and `do-finish` called `do-gds`, meaning the flow could not complete
without KLayout installed — even though most use cases never need GDS.

This change decouples KLayout so it is only pulled in when explicitly
requested via `make gds` / `make do-gds`, following the existing
target naming pattern (place/do-place, finish/do-finish, gds/do-gds).

Makefile changes:
- Remove $(GDS_FINAL_FILE) from `finish` dependencies
- Remove do-gds from `do-finish` recipe
- Add explicit `gds` phony target
- Add `check-klayout` guard on all KLayout-dependent targets
  (GDS merge, DRC, LVS, gallery, klayout viewer shortcuts)

Extract .lyt tech file generation from sed to Python:
- The do-klayout and do-klayout_wrap targets previously used fragile
  sed-based XML manipulation with shell variable expansion and
  ifeq/else branching. New util/generate_klayout_tech.py replaces
  this with stdlib xml/regex processing (no KLayout dependency).

Refactor def2stream.py for testability:
- Extract logic into merge_gds() function with pya as a parameter
- Guard `import pya` so the module can be imported without KLayout
- When run via `klayout -r`, the script behaves identically using
  klayout's -rd global variables

The interface is backwards compatible: `make finish gds` produces GDS
as before, `do-gds` is unchanged, and bazel-orfs can invoke `do-gds`
from a new `orfs_gds()` rule while `do-final` no longer requires
KLayout in the toolchain.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
34 mock-based tests that run without KLayout installed:
- test_generate_klayout_tech.py: .lyt generation including validation
  against real platform templates (nangate45, asap7, sky130hd)
- test_def2stream.py: cell clearing, VIA_ preservation, orphan
  detection, GDS_ALLOW_EMPTY regex, seal file merging, error counting
- test_convertDrc.py: DRC report conversion (box/edge/text violations,
  waived items, comment assembly)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
Use glob patterns (flow/util/*.py, flow/test/test_*.py) instead of
listing individual files, so new test and utility scripts trigger CI
automatically.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@oharboe oharboe force-pushed the klayout-dependency branch from 73b906f to 2337490 Compare March 15, 2026 08:32

@maliberty maliberty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not change the default behavior. Perhaps a new target like signoff could be used for your purpose.

Comment thread flow/docs/KLayoutOptionalDependency.md Outdated
Comment thread flow/docs/KLayoutOptionalDependency.md Outdated
oharboe and others added 2 commits March 15, 2026 22:33
Address PR review: do-targets are internal to bazel-orfs and
don't need user-facing documentation. Use-cases table is
redundant with the introductory paragraph.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
No changes to the non do- versions of targets. bazel-orfs does
not use the finish target; it uses do-finish and can invoke
do-gds as a separate step.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@oharboe

oharboe commented Mar 15, 2026

Copy link
Copy Markdown
Collaborator Author

I would rather not change the default behavior. Perhaps a new target like signoff could be used for your purpose.

Well spotted, thanks!

Fixed.

@maliberty

Copy link
Copy Markdown
Member

hmm... I don't see a new target

@oharboe

oharboe commented Mar 16, 2026

Copy link
Copy Markdown
Collaborator Author

hmm... I don't see a new target

bazel-orfs already has do-gds broken out, so I am good.

Comment thread flow/docs/KLayoutOptionalDependency.md Outdated
Comment thread flow/docs/KLayoutOptionalDependency.md Outdated
Remove speculative write_gds section — document it when relevant.
Clarify why do-finish differs from finish (Make dependency vs recipe).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
@oharboe oharboe requested a review from maliberty March 16, 2026 23:01
@maliberty maliberty merged commit ed40258 into The-OpenROAD-Project:master Mar 17, 2026
9 checks passed
@oharboe oharboe deleted the klayout-dependency branch April 19, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants