digitalmars.D.learn - Use dub to create source lib and executables
- Chris Piker (36/36) Mar 04 2023 Hi D
- Steven Schveighoffer (11/57) Mar 04 2023 If you mean that you have multiple subprojects inside your main dub
- Chris Piker (14/18) Mar 04 2023 I have been trying to do that for hours, and all I get is cryptic
- Richard (Rikki) Andrew Cattermole (6/6) Mar 04 2023 Yes dub was setup to cover the most common cases, but ignores when you
- Chris Piker (9/17) Mar 04 2023 It's interesting to hear that multiple outputs are rare for other
Hi D I normally work in a *nix environment, typically on server-side code. For many projects I have gnu makefiles that build a small lib along with command line utilities. Up to now I've been creating a dub.json file for just the sourceLibrary, and then putting embedded dub comments at the top of each of the utility programs. The utilities are built via `dub build --single` and a thin makefile triggers all the dub commands. This method is inefficient, and it won't work in a typical Windows dev environment, so today I'm trying to remove gnu make from the picture. Going back to basics, does anyone know of a clear example of how to convert this simplified makefile into 1-N dub files?: ```makefile outdir/%:utils/%.d outdir/mylib.a dmd -I libsrc -od=outdir -of=$ $^ build:outdir/mylib.a outdir/prog1 outdir/prog2 | outdir outdir: if [ ! -e outdir ]; then mkdir outdir; fi outdir/mylib.a:libsrc/mod1.d libsrc/mod2.d dmd -lib -od=outdir -of=$ $^ ``` This is a paired down example since `make test` and `make install` aren't present, but I hope the main ideas are apparent. I've been at it now for about four hours, with lots of web-searches (btw, thanks to schveiguy for getting me this far) but I haven't figured out what hierarchy of dub constructs I need to create to order to get the effect of the small make file above. Thanks for considering the question,
Mar 04 2023
On 3/4/23 1:33 PM, Chris Piker wrote:Hi D I normally work in a *nix environment, typically on server-side code. For many projects I have gnu makefiles that build a small lib along with command line utilities. Up to now I've been creating a dub.json file for just the sourceLibrary, and then putting embedded dub comments at the top of each of the utility programs. The utilities are built via `dub build --single` and a thin makefile triggers all the dub commands. This method is inefficient, and it won't work in a typical Windows dev environment, so today I'm trying to remove gnu make from the picture. Going back to basics, does anyone know of a clear example of how to convert this simplified makefile into 1-N dub files?: ```makefile outdir/%:utils/%.d outdir/mylib.a dmd -I libsrc -od=outdir -of=$ $^ build:outdir/mylib.a outdir/prog1 outdir/prog2 | outdir outdir: if [ ! -e outdir ]; then mkdir outdir; fi outdir/mylib.a:libsrc/mod1.d libsrc/mod2.d dmd -lib -od=outdir -of=$ $^ ``` This is a paired down example since `make test` and `make install` aren't present, but I hope the main ideas are apparent. I've been at it now for about four hours, with lots of web-searches (btw, thanks to schveiguy for getting me this far) but I haven't figured out what hierarchy of dub constructs I need to create to order to get the effect of the small make file above. Thanks for considering the question,If you mean that you have multiple subprojects inside your main dub project, my advice is to follow what other such projects do. I always look at vibe for my example. dub isn't great when it comes to the "one true way" to specify this. You can actually create a dub subproject inside your dub file, or create dub files inside all your other subproject folders, and tag them as subprojects of the main project. I've tried both ways, and I find the latter to be easier to deal with. This is what vibe does. -Steve
Mar 04 2023
On Saturday, 4 March 2023 at 20:23:29 UTC, Steven Schveighoffer wrote:On 3/4/23 1:33 PM, Chris Piker wrote: If you mean that you have multiple subprojects inside your main dub project, my advice is to follow what other such projects do. I always look at vibe for my example.I have been trying to do that for hours, and all I get is cryptic error messages from dub. I've tried all in one top level dub.json, I've tried three dub.json files, one at the top level and one for each of lib and utilities. The fact that dub considers the output of a project to only be a single lib, exc, etc. is quite restrictive and it means we have to have a target of "none" and then subprojects, which is cumbersome at best. Maybe it's just the frustration talking, but it seems wrong that a build rule that is so trivial to construct using 1980s makefiles is so hard today. If I wasn't trying to blend in I would have just given up a long time ago. But thanks for mentioning vibe.d as an example I'll take a look.
Mar 04 2023
Yes dub was setup to cover the most common cases, but ignores when you have multiple outputs. Not ideal. There is a PR to add build steps currently, which will help improve things, so there is work to make dub better at these less common use cases. The simplest solution is to do one package per binary, then use a shell script to trigger them in succession, not great but a workable solution.
Mar 04 2023
On Saturday, 4 March 2023 at 21:31:09 UTC, Richard (Rikki) Andrew Cattermole wrote:Yes dub was setup to cover the most common cases, but ignores when you have multiple outputs. Not ideal. There is a PR to add build steps currently, which will help improve things, so there is work to make dub better at these less common use cases. The simplest solution is to do one package per binary, then use a shell script to trigger them in succession, not great but a workable solution.It's interesting to hear that multiple outputs are rare for other developers. So I was hoping to do away with shell scripts (or make) since dub is common on all systems, but alas it's not worth the effort, so I won't continue to try and make `"targetType":"none"` work. By the way, do you know if there will be a dub "build-all" type command in the future?
Mar 04 2023