简体   繁体   中英

Can I specify a min Dub or DMD version?

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

Unfortunately you can't. See this issue for more details. Please make noise there ;-)

Two ideas how to workaround around this for 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;
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM