Skip to content

feat: expose a build's options to the run step as {build_opts_file} - #256

Open
martin-velay wants to merge 1 commit into
lowRISC:masterfrom
martin-velay:xcelium_reinvoke_simulator
Open

feat: expose a build's options to the run step as {build_opts_file}#256
martin-velay wants to merge 1 commit into
lowRISC:masterfrom
martin-velay:xcelium_reinvoke_simulator

Conversation

@martin-velay

Copy link
Copy Markdown
Contributor

Description

A run step that compiles for itself instead of loading the build's snapshot has to compile the way the build did. Every build now records its options in build_opts.f, named by the hjson as {build_opts_file}.

Comment thread src/dvsim/job/deploy.py Outdated
Comment thread src/dvsim/job/deploy.py Outdated
Comment thread src/dvsim/job/deploy.py Outdated
A run step that compiles for itself instead of loading the build's
snapshot has to compile the way the build did.  Every build now records
its options in build_opts.f, named by the hjson as {build_opts_file}.

Signed-off-by: Martin Velay <mvelay@lowrisc.org>
@martin-velay
martin-velay force-pushed the xcelium_reinvoke_simulator branch from 4843503 to 13e6aca Compare September 1, 2026 10:47

@rswarbrick rswarbrick 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.

This looks nice, and I'm sorry for not getting back more quickly. I've got some suggestions about how to make the code structure a bit clearer, but I'm a fan of the change.

Comment thread src/dvsim/job/deploy.py
Comment on lines +526 to +531
opts_file = Path(self.build_opts_file)
opts_file.parent.mkdir(parents=True, exist_ok=True)
opts_file.write_text(
"".join(f"{opt.strip()}\n" for opt in self.build_opts if opt.strip()),
encoding="UTF-8",
)

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.

I squinted at this for a few minutes. I'm was sad about the repeated calls to opt.strip() and the fact that we concatenate a bunch of lines, appending \n to each. It took me a while to spot that the reason to do so is to ensure there's a \n at the end of the file.

I think the following structure is probably a bit simpler to understand, and also splits up "render an option" from "write a bunch of options to a file". What do you think?

        maybe_options = [opt.strip() for opt in self.build_opts]
        options = [opt for opt in maybe_options if opt]

        opts_file = Path(self.build_opts_file)
        opts_file.parent.mkdir(parents=True, exist_ok=True)
        opts_file.write_text("\n".join(options) + "\n", encoding="UTF-8")

Comment thread src/dvsim/job/deploy.py
self.build_timeout_mins = self.sim_cfg.args.build_timeout_mins

def _write_build_opts_file(self) -> None:
"""Record the options this build used, in the build directory.

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.

I spent a while trying to work out whether there was a more concise way to write this, and make a docstring that's easier to understand. I think this contains all the information we need to convey, and is much easier to understand. Does it look reasonable to you?

        """Write build options to the build directory.

        Doing so allows a run step to recompile and elaborate for itself, without having to
        re-invoke dvsim from scratch. It would be complicated for an external tool to infer these
        options: they depend on lots of configuration files. Writing them out here solves that
        problem.

        """

Comment thread src/dvsim/sim/flow.py
Comment on lines +204 to +207
# Where each build records the options it compiled with, for a run step that compiles for
# itself rather than loading the snapshot the build produced, see
# CompileSim._write_build_opts_file(). The HJSON can name this path as {build_opts_file},
# and can also set it, to move the file or to share one between cfgs.

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.

Please could this comment move to the "declaration" of the field in constructor? (I know that dvsim isn't great at this! But here's an opportunity to do it right :-)

Comment thread tests/job/test_deploy.py
"""Test that a CompileSim records the options it built with, for the run step."""
build_dir = tmp_path / "build" / "dir"
job = _build_compile_sim(
sim_overrides={"build_dir": str(build_dir), "cov_db_dir": str(tmp_path / "cov")},

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.

What does cov_db_dir do here and in the next test?

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