www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dub sub-packages

reply "Alessandro" <a.bianciotto gmail.com> writes:
Hi everyone,
I've been learning D for a few months now and really liked it :) !
Currently I'm experimenting with client/server application
development using the ZeroMQ library D wrapper called "zmqd".
Although I could successfully build the basic hello_world
application with a custom written Makefile using dmd/rdmd, I've
tried to use the DUB package manager to achieve the same goal,
but I'm having some issues with it.
By following the DUB documentation at
http://code.dlang.org/package-format#build-options I created a
main dub project called "hello_world" (dub init hello_world) and
set up two sub-packages therein called "client" and "server" (dub
init client|server).
Then I configured the three dub.json files as follows:
hello_world/dub.json:
{
	"name": "hello_world",
	"description": "Hello World client/server application using ZMQ",
	"targetType": "none",
	"dependencies": {
          	"hello_world:client": "*",
          	"hello_world:server": "*"
	},
	"subPackages": [
          	"./client/",
	        "./server/"
      ]
}

hello_world/client/dub.json:
{
	"name": "client",
	"description": "Hello World client application using ZMQ",
          "targetType": "executable",
          "sourceFiles": ["source/hwclient.d"],
	"dependencies": {
          	"zmqd": "~>1.0.0-alpha"
	}
}

hello_world/server/dub.json -> same as above with "server"
substituting "client"

With this setting, from within "hello_world" directory, I can
build client and server individually with:

$ dub build hello_world:client
$ dub build hello_world:server

but when I simply try:

$ dub build

to build the whole thing at once, I get an error saying:

Error executing command build:
Main package must have a binary target type, not none. Cannot
build.

But if I change the "targetType" to "executable" or "autodetect"
in hello_world/dub.json I get the error:

Configuration 'application' of package hello_world contains no
source files. Please add {"targetType": "none"} to it's package
description to avoid building it.
Error executing command build:
Main package must have a binary target type, not none. Cannot
build.

What shall I do to have all sub-packages automatically built when
I build the main package? Is there a way to specify a small bash
script to have custom commands executed when giving the "dub run"
command?

Sorry for the long post :( !
May 06 2015
parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 6/05/2015 11:39 p.m., Alessandro wrote:
 Hi everyone,
 I've been learning D for a few months now and really liked it :) !
 Currently I'm experimenting with client/server application
 development using the ZeroMQ library D wrapper called "zmqd".
 Although I could successfully build the basic hello_world
 application with a custom written Makefile using dmd/rdmd, I've
 tried to use the DUB package manager to achieve the same goal,
 but I'm having some issues with it.
 By following the DUB documentation at
 http://code.dlang.org/package-format#build-options I created a
 main dub project called "hello_world" (dub init hello_world) and
 set up two sub-packages therein called "client" and "server" (dub
 init client|server).
 Then I configured the three dub.json files as follows:
 hello_world/dub.json:
 {
      "name": "hello_world",
      "description": "Hello World client/server application using ZMQ",
      "targetType": "none",
      "dependencies": {
               "hello_world:client": "*",
               "hello_world:server": "*"
      },
      "subPackages": [
               "./client/",
              "./server/"
       ]
 }

 hello_world/client/dub.json:
 {
      "name": "client",
      "description": "Hello World client application using ZMQ",
           "targetType": "executable",
           "sourceFiles": ["source/hwclient.d"],
      "dependencies": {
               "zmqd": "~>1.0.0-alpha"
      }
 }

 hello_world/server/dub.json -> same as above with "server"
 substituting "client"

 With this setting, from within "hello_world" directory, I can
 build client and server individually with:

 $ dub build hello_world:client
 $ dub build hello_world:server

 but when I simply try:

 $ dub build

 to build the whole thing at once, I get an error saying:

 Error executing command build:
 Main package must have a binary target type, not none. Cannot
 build.

 But if I change the "targetType" to "executable" or "autodetect"
 in hello_world/dub.json I get the error:

 Configuration 'application' of package hello_world contains no
 source files. Please add {"targetType": "none"} to it's package
 description to avoid building it.
 Error executing command build:
 Main package must have a binary target type, not none. Cannot
 build.

 What shall I do to have all sub-packages automatically built when
 I build the main package? Is there a way to specify a small bash
 script to have custom commands executed when giving the "dub run"
 command?

 Sorry for the long post :( !
$ dub build hello_world:client ; dub build hello_world:server Dub wasn't meant to build, more or less completely unrelated project targets at the same time.
May 06 2015
parent "Alessandro" <a.bianciotto gmail.com> writes:
On Wednesday, 6 May 2015 at 15:28:53 UTC, Rikki Cattermole wrote:
 On 6/05/2015 11:39 p.m., Alessandro wrote:
 Hi everyone,
 I've been learning D for a few months now and really liked it 
 :) !
 Currently I'm experimenting with client/server application
 development using the ZeroMQ library D wrapper called "zmqd".
 Although I could successfully build the basic hello_world
 application with a custom written Makefile using dmd/rdmd, I've
 tried to use the DUB package manager to achieve the same goal,
 but I'm having some issues with it.
 By following the DUB documentation at
 http://code.dlang.org/package-format#build-options I created a
 main dub project called "hello_world" (dub init hello_world) 
 and
 set up two sub-packages therein called "client" and "server" 
 (dub
 init client|server).
 Then I configured the three dub.json files as follows:
 hello_world/dub.json:
 {
     "name": "hello_world",
     "description": "Hello World client/server application 
 using ZMQ",
     "targetType": "none",
     "dependencies": {
              "hello_world:client": "*",
              "hello_world:server": "*"
     },
     "subPackages": [
              "./client/",
             "./server/"
      ]
 }

 hello_world/client/dub.json:
 {
     "name": "client",
     "description": "Hello World client application using ZMQ",
          "targetType": "executable",
          "sourceFiles": ["source/hwclient.d"],
     "dependencies": {
              "zmqd": "~>1.0.0-alpha"
     }
 }

 hello_world/server/dub.json -> same as above with "server"
 substituting "client"

 With this setting, from within "hello_world" directory, I can
 build client and server individually with:

 $ dub build hello_world:client
 $ dub build hello_world:server

 but when I simply try:

 $ dub build

 to build the whole thing at once, I get an error saying:

 Error executing command build:
 Main package must have a binary target type, not none. Cannot
 build.

 But if I change the "targetType" to "executable" or 
 "autodetect"
 in hello_world/dub.json I get the error:

 Configuration 'application' of package hello_world contains no
 source files. Please add {"targetType": "none"} to it's package
 description to avoid building it.
 Error executing command build:
 Main package must have a binary target type, not none. Cannot
 build.

 What shall I do to have all sub-packages automatically built 
 when
 I build the main package? Is there a way to specify a small 
 bash
 script to have custom commands executed when giving the "dub 
 run"
 command?

 Sorry for the long post :( !
$ dub build hello_world:client ; dub build hello_world:server Dub wasn't meant to build, more or less completely unrelated project targets at the same time.
Hi Rikki, Thank you for your answer. So it seems my DUB setup was a bit redundant. If I well understood, there is no point in having the root hello_world DUB package setup in the first place. I could just stay with the client and server sub-projects living in their own sub-directories and orchestrate the whole build in one go by means of a custom Makefile from the root directory. This would also allow me to launch the client/server application for testing in a custom-defined way (e.g. launching several clients and a single server in parallel).
May 08 2015