On Wed, 04 Sep 2019 22:30:20 GMT, Anonymouse wrote:

(Crossposting from the normal dlang forums since no replies there.)

Manjaro/Arch x86_64, dub 1.16.0 from official repositories.

I have a project where the source is mixed library, mixed application, and I'd like to separate the two. The code is fairly decoupled as is, but the files are all next to each other in the same namespace.

I moved out the library parts and made a new dub package, and it alone compiles fine. Ideally I'd like to separate it further into subpackages in a tree-like structure where some depend on others (but not the other way around), for separate compilation.


$ dub build

$ dub build :a
Performing "debug" build using /usr/bin/dmd for x86_64.
test:a ~master: building configuration "library"...

$ dub build :b
Performing "debug" build using /usr/bin/dmd for x86_64.
test:b ~master: building configuration "library"...
b/b.d(2,8): Error: module `a` is in file 'test/a.d' which cannot be read
import path[0] = /usr/include/dlang/dmd
/usr/bin/dmd failed with exit code 1.

Is what I'm trying to do not possible? I thought test:b would just use the generated libtest_a.a because of the dependency declaration, but the -v build command says otherwise. Am I not understanding it right? I tried adding importPaths "." to the subPackages section in dub.sdl in hope it would see it but it did nothing. importPaths "a" does nothing either. Only adding sourcePaths does, which then makes it compile a.b twice.

Do I need to add the source paths for "upstream" subpackages after all? Is that kind of relation where a subpackage uses the compiled libraries of its fellow subpackages not supported?

The problem is that the path of the two files is out of sync with the module name. This still works as along as all files are specified on the same (DMD) command line, but generally breaks the module name based file lookup. To correct this, the directory structure should be as follows:

├── a
│   └── test
│       └── a.d
├── b
│   └── test
│       └── b.d
└── dub.sdl

and then specify importPaths explicitly:

subPackage {
     name "a"
     targetType "library"
     sourcePaths "a"
     importPaths "a"

subPackage {
     name "b"
     targetType "library"
     dependency "test:a" version="*"
     sourcePaths "b"
     importPaths "b"