core icon indicating copy to clipboard operation
core copied to clipboard

run.dlang.org: Compiler flags ignored after adding dependency

Open jmh530 opened this issue 4 years ago • 3 comments

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.

jmh530 avatar Apr 14 '20 19:04 jmh530

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

PetarKirov avatar Apr 25 '20 06:04 PetarKirov

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

jmh530 avatar Apr 30 '20 18:04 jmh530

@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.

jmh530 avatar Jun 13 '20 20:06 jmh530