dub icon indicating copy to clipboard operation
dub copied to clipboard

Build multiple executables (easier config)

Open wilzbach opened this issue 9 years ago • 4 comments

My problem is simple - I would like to build multiple scripts that use the same library with dub.

examples/script1
examples/script2
source/lib/...

(concrete example here)

Creating a new configuration entry for each executable fells a bit annoy - is there a solution to this on your roadmap?

wilzbach avatar Apr 18 '16 11:04 wilzbach

See #97 - this should definitely be implemented sooner rather than later, as it's quite frequently requested.

s-ludwig avatar Apr 18 '16 11:04 s-ludwig

The TSV command line tools I released may provide a useful example of the needs of a repository/package creating multiple executables. Repo: tsv-utils-dlang. I normally use make, but also have a dub build mode to make it simpler for D developers who want to download and build with dub. The dub support seems popular, but making this usage smooth took some effort. Some specifics:

  • Installation - dub fetch assumes installation into dub package directories and using dub run to execute. This is inconvenient for command line utilities, especially those commonly taking command line arguments or used in unix pipes. In addition, the dub package directories do not appear well suited for inclusion the user PATH. Using dub fetch --local would be more suitable, but this doesn't work at present (issue #1022). Whether dub should support an install command is a larger issue, but having a simple form of executable installation for folks building from source may be useful.
  • Recursing through sub-directories / sub-packages - The repo has a sub-directory for each tool. Building all the tools involves iterating over the sub-directories and performing a dub build. However, I couldn't find a way to create a dub package specification that would do this. I ended up creating a special 'dub_build.d' program at the top-level that does this in response to a dub run command. This works, but it's limited. For example, it would be useful to be able to use dub test at the top level and have it run against all sub-directories / sub-packages. That is, running arbitrary dub commands at top-level and having them run against all sub-packages would be useful.
  • Running arbitrary shell commands - The tools have both unit tests and tests run against the built executables. The tests against the executables use Unix shell commands. I was unable to find a way to run these tests as part of a dub test command, and I did not see a way to add a new command to dub that would provide a way to run these tests.

jondegenhardt avatar Jan 04 '17 06:01 jondegenhardt

With #1364 in, what is left for this issue is a command line switch that allows building all sub packages or possibly all root packages in sub directories, even if they are not a dependency of the base package. It could also come in the form of supporting wildcards for "dub build" (e.g. dub build --multi examples/*)

s-ludwig avatar Sep 12 '18 14:09 s-ludwig

Isn't there still any easy way to have single dub.json config for bunch of single file executables? Seems such PITA creating lots of config when all are exactly same... I think when dub sees multiple main in several files then just build them all using name of file.

davispuh avatar May 29 '21 17:05 davispuh