简体   繁体   English

我可以指定最小Dub或DMD版本吗?

[英]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. 人们一直试图用Dmd和Dub的旧版本(0.9.2代替1.0.0)来构建我的项目,但是它不起作用。 Can I specify in the dub.json file the min required dub version? 我可以在dub.json文件中指定所需的最低配音版本吗?

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 1)如果在主语句中使用static

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

2) Use preGenerateCommands = ['rdmd checkversions.d'] 2)使用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;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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