Skip to content

make: immediately expand deferred vars, v2 - #4573

Closed
gtkiku wants to merge 2 commits into
The-OpenROAD-Project:masterfrom
gtkiku:immediate-expand
Closed

gtkiku wants to merge 2 commits into
The-OpenROAD-Project:masterfrom
gtkiku:immediate-expand

Conversation

@gtkiku

@gtkiku gtkiku commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Previous approach apparently caused some externally-defined variables to become overwritten, and modifications made in 72eca88 effectively reverted back to the old behaviour of spawning 28k shells for each make invocation. Try to cut that number down to 41 again by explicitly checking if the variables have been externally defined.


@oharboe Does this look alright? ifeq ($(origin ... should be identical to ?= according to the GNU Make manual, and passing variables from outside like PYTHON_EXE=... make ... seems to work on my machine.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates flow/scripts/variables.mk to replace the conditional variable assignment operator ?= with explicit ifeq ($(origin VAR), undefined) checks for PYTHON_EXE, OPENROAD_EXE, OPENSTA_EXE, and YOSYS_EXE. This ensures that these variables are only assigned default values if they are completely undefined, preventing unintended overrides. There are no review comments to assess, and I have no additional feedback to provide.

@oharboe

oharboe commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Let me test it with bazel-orfs, which is my use-case

@openroad-ci

openroad-ci commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

🔍 QoR check

Metrics reflect the PR merge build — i.e. what will land on the target branch.

Commit bad7ca9 · Jenkins build #3 · Baseline: build · View build on dashboard

62 design(s) checked — 0 with regression(s), 0 without a comparable baseline.

@oharboe

oharboe commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks. I tested this: it works, and it doesn't break bazel-orfs. It made me think about a direction that could make the Makefile more environment-agnostic, so that bazel-orfs, Nix and whatever comes next are all first-class, with no special case for any of them.

For one make print-… on nangate45/gcd:

before after
IN_NIX_SHELL=1 15 501 processes 38
plain ORFS 135 43
bazel-orfs 40 40

ORFS already has the mechanism, and bazel-orfs uses it: the environment sets OPENROAD_EXE, OPENSTA_EXE, YOSYS_EXE and PYTHON_EXE, and variables.mk only falls back to the in-tree install. Nix supports this natively, since mkShell exports any extra attribute as an environment variable:

devShells.default = pkgs.mkShell {
  buildInputs = [ ... ];
  OPENROAD_EXE = "${openroad.packages.${system}.default}/bin/openroad";
  OPENSTA_EXE  = "${openroad.packages.${system}.default}/bin/sta";
  YOSYS_EXE    = "${yosys.packages.${system}.default}/bin/yosys";
  PYTHON_EXE   = "${pkgs.python3}/bin/python3";
};

variables.mk then has one path for everyone. Each tool is one ?= pointing at the in-tree install, and whatever the environment supplies wins. With no $(shell) in those defaults they cost nothing and need no origin guard. PYTHON_EXE is the one default that still runs $(shell), so it gets := inside ifeq ($(origin PYTHON_EXE),undefined).

The comment block can carry that as the rule for the future: the environment supplies tool paths, whether it's bazel-orfs, a Nix shell or a user; defaults here never call $(shell). A default that must run a shell is assigned with := inside an origin guard.

One behaviour changes: a Nix shell other than ORFS's flake, with openroad on PATH, would set OPENROAD_EXE the same way every other environment does.

Would you be up for reshaping the PR that way? I don't have Nix to test the flake half.

Two more of the same kind, if you're in there anyway:

  • KLAYOUT_ENV_VAR_IN_PATH has no readers and is re-evaluated every time make exports its environment, so it can be deleted.
  • ihp-sg13g2's ABC_CLOCK_PERIOD_IN_PS ?= $(shell sed …) can be :=, since it's already inside an origin guard.

@oharboe

oharboe commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

@hzeller @maliberty FYI. TL;DR I think we should generalize and narrow the interface of ORFS to support nix and bazel-orfs as first class citizens rather than add more conditional code to the makefiles.

#4573 (comment)

Previous approach apparently caused some externally-defined variables to
become overwritten, and modifications made in 72eca88 effectively
reverted back to the old behaviour of spawning a huge number of shells
for each `make` invocation. Try to cut that number down again by
requiring that the runtime environment provide appropriate values for
PYTHON_EXE, OPENROAD_EXE, OPENSTA_EXE and YOSYS_EXE, otherwise use
ORFS-built tools.

Signed-off-by: ctkiku <kim.kuparinen@tuni.fi>
Signed-off-by: ctkiku <kim.kuparinen@tuni.fi>
@gtkiku

gtkiku commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

I changed OPENROAD_EXE and co. to use ORFS-built tools as a fallback with just ?= and added the environment variables for them in nix.flake. Also rewrote the "HERE BE DRAGONS" comment to hopefully clarify what to (not) do and why. Did the smaller requested changes in two trailing commits.

Couldn't unfortunately test the nix flake, as it's trailing a bit and ORFS uses some commands not used in the flake version. Updating the flake to match the submodule commits shows a build failure in OpenROAD, apparently git is not exposed and CMake tries to fetch some dependencies with it. I did run a flow locally by passing in the variables manually, though.

I'm actually not a Nix user, I was just using IN_NIX_SHELL to lazily use a locally built OpenROAD so I could play around with it, so making the build more env-generic is all good by me :)

Comment thread flow/platforms/ihp-sg13g2/config.mk Resolved
@oharboe

oharboe commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

This PR is still two concerns. I would consider closing it and splitting it into two. That should speed up reviews...

@gtkiku

gtkiku commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Sure, along nix/make changes or removing the unused variable?

@oharboe

oharboe commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Sure, along nix/make changes or removing the unused variable?

ah, so three concerns then? 😄

I'd recommend one PR per concern.

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.

3 participants