Open jmh530 opened 4 years ago
run.dlang.io is ignoring compiler flags when dependencies are included.
That's a known, although undocumented limitation. Without dependencies, our command-line invitation looks something like this:
$DC -g $args "${d_files[@]:1}" $with_run "${d_files[0]}" ${run_args}
($args
are the compiler options, while $run_args
are the command-line arguments to your program.)
On the other hand, when you have dependencies we use this:
dub -q --compiler=$DC --single --skip-registry=all onlineapp.d ${run_args}
You can check the entry point source code of our docker container here: https://github.com/dlang-tour/core-exec/blob/master/entrypoint.sh
In order to set compiler arguments using dub, you need to use dflags
build setting in the dub.sdl portion of your code: https://dub.pm/package-format-sdl.html#build-settings
I agree that it would be nice if setting the compiler flags in run.dlang.io
would set them automatically in dub.sdl
.
Pull request are welcome :P
The code below properly runs the unittest. However, it also gives a big warning from dub that it should be called with --build=unittest.
The more I've thought about it, the more it seems the solution isn't so easy.
The entrypoint.sh file depends on the dub.json comment so you'd need to update that, maybe whenever hitting run, with whatever $args there are.
Some other potential solutions: 1) Pass $args to dub when dub is used (annoying because if you add a dependency then the right $args to use will change, for instance you start with -unittest, add a dependency, now you have to change to --build=) 2) A button to force the use of dub and send any $args to dub. (kind of ugly) 3) Handle a few main dflags like -unittest by adjusting the dub calls manually (code becomes uglier) 4) Add the ability to include extra dflags in dub with a command line switch (I kind of like this). EDIT: Would probably still need to have a mapping for some things, like -unittest getting changed to --build=unittest, to avoid warnings from dub)
/+dub.sdl:
dependency "mir-algorithm" version="*"
dependency "mir-core" version="*"
dflags "-unittest"
+/
unittest {
import std.stdio: writeln;
writeln("here");
}
void main() {
}
EDIT: Some additional comments
@PetarKirov I have done some work here for getting dub test
to work if -unittest
is passed as an argument. However, I have no idea how to actually test this. I've never used docker before. I don't see anything wrong with it, but I still feel a bit nervous suggesting a PR I haven't actually tested.
This issue is combining together issues 734 747.
run.dlang.io is ignoring compiler flags when dependencies are included. Those two issues detail the issue with respect to -main and -unittest. I have also noticed the issue with --version, whereby the version information is produced when there are no dependencies and then it is not displayed when a dependency is added.