www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - using dub to compile plugins

reply Codifies <a b.com> writes:
I am currently using this dub.sdl

name        "runz80"
targetType  "executable"
lflags      "libz80/libz80.a"

however I will be creating a number of plugins, each plugin will 
consist of a single source file, I'd like the plugin source 
directory to be separate from main source directory and compile 
the plugins (.so) to a (binary) plugins directory

(the plugins will be dynamically loaded at runtime - I've 
previously done this in C so I don't anticipate any particular 
issues - famous last words!)

I could do this with a few simple rules in a Makefile, but I have 
no clue how to achieve this using dub.

can someone show me a concrete example of doing this ? Ideally 
just dropping a new source file into the plugins source folder 
should produce a new .so the next time dub is run, without having 
to explicitly add each plugin to the dub file...
Dec 19 2018
next sibling parent Codifies <a b.com> writes:
oh forgot to add just for extra pain.... while the main 
application won't need gtk, most of the plugins will...
Dec 19 2018
prev sibling next sibling parent reply Andre Pany <andre s-e-a-p.de> writes:
On Wednesday, 19 December 2018 at 12:57:14 UTC, Codifies wrote:
 I am currently using this dub.sdl

 name        "runz80"
 targetType  "executable"
 lflags      "libz80/libz80.a"

 however I will be creating a number of plugins, each plugin 
 will consist of a single source file, I'd like the plugin 
 source directory to be separate from main source directory and 
 compile the plugins (.so) to a (binary) plugins directory

 (the plugins will be dynamically loaded at runtime - I've 
 previously done this in C so I don't anticipate any particular 
 issues - famous last words!)

 I could do this with a few simple rules in a Makefile, but I 
 have no clue how to achieve this using dub.

 can someone show me a concrete example of doing this ? Ideally 
 just dropping a new source file into the plugins source folder 
 should produce a new .so the next time dub is run, without 
 having to explicitly add each plugin to the dub file...
You can use dub sub packages. Each plugin will be a dub package with its own dub descriptor (sdl) file. For your main dub sdl you set targetType to None. Kind regards Andre
Dec 19 2018
parent reply Codifies <a b.com> writes:
On Wednesday, 19 December 2018 at 13:14:20 UTC, Andre Pany wrote:
 On Wednesday, 19 December 2018 at 12:57:14 UTC, Codifies wrote:
 [...]
You can use dub sub packages. Each plugin will be a dub package with its own dub descriptor (sdl) file. For your main dub sdl you set targetType to None. Kind regards Andre
how could I have multiple dub files in the same directory for each plugin ???
Dec 19 2018
parent reply Andre Pany <andre s-e-a-p.de> writes:
On Wednesday, 19 December 2018 at 14:08:10 UTC, Codifies wrote:
 On Wednesday, 19 December 2018 at 13:14:20 UTC, Andre Pany 
 wrote:
 On Wednesday, 19 December 2018 at 12:57:14 UTC, Codifies wrote:
 [...]
You can use dub sub packages. Each plugin will be a dub package with its own dub descriptor (sdl) file. For your main dub sdl you set targetType to None. Kind regards Andre
how could I have multiple dub files in the same directory for each plugin ???
You have sub folders in which you create the dub.sdl files. In your main dub.sdl you include these folders as sub packages. Regarding the automatic logic you ideally want to have: there is the plan to add dub extension plugins. Unfortunately a hero is needed to implement it. Kind regards Andre
Dec 19 2018
parent Codifies <a b.com> writes:
On Wednesday, 19 December 2018 at 16:31:57 UTC, Andre Pany wrote:
 On Wednesday, 19 December 2018 at 14:08:10 UTC, Codifies wrote:
 On Wednesday, 19 December 2018 at 13:14:20 UTC, Andre Pany 
 wrote:
 On Wednesday, 19 December 2018 at 12:57:14 UTC, Codifies 
 wrote:
 [...]
You can use dub sub packages. Each plugin will be a dub package with its own dub descriptor (sdl) file. For your main dub sdl you set targetType to None. Kind regards Andre
how could I have multiple dub files in the same directory for each plugin ???
You have sub folders in which you create the dub.sdl files. In your main dub.sdl you include these folders as sub packages. Regarding the automatic logic you ideally want to have: there is the plan to add dub extension plugins. Unfortunately a hero is needed to implement it. Kind regards Andre
I was planning to have all the plugin sources in one directory otherwise I'd have loads of folders all over the place... I think Make is the way forward!
Dec 19 2018
prev sibling next sibling parent Neia Neutuladh <neia ikeran.org> writes:
On Wed, 19 Dec 2018 12:57:14 +0000, Codifies wrote:
 I could do this with a few simple rules in a Makefile, but I have no
 clue how to achieve this using dub.
If you need dub, you can create a wrapper script that generates the dub file for the plugins directory. Make is a lot better for this kind of thing.
Dec 19 2018
prev sibling parent reply Atila Neves <atila.neves gmail.com> writes:
On Wednesday, 19 December 2018 at 12:57:14 UTC, Codifies wrote:
 I am currently using this dub.sdl

 name        "runz80"
 targetType  "executable"
 lflags      "libz80/libz80.a"

 however I will be creating a number of plugins, each plugin 
 will consist of a single source file, I'd like the plugin 
 source directory to be separate from main source directory and 
 compile the plugins (.so) to a (binary) plugins directory

 (the plugins will be dynamically loaded at runtime - I've 
 previously done this in C so I don't anticipate any particular 
 issues - famous last words!)

 I could do this with a few simple rules in a Makefile, but I 
 have no clue how to achieve this using dub.

 can someone show me a concrete example of doing this ? Ideally 
 just dropping a new source file into the plugins source folder 
 should produce a new .so the next time dub is run, without 
 having to explicitly add each plugin to the dub file...
Unless the plugins have dub dependencies, don't use dub for it. Plugins that do can have their own dub.sdl/json with targetType "dynamicLibrary".
 Ideally just dropping a new source file into the plugins source 
 folder should produce a new .so the next time dub is run, 
 without having to explicitly add each plugin to the dub file...
I don't see how you can do this with dub, and I wouldn't attempt it either. Just use make, and have make call dub for the main project (and potentially any plugins that need it). Remember to make the dub targets `.PHONY` since you don't want to be managing the D dependencies by hand.
Dec 21 2018
parent Neia Neutuladh <neia ikeran.org> writes:
On Fri, 21 Dec 2018 10:56:39 +0000, Atila Neves wrote:
 I don't see how you can do this with dub, and I wouldn't attempt it
 either. Just use make, and have make call dub for the main project (and
 potentially any plugins that need it). Remember to make the dub targets
 `.PHONY` since you don't want to be managing the D dependencies by hand.
Or you could have it depend on dub.sdl, dub.selections.json, your D source files, and your string import files. Which is a bit more work but will result in a little less recompilation.
Dec 21 2018