Thread overview
Building custom library package with dub
Mar 18, 2017
alex1974
Mar 18, 2017
Basile B.
Mar 18, 2017
alex1974
Mar 18, 2017
Mike Parker
Mar 18, 2017
alex1974
Aug 24, 2017
alexander1974
March 18, 2017
I want to build a custom library with useful extensions to phobos. They should be named like:

extensions.regex
extensions.path
extensions.files
...

Some libraries, like extensions.files contain several files (e.g files.d, filesexceptions.d)

Analog to phobos I would like to import them like
import extensions.files: temporary;

What would be the best approach for the folder layout and dub?
I guess subPackages, but I can't get them to compile and link properly.

Thanks for the help
March 18, 2017
On Saturday, 18 March 2017 at 11:29:43 UTC, alex1974 wrote:
> I want to build a custom library with useful extensions to phobos. They should be named like:
>
> extensions.regex
> extensions.path
> extensions.files
> ...
>
> Some libraries, like extensions.files contain several files (e.g files.d, filesexceptions.d)
>
> Analog to phobos I would like to import them like
> import extensions.files: temporary;
>
> What would be the best approach for the folder layout and dub?
> I guess subPackages, but I can't get them to compile and link properly.
>
> Thanks for the help

You can put everything in a single library. The module names should match to the folder layout:

extensions/regex.d                    // module extensions.regex;
extensions/path.d                     // module extensions.path;
extensions/files/package.d            // module extensions.files;
extensions/files/files_stuff1.d       // module extensions.files.files_stuff1;
extensions/files/files_stuff2.d       // module extensions.files.files_stuff2;

Note the particular case of package.d. To have a module with the same name as a folder you name it package.
March 18, 2017
On Saturday, 18 March 2017 at 12:26:35 UTC, Basile B. wrote:
> On Saturday, 18 March 2017 at 11:29:43 UTC, alex1974 wrote:
>> [...]
>
> You can put everything in a single library. The module names should match to the folder layout:
>
> extensions/regex.d                    // module extensions.regex;
> extensions/path.d                     // module extensions.path;
> extensions/files/package.d            // module extensions.files;
> extensions/files/files_stuff1.d       // module extensions.files.files_stuff1;
> extensions/files/files_stuff2.d       // module extensions.files.files_stuff2;
>
> Note the particular case of package.d. To have a module with the same name as a folder you name it package.

Thanks for the answer.

This simple layout works, but then all parts will be compiled every time. Is there a way to just compile the "sublibraries" which have changed?
March 18, 2017
On Saturday, 18 March 2017 at 12:49:33 UTC, alex1974 wrote:

>
> This simple layout works, but then all parts will be compiled every time. Is there a way to just compile the "sublibraries" which have changed?

By "compiled every time", if you're talking about when using the library as a dependency, that's not quite true. dub will compile dependencies on the first run, then only in specific scenarios, not every time. It's really not a big deal. Take a look at dlib [1], for example. On big monolithic library and I haven't seen anyone complaining.

But if you really want to, take a look at subpackages[2] in the dub docs.

[1] https://github.com/gecko0307/dlib
[2] https://code.dlang.org/package-format?lang=json#sub-packages
March 18, 2017
On Saturday, 18 March 2017 at 13:41:12 UTC, Mike Parker wrote:
> On Saturday, 18 March 2017 at 12:49:33 UTC, alex1974 wrote:
>
>>
>> This simple layout works, but then all parts will be compiled every time. Is there a way to just compile the "sublibraries" which have changed?
>
> By "compiled every time", if you're talking about when using the library as a dependency, that's not quite true. dub will compile dependencies on the first run, then only in specific scenarios, not every time. It's really not a big deal. Take a look at dlib [1], for example. On big monolithic library and I haven't seen anyone complaining.
>
> But if you really want to, take a look at subpackages[2] in the dub docs.
>
> [1] https://github.com/gecko0307/dlib
> [2] https://code.dlang.org/package-format?lang=json#sub-packages

Actually the compiling is fast. But its confusing, that all unittests from all sublibraries are performed every time.
I thought with subpackages I can perform just the test from the part I'm working on.
But I can't get the right layout for the subpackages.
August 24, 2017
On Saturday, 18 March 2017 at 13:47:34 UTC, alex1974 wrote:
> On Saturday, 18 March 2017 at 13:41:12 UTC, Mike Parker wrote:
>> On Saturday, 18 March 2017 at 12:49:33 UTC, alex1974 wrote:
>>
>>>
>>> This simple layout works, but then all parts will be compiled every time. Is there a way to just compile the "sublibraries" which have changed?
>>
>> By "compiled every time", if you're talking about when using the library as a dependency, that's not quite true. dub will compile dependencies on the first run, then only in specific scenarios, not every time. It's really not a big deal. Take a look at dlib [1], for example. On big monolithic library and I haven't seen anyone complaining.
>>
>> But if you really want to, take a look at subpackages[2] in the dub docs.
>>
>> [1] https://github.com/gecko0307/dlib
>> [2] https://code.dlang.org/package-format?lang=json#sub-packages
>
> Actually the compiling is fast. But its confusing, that all unittests from all sublibraries are performed every time.
> I thought with subpackages I can perform just the test from the part I'm working on.
> But I can't get the right layout for the subpackages.

My folder structure looks like

extensions/
  dub.sdl
  regex/
    dub.sdl
    source/
      regex.d
  files/
    dub.sdl
    source/
      package.d
      commons.d
      fileexceptions.d
  ...

the main dub.sdl under extensions/:

dependency "extensions:regex" version="*"
subPackage "./regex/"
dependency "extensions:path" version="*"
subPackage "./path/"
dependency "extensions:files" version="*"
subPackage "./files/"
dependency "extensions:ranges" version="*"
subPackage "./ranges/"
dependency "extensions:arrays" version="*"
subPackage "./arrays/"
dependency "extensions:types" version="*"
subPackage "./types/"

eg regex/dub.sdl:

name "regex"
targetType "library"

"simple" subpackages, like extensions:regex, compile fine with
dub build extensions:regex
but subpackages containing several files won't, like
dub build extensions:files

Also reffering to them from external projects don't work.

Any ideas?