Skip to content

Add --batch-compile to compile files of a library in one call - #1236

Open
ru551n wants to merge 11 commits into
VUnit:masterfrom
ru551n:batch-compile
Open

ru551n wants to merge 11 commits into
VUnit:masterfrom
ru551n:batch-compile

Conversation

@ru551n

@ru551n ru551n commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #1235, and built on it. Only the commits after "Compile in parallel only with --parallel-compile" are new; the rest are #1235 and will drop out once it is merged.

Adds --batch-compile, which compiles the VHDL files of a library that are ready at the same time in one call to the compiler, instead of one call per file. Most of the time of compiling a file goes into starting the compiler and updating the library, so a clean compile gets several times faster. This is the automatic form of the soft file groups discussed in #1088: a clean compile batches, while an incremental compile of a few files compiles them one at a time. It can be used on its own or together with --parallel-compile.

What was added

  • Batches: when the scheduler starts a file, it also takes the other waiting files of the same library whose dependencies are compiled, or are earlier in the batch. The files of a batch are passed in compile order.
  • Which files are batched: only VHDL files whose compile commands are identical apart from the file name at the end, so files with different compile options, VHDL standards or libraries are compiled in separate calls. A simulator opts in with supports_batch_compile; GHDL, NVC and Riviera-PRO do. GHDL does not batch files compiled with coverage, whose .gcno files it moves one file at a time.
  • Command length: NVC and Riviera-PRO read the file names of a batch from a file list (nvc -a @file, one name per line, and vcom -f file, quoted names), written to the output path and removed after the call. GHDL gets the file names in the command, because its response files handle neither quotes nor escapes, so a name with a space cannot be listed. A GHDL batch therefore ends before its command gets longer than 32,000 characters, below the 32,767 characters of a command line on Windows, and the remaining files go into the next batch. A file name a file list cannot hold, with a line break for NVC or a double quote for Riviera-PRO, makes its batch fail, so the batch is compiled one file at a time.
  • Failures: a batch that fails is compiled again one file at a time, so the failing file is reported and its dependents are skipped as before. GHDL writes nothing for a batch that fails.
  • Read rule: the library rule of Add --parallel-compile to compile files in parallel #1235 applies to every file of a batch.

Measured

A clean compile (--compile --clean) of hdl-modules, 330 files, wall time including VUnit's start-up, median of 3 runs:

NVC GHDL Riviera-PRO*
one file at a time 5.99 s 7.37 s 11.83 s
--parallel-compile -p 16 (#1235) 1.65 s 5.97 s 7.49 s
--batch-compile 2.19 s 2.44 s 4.26 s
--batch-compile --parallel-compile -p 16 1.42 s 1.64 s 2.66 s

* With --keep-compiling, because hdl-modules does not compile completely with Riviera-PRO on master either ('latency attribute in sine_calculator.vhd). Every Riviera-PRO run compiled the same 327 files, failed the same 2 and skipped the same 2. The batch containing sine_calculator.vhd failed and was compiled again one file at a time, which exercises the fallback.

Every NVC and GHDL run compiled all 330 files. With both flags, GHDL goes from 7.37 s to 1.64 s, where --parallel-compile alone gives 5.97 s.

Tested

  • New unit tests: files of a library compiled in one call, separate calls per library and per compile options, a failed batch compiled again one file at a time with its dependents skipped, and batches with --parallel-compile with and without concurrent compiles into a library. The last case covers a crash found while measuring, when a batch took a file the scheduler had not reached yet.
  • Unit tests for splitting a batch at the command length limit, for a file list that keeps a batch in one call, and for Riviera-PRO's quoted file list with a name containing a space. With Riviera-PRO, a batch including quo"te.vhd fails and its three files then compile one at a time.
  • Windows Riviera-PRO 2026.04 (under Wine): the VUnit uart example, copied to C:\fl\my proj, compiles all 147 files with and without --batch-compile, and with --parallel-compile -p 4, and its 6 tests pass after a batched compile.
  • A UI test for --batch-compile.
  • The unit and lint tests pass.
  • GHDL stress test: 10 clean hdl-modules compiles with --batch-compile --parallel-compile -p 32 compiled all 330 files every time.

🤖 Generated with Claude Code

ru551n and others added 4 commits October 15, 2026 11:25
A file is compiled as soon as the files it depends on are compiled, up to
-p files at a time. Files of a library are compiled one at a time, since
GHDL and Riviera-PRO update the index of a library without locking it and
lose units when compiled into concurrently. NVC locks its libraries and
compiles files of a library at the same time. The output of a file is
written once it is compiled so that outputs do not mix. GHDL compiles one
file at a time with gcc coverage, which writes .gcno files to the working
directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GHDL rewrites the index of a library by deleting it and renaming a new
one into place, so a compile reading the library in between fails with
"cannot find resource library". Unless a simulator locks its libraries, a
file is not compiled while its library is read, or while a library it
reads, that of any of its dependencies, is compiled into.

A library clause fails in GHDL on a library nothing has been compiled
into, which a file compiled in parallel may come before. GHDL creates
every library with ghdl -i when setting up the library mapping.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without it, files are compiled one at a time whatever -p is, so that a
-p given for running tests does not change how files are compiled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ru551n
ru551n marked this pull request as ready for review October 15, 2026 12:34
ru551n and others added 6 commits October 15, 2026 14:40
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Most of the time of compiling a file goes into starting the compiler and
updating the library. With --batch-compile, the VHDL files of a library
that are ready to be compiled at the same time, and whose compile
commands only differ in the file name, are compiled in one call. A batch
that fails is compiled again one file at a time, to find the file that
fails. GHDL, NVC and Riviera-PRO support it; GHDL does not batch files
compiled with coverage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A command line on Windows has at most 32767 characters, which the file
names of a large library can exceed. A batch ends before its command
gets longer than 32000 characters, on every platform so that it behaves
the same everywhere, and the remaining files go into the next batch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NVC reads the file names of a batch from a file given as @file, one name
per line, and Riviera-PRO from vcom -f, quoted, so their batches are not
limited by the length of a command line. GHDL keeps the limit, since its
response files handle neither quotes nor escapes. A file whose name
cannot be listed, with a line break for NVC or a double quote for
Riviera-PRO, is compiled on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A file name cannot contain a double quote on Windows, so that case is
skipped there. The interface is created with its prefix and version
lookup mocked, like in the other tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A file name that a file list cannot hold, with a line break for NVC or a
double quote for Riviera-PRO, makes its batch fail, which compiles the
files of the batch one at a time. The checks for those names are
removed. The line of a file list is a format string rather than a
method, and the batch tests share the project setup of the compile
tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant