Install multiple executables with DUB

WebFreak001 d.forum at webfreak.org
Fri Sep 4 08:18:44 UTC 2020


On Thursday, 3 September 2020 at 08:22:25 UTC, glis-glis wrote:
> Hi,
>
> I have a few modules for parsing different file formats and a 
> folder with d-scripts using these parsers to perform 
> manipulations, extract information, ...
>
> Until now, I just added
> #!/usr/bin/env rdmd
>
> to the d-scripts and run them that way, but I'd like to make 
> the scripts available to my collaborators without them being 
> required to install dmd & co, so I'll have to compile the 
> scripts.
>
> I usually would just write a makefile for that, but I thought 
> I'd give DUB a go. Unfortunately, the DUB-documentation is a 
> little thin and I cannot find a way to tell DUB
> "compile all the files in the scripts folder and put the binary 
> to the bin folder". How do I do that?
>
> Thanks!

Option 1: (recommended for multiple single file binaries)

use preBuildCommands to invoke dub or dmd for each of your 
scripts you need

Compatibility tip: use the special $DUB and $DC variables, see 
https://dub.pm/package-format-json.html#environment-variables

If built often, consider using rdmd for easy caching or make this 
a sub-package which you depend on which will therefore only be 
rebuilt in case of changes to that sub-path folder. Add a glob of 
"extraDependencyFiles" matching your script files to make the 
package rebuild on script changes.

Option 2: (recommended for multiple larger binaries)

use sub-packages and make your root package targetType: none to 
build all child packages, see 
https://dub.pm/package-format-json.html#sub-packages

root dub.sdl:
name "test"
targetType "none"
dependency ":a" version="*"
dependency ":b" version="*"
subPackage "a"
subPackage "b"

a/dub.sdl:
name "a"
targetType "executable"

b/dub.sdl:
name "b"
targetType "executable"

$ dub build

Result:
a/test_a.exe
b/test_b.exe

Note: this only works if your package is targetType none, use 
targetName and targetPath to customize how the exe is called and 
where it's placed


More information about the Digitalmars-d-learn mailing list