On Tuesday, 20 April 2021 at 18:11:18 UTC, Andre Pany wrote:
On Tuesday, 20 April 2021 at 17:15:15 UTC, JG wrote:
Hi
I want to put some code together in a local library that is
then used by several other projects. I am running into a few
problems. Firstly when I try and configure the code to be a
library (dub init, add d files to source, and remove
source/app.d - perhaps this wrong) dub test no longer seems to
work?
Secondly I am having problems getting dub to add the library
code to other projects. It seems to work if I run dub
add-local path/to/library and then add the appropriate
dependencies to the projects dub.json file. However, I didn't
manage to find documentation that explains exactly how this
should work. Also there seems to be some mention getting this
to work with versions (in the documentation about dub
add-path), which I couldn't follow.
Does anyone know in more detail how this works or how I can
find out?
You need to add 2 configurations. The first configuration is
used automatically when you execute `dub build`. Just name the
config `debug` with targetType `library`. Add a second
configuration with name `unittest` and targetType `executable`
and attribute `mainSourceFile` pointing to a module containing
your main function for your test. For example name this module
`testapp.d`.
The module `testapp.d` you need to exclude in your
configuration `debug` using attribute `excludeSourceFiles`.
The configuration `unittest` is automatically used when you
execute `dub test`.
Kind regards
Andre
Thank you very much. In case someone wants more specific
instructions:
(a) add a file source/test.d containing:
void main(){}
(b) add configurations to dub.json:
"configurations": [
{ "name": "debug",
"excludedSourceFiles": ["source/test.d"],
"targetType": "library"},
{ "name": "unittest",
"mainSourceFile": "source/test.d",
"targetType": "executable"}]
This still leaves open the question of how to include a version
of such a library in another project via dub.