www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dub for lib & app?

reply mark <mark qtrac.eu> writes:
Is it possible to create a dub project that has one library and 
one or more executables (that use the library)? If so, could 
someone point me to the docs for this since I couldn't find this 
in the dub docs?

Aside: I'm learning D to give me something approaching the 
convenience of Python with the fast executable that I'd get with 
Rust. I love Rust's cargo tool, but find that Rust is very 
frustrating to do prototyping or experimentation whereas D seems 
easy for these purposes. But dub does seem a bit basic (or maybe 
I just haven't found the right docs).
Feb 04 2020
parent reply Andre Pany <andre s-e-a-p.de> writes:
On Tuesday, 4 February 2020 at 09:13:48 UTC, mark wrote:
 Is it possible to create a dub project that has one library and 
 one or more executables (that use the library)? If so, could 
 someone point me to the docs for this since I couldn't find 
 this in the dub docs?

 Aside: I'm learning D to give me something approaching the 
 convenience of Python with the fast executable that I'd get 
 with Rust. I love Rust's cargo tool, but find that Rust is very 
 frustrating to do prototyping or experimentation whereas D 
 seems easy for these purposes. But dub does seem a bit basic 
 (or maybe I just haven't found the right docs).
Yes, using sub packages. Set the targetType of the root package to None and introduce 2 sub packages of targetType Executable and Library. Kind regards Andre
Feb 04 2020
parent reply mark <mark qtrac.eu> writes:
On Tuesday, 4 February 2020 at 09:21:17 UTC, Andre Pany wrote:
 On Tuesday, 4 February 2020 at 09:13:48 UTC, mark wrote:
 Is it possible to create a dub project that has one library 
 and one or more executables (that use the library)? If so, 
 could someone point me to the docs for this since I couldn't 
 find this in the dub docs?
[snip]
 Yes, using sub packages. Set the targetType of the root package 
 to None and introduce 2 sub packages of targetType Executable 
 and Library.
Ah, thank you. And if I'm doing *separate* individual projects, for an app, dub creates source/app.d (which I rename src/app.d). But what should it be for a library? Should it be src/package.d along with any supporting src/one.d src/two.do etc? And is this documented anywhere? (I thought I'd seen dub used with a --template argument, but can't find it; so maybe I'm mixing it up with something else?)
Feb 04 2020
parent Paul Backus <snarwin gmail.com> writes:
On Tuesday, 4 February 2020 at 19:21:07 UTC, mark wrote:
 Ah, thank you.

 And if I'm doing *separate* individual projects, for an app, 
 dub creates source/app.d (which I rename src/app.d).

 But what should it be for a library? Should it be src/package.d 
 along with any supporting src/one.d src/two.do etc?
For a library, you can name the source files anything you want. If you put your code in `src/mylib.d`, for example, users of your library can import it with `import mylib`.
Feb 04 2020