Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jmh530 opened this issue Apr 14, 2020 · 3 comments
Open

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

jmh530 opened this issue Apr 14, 2020 · 3 comments

Comments

@jmh530
Copy link

jmh530 commented Apr 14, 2020

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 jmh530 changed the title Compiler flags ignored after adding dependency run.dlang.org: Compiler flags ignored after adding dependency Apr 14, 2020
@PetarKirov
Copy link
Member

PetarKirov commented Apr 25, 2020

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

@jmh530
Copy link
Author

jmh530 commented Apr 30, 2020

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
Copy link
Author

jmh530 commented Jun 13, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants