Specify dmd or ldc compiler and version in a json dub file?

Moritz Maxeiner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 8 02:51:40 PDT 2017


On Tuesday, 8 August 2017 at 09:31:49 UTC, data pulverizer wrote:
> On Tuesday, 8 August 2017 at 09:21:54 UTC, Moritz Maxeiner 
> wrote:
>> On Tuesday, 8 August 2017 at 09:17:02 UTC, data pulverizer 
>> wrote:
>>> Hi,
>>>
>>> I would like to know how to specify dmd or ldc compiler and 
>>> version in a json dub file.
>>>
>>> Thanks in advance.
>>
>> You can't [1]. You can specify the compiler to use only on the 
>> dub command line via `--compiler=`.
>>
>> [1] https://code.dlang.org/package-format?lang=json
>
> How do you distribute packages with specific compiler 
> dependencies? I guess I could write it in the readme.

If your code depends on capabilities of a specific D compiler, I 
wouldn't depend on build tools for that, I'd make it clear in the 
source code via conditional compilation [1]:

---
version (DigitalMars)
{
}
else version (LDC)
{
}
else
{
     static assert (0, "Unsupported D compiler");
}
---

There's no equivalent for the frontend version, though AFAIK.

If it's not your code that needs something compiler specific, but 
you just want to control which is used, don't use dub as a build 
tool, use another (cmake, meson, write your own compilation 
"script" in D), and set it's invocation as a prebuildcommand in 
the dub package file (make sure dub's source file list is empty).

[1] http://dlang.org/spec/version.html#predefined-versions


More information about the Digitalmars-d-learn mailing list