On Fri, 11 Sep 2015 18:07:38 GMT, Sönke Ludwig wrote:

On Wed, 09 Sep 2015 18:15:39 GMT, Márcio Martins wrote:

Is there a way to release an app in source code form to code.dlang.org and also allow it to be used as a library?
The app I want to release comes with a tiny supporting stub library that is optional and provided as reference.

I would like users to install the package with dub, and use it normally, but then also just import the support library without any major issues.

The problem I'm facing is that when used as a library, dub tries to compile every file in the package,
which already contain a main() which will then conflict with the user's code.

Is this even good practice? Would it be better to release as 2 separate packages?

I'm doing a similar thing for many packages, whenever it feels natural to do so, for example the "dub" package itself is usable both ways. If main() is within source/app.d or source/main.d, DUB will automatically create a "library" configuration that excludes that file. If that is not the case, you have to create the configurations manually:

  "configurations": [
      "name": "application",
      "targetType": "executable",
      "mainSourceFile": "source/main.d",
      "sourceFiles": [...]
      "name": "library",
      "targetType": "library",
      "sourceFiles": [...]

Then, when doing "dub build" or similar on the package itself, it will choose the first (i.e. "application") configuration by default, while when used as a dependency it will default to the first configuration that has a library target type.

An alternative would be to use a sub package. But I'd only do that if for example the library part doesn't really contain the core part of the application.

The library part is useful as standalone but it is also part of the application. I used subpackages and it works quite well, but I don't like the extra bit of complexity for the user. I will give your suggestion a try! Thanks!