|
| 1 | +# Platform config.py variable rules |
| 2 | + |
| 3 | +Rules for writing and consuming platform `config.py` files. |
| 4 | + |
| 5 | +## Path variables must stay symbolic |
| 6 | + |
| 7 | +Output values must use `$(PLATFORM_DIR)/...` and `$(PLATFORM)`, never |
| 8 | +baked-in absolute paths. Consumers expand on their end: |
| 9 | + |
| 10 | +- **Make shim**: `$(eval)` expands `$(PLATFORM_DIR)` and `$(PLATFORM)` |
| 11 | + naturally, matching the original config.mk behavior. |
| 12 | +- **bazel-orfs**: Python string substitution when the Bazel rule |
| 13 | + executes. The sandbox has platform files at a different path than |
| 14 | + the developer's machine. |
| 15 | + |
| 16 | +`PlatformConfig._unexpand()` handles this automatically at output time. |
| 17 | + |
| 18 | +### Variables that use $(PLATFORM_DIR) |
| 19 | + |
| 20 | +All 6 platforms. Every path-valued variable: `TECH_LEF`, `SC_LEF`, |
| 21 | +`LIB_FILES`, `GDS_FILES`, `PDN_TCL`, `TAPCELL_TCL`, `FASTROUTE_TCL`, |
| 22 | +`KLAYOUT_TECH_FILE`, `RCX_RULES`, `LATCH_MAP_FILE`, etc. |
| 23 | + |
| 24 | +### Variables that use $(PLATFORM) |
| 25 | + |
| 26 | +sky130hd, sky130hs only. Used in filenames within `$(PLATFORM_DIR)`: |
| 27 | +`KLAYOUT_TECH_FILE`, `KLAYOUT_DRC_FILE`, `CDL_FILE`, `KLAYOUT_LVS_FILE`. |
| 28 | + |
| 29 | +Example: `$(PLATFORM_DIR)/$(PLATFORM).lyt` not `$(PLATFORM_DIR)/sky130hd.lyt`. |
| 30 | + |
| 31 | +## Assignment semantics |
| 32 | + |
| 33 | +| Syntax | PlatformConfig method | Behavior | |
| 34 | +|--------|----------------------|----------| |
| 35 | +| `=` | `cfg.set(key, val)` | Unconditional. Always sets. | |
| 36 | +| `?=` | `cfg.set(key, val, conditional=True)` | Set only if not already defined (internally or in env). | |
| 37 | +| `+=` | `cfg.append(key, val)` | Append to existing value. Reads env if not set internally. | |
| 38 | + |
| 39 | +## Glob results |
| 40 | + |
| 41 | +`$(sort $(wildcard ...))` and `$(wildcard ...)` require real filesystem |
| 42 | +paths at config.py runtime. `PlatformConfig.sorted_glob()` and |
| 43 | +`wildcard_glob()` use the real `platform_dir` for glob operations. |
| 44 | +The `_unexpand()` step replaces the prefix back to `$(PLATFORM_DIR)` |
| 45 | +in output. |
| 46 | + |
| 47 | +## Environment variable inputs |
| 48 | + |
| 49 | +These env vars are **read** by config.py to control logic but do NOT |
| 50 | +appear as `$(...)` references in output: |
| 51 | + |
| 52 | +| Input | Platforms | Purpose | |
| 53 | +|-------|-----------|---------| |
| 54 | +| `CORNER` | asap7, gf180 | Select lib files (BC/WC/TC) | |
| 55 | +| `TRACK_OPTION` | gf180 | Track variant (9t/7t) | |
| 56 | +| `METAL_OPTION` | gf180 | Metal stack (5LM_1TM) | |
| 57 | +| `KVALUE` | gf180 | K value (9/11) | |
| 58 | +| `POWER_OPTION` | gf180 | Power variant (5v0/3v3) | |
| 59 | +| `LIB_MODEL` | asap7 | NLDM or CCS | |
| 60 | +| `ASAP7_USE_VT` | asap7 | VT list (RVT LVT SLVT) | |
| 61 | +| `CLUSTER_FLOPS` | asap7 | Enable flop clustering | |
| 62 | +| `BLOCKS` | asap7 | Hierarchical block PDN | |
| 63 | +| `FOOTPRINT_TCL` | ihp-sg13g2 | IO placement file | |
| 64 | +| `LOAD_ADDITIONAL_FILES` | ihp-sg13g2 | Enable IO libs/lefs | |
| 65 | +| `SDC_FILE` | ihp-sg13g2 | Parsed for clock period | |
| 66 | +| `ABC_CLOCK_PERIOD_IN_PS` | ihp-sg13g2 | Override clock period | |
| 67 | + |
| 68 | +These env vars are **concatenated into output values** (their content |
| 69 | +is embedded in variables like `LIB_FILES`, `GDS_FILES`): |
| 70 | + |
| 71 | +| Input | Output vars | Platforms | |
| 72 | +|-------|-------------|-----------| |
| 73 | +| `ADDITIONAL_LIBS` | `LIB_FILES` | all 6 | |
| 74 | +| `ADDITIONAL_GDS` | `GDS_FILES` | all 6 | |
| 75 | +| `ADDITIONAL_LEFS` | `ADDITIONAL_LEFS` | ihp-sg13g2, asap7 | |
| 76 | +| `ADDITIONAL_SLOW_LIBS` | `SLOW_LIB_FILES` | ihp-sg13g2 | |
| 77 | +| `ADDITIONAL_FAST_LIBS` | `FAST_LIB_FILES` | ihp-sg13g2 | |
| 78 | +| `ADDITIONAL_TYP_LIBS` | `TYP_LIB_FILES` | ihp-sg13g2 | |
| 79 | +| `BC_ADDITIONAL_LIBS` | `BC_CCS_LIB_FILES` | asap7 | |
| 80 | + |
| 81 | +In Make, these come from design configs as concrete paths. In bazel-orfs, |
| 82 | +the Bazel rule provides them — no `$(...)` syntax. |
| 83 | + |
| 84 | +## Why variables.mk does not need porting |
| 85 | + |
| 86 | +`variables.mk` computes tool paths (`OPENROAD_EXE`, `YOSYS_EXE`, |
| 87 | +`KLAYOUT_CMD`), output directories (`LOG_DIR`, `RESULTS_DIR`), macro |
| 88 | +wrappers (`WRAPPED_LEFS`), stream format selection (`GDS` vs `OAS`), |
| 89 | +and Make debugging introspection. This is Make-flow plumbing that |
| 90 | +bazel-orfs replaces with Bazel-native equivalents. The only shared |
| 91 | +concern is platform config variables, which `config.py` provides. |
| 92 | + |
| 93 | +## Make functions already resolved by config.py |
| 94 | + |
| 95 | +These Make constructs appeared in the original config.mk files. config.py |
| 96 | +resolves all of them — none leak into output: |
| 97 | + |
| 98 | +| Make function | Python equivalent | Platforms | |
| 99 | +|---------------|-------------------|-----------| |
| 100 | +| `$(sort $(wildcard ...))` | `sorted_glob()` | nangate45 | |
| 101 | +| `$(wildcard ...)` | `wildcard_glob()` | sky130hd, sky130hs, gf180 | |
| 102 | +| `$(abspath ...)` | `os.path.abspath()` | gf180 | |
| 103 | +| `$(realpath ...)` | `os.path.realpath()` | asap7 | |
| 104 | +| `$(origin VAR)` | `"VAR" in os.environ` | ihp-sg13g2 | |
| 105 | +| `$(shell sed ...)` | `re.search()` | ihp-sg13g2 | |
| 106 | +| `$(foreach)/$(eval)` | `for` loop | asap7 | |
| 107 | +| `$(subst ...)` | `str.replace()` | asap7 | |
| 108 | +| `$(patsubst ...)` | `str.replace()` | asap7 | |
| 109 | +| `$(addsuffix ...)` | string concat | asap7 | |
| 110 | +| `$(word N,...)` | `str.split()[N]` | asap7 | |
| 111 | +| `$(wordlist ...)` | `str.split()[N:]` | asap7 | |
| 112 | +| `$(strip ...)` | `str.strip()` | asap7 | |
| 113 | +| `$(if ...)` | `if` statement | asap7 | |
0 commit comments