Am 11.12.2013 09:05, schrieb Jacob Carlborg:> I tried to start to use Dub for one of my project and noticed a problem. Dub builds all files in one go. This leads to a couple of problems:

  1. Compiler flags are applied to all files when they in fact should only be applied to a limited set of files (those of a project)

  2. Require linking of functions not actually used. An example of this is Tango which depends on zlib. But when Tango is built as a static library

those functions are only pulled in to the executable if they're used in the executable. Since Dub builds all files in one go they will always be
pulled in to the executable, regardless if they're used in the code or not

Sounds like the compiler should be smarter here. Wasn't there some issue that DMD always emits all symbols in Posix systems, which is supposed to be fixed by a proper "export" definition?

It would be better if Dub compiled each package separately, then link everything together.

It's planned to make that the default behavior and the first step was already taken in 0.9.20 (caching the build result of each package). It will be the next addition to the build system, but I don't know when exactly I can get around to do it. See also https://github.com/rejectedsoftware/dub/wiki/Separate-compilation-and-caching-of-dependencies.

I guess the first issue not as big issue but the second issue is a blocker for me.
I will not link with zlib when my application doesn't require it. Is there a workaround?

A workaround is to define two configurations in each dependency, the first "library" one just outputs a "library" target as normal, and a second "import" configuration defines the necessary flags for importing that library (consisting of only import folders + the library import flags).

Then each dependency needs to be built once using "dub build (dependency)" and the main project should put a "subConfigurations": {"(dependency)": "import"} entry for each such dependency to use the pre-compiled version.

Well, hopefully this workaround won't be necessary for long.