On Friday, 16 July 2021 at 16:44:31 UTC, Scotpip wrote:
Again, if this helps anyone my current setup is to have a
single main() in app.d. I changed the main() in my sandboxes to
runSandbox(), and I import and run from app.d rather than
directly. Or with a couple of keystrokes I can switch to
running the full app. This seems to be a practical workflow
that plays properly with the build system.
If anyone has a better suggestion, I'd appreciate your tips.
You might look into dub configurations. The first configuration
that matches the current platform is the default, and other can
be specified on the command line with `dub -cConfigName` (or
`--config=ConfigName`).
Here's are two configurations in SDLang format from one of my
projects:
// Default library config.
configuration "dolce" {
targetType "staticLibrary"
targetPath "lib"
targetName "dolce"
excludedSourceFiles "source/dolce/dev/*"
}
// Development config for testing/experimenting.
configuration "dolceDev" {
targetType "executable"
targetPath "bin"
targetName "dolceDev"
}
Files for the executable are in `source/dolce/dev`, so I just
exclude them from the library builds. In your case, you might
have two mains and do something like this:
targetType "executable"
configuration "default" {
excludedSourceFiles "source/sandbox/*"
}
configuration "sandbox" {
exludedSourceFiles "source/app.d"
}
Or maybe the sandbox config could just add a version:
configuration "sandbox" {
versions "Sandbox"
}
Then you can conditionally compile as needed:
void main()
{
version(Sandbox) {
import sandbox : runSandbox;
runSandbox();
} else {
// Normal main stuff here
}
}