Can I specify a minimum version of Dub or DMD?

People keep trying to build my project with old versions of Dmd and Dub (0.9.2 instead of 1.0.0), and this will not work. Can I specify the minimum version of dub in the dub.json file?

+4
source share
1 answer

Sorry, you can’t. See this issue for more details . Please make a noise there; -)

Two ideas on how to get around this now.

1) Use static if in the main statement

int main()
{
   static if (__VERSION__ < 2069)
   {
       pragma(msg, "Your DMD version is outdated. Please update");
       return 1;
   }
   ...
}

2) Use preGenerateCommands = ['rdmd checkversions.d']

int main()
{
    import std.process : execute;
    import std.stdio : writeln;
    auto ver = execute(["dub", "--version"]);
    if (ver.status != 0)
    {
        writeln("Error: no dub installation found.");
    }
    else
    {
        import std.conv : to;
        import std.regex : ctRegex, matchFirst;
        auto ctr = ctRegex!`version ([0-9]+)[.]([0-9]+)[.]([0-9]+)`;
        auto r = ver.output.matchFirst(ctr);
        assert(r.length == 4, "version not found");
        int major = r[1].to!int, minor = r[2].to!int, patch = r[3].to!int;
        if (major < 2)
        {
            writeln(minor);
            return 1;
        }
    }
}
+3
source

Source: https://habr.com/ru/post/1649226/


All Articles