On Fri, Dec 07, 2018 at 07:01:18PM +0000, Adam D. Ruppe via Digitalmars-d-learn 
> On Friday, 7 December 2018 at 17:41:47 UTC, Ron Tarrant wrote:
> > when I compile rather than compiling modules over and over
> > needlessly.
> Oh, lots of us compile everything at once. It works quite well and is
> fast for many applications that you don't need to do anything more.

Yes, the D compiler is fast enough that for a small project, recompiling
everything vs. compile a single source file doesn't make a noticeable
difference in compilation time.

For larger projects, the general recommendation is to use the package as
your unit of recompilation, i.e., if you have your source tree structure
like this:


then when you recompile, if package1/* hasn't been touched, but
package2/mod2.d was changed, then recompile package2/* into a static
library, and relink your application.

The above example is greatly simplified, of course; generally, your
package subdirs would have 10+ source files or so before this sort of
per-package recompilation actually benefits compilation times.  In some
of my projects, where package subdirs are relatively small, I just lump
the source files inside together with everything else and just recompile
the whole thing at once.  IME, separately recompiling individual .d
files generally slows down compilation rather than speed it up -- the
linker has more work to do to resolve cross-references that the compiler
would have statically resolved had you passed all source files at once

> > Does D have the concept of makefiles? I haven't run across any
> > reference to such things so far.
> Yes, you can use a makefile with D basically the same as with C. But
> you may find it actually builds slower than just dmd -i main.d....

This is true for most small to medium-sized projects. For larger
projects, it does help to compile different packages separately (perhaps
in parallel if your build system supports that).

In my own projects, I actually use my build system more to resolve other
complex tasks than to individually compile D source files; I'd just
specify what amounts to `dmd *.d` in a single build rule, and most of
the rest of the build script is to handle other tasks, like generating
code from input data, preprocessing resource files, building/signing
packages, compiling code in other languages (Java, C, etc.),
installation to the staging area for testing, etc.. So ironically, most
of my build rules concern stuff other than compilation.  :-D


Stop staring at me like that! It's offens... no, you'll hurt your eyes!

Reply via email to