0

假设我有一个名为“myapp”的项目,它依赖于“sdlang-d”。我想使用dub build --build=release-debug命令行将我的项目构建为发布调试。由于SDLang 问题 #54,我无法将 sdlang-d 构建为 release-debug,因此我想使用我的 dub 配置文件强制 sdlang-d 构建为“debug”或“debugMode”,无论何时构建我为“myapp”选择的选项,然后将 sdlang-d 的调试版本链接到 myapp 的发布版本(以便我在 sdlang-d 之外的代码可以从优化中受益)。

出于测试目的,我在 github 上创建了一个名为“dub_dependency_config”的项目来模拟这种情况。在下面的文本中,我将提供从我尝试过的事情中观察到的具体输出,因此我将参考“ dub_dependency_config ”而不是“myapp”。

我从一个简单的 dub.sdl 配置文件开始...

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1"

...并尝试用 编译它dub build --build=release-debug,当然问题 #54 会做它的事情:

C:\dprojects\dub_dependency_config>dub build --build=release-debug
Performing "release-debug" build using dmd for x86_64.
libinputvisitor 1.2.2: target for configuration "library" is up to date.
taggedalgebraic 0.10.7: target for configuration "library" is up to date.
sdlang-d 0.10.1: building configuration "library"...
..\..\Users\cjoan\AppData\Roaming\dub\packages\sdlang-d-0.10.1\sdlang-d\src\sdlang\lexer.d(1273,41): Deprecation: function std.datetime.TimeZone.getTimeZone is deprecated - Use PosixTimeZone.getTimeZone or WindowsTimeZone.getTimeZone instead
..\..\Users\cjoan\AppData\Roaming\dub\packages\sdlang-d-0.10.1\sdlang-d\src\sdlang\ast.d(680,21): Error: null dereference in function _D6sdlang3ast3Tag16getTagAttributesMFAyaAyaZS6sdlang3ast3Tag146__T11MemberRangeTC6sdlang3ast9AttributeVAyaa13_616c6c41747472696275746573VAyaa17_617474726962757465496e646963696573VAyaa11_5f61747472696275746573Z11MemberRange
dmd failed with exit code 1.

为了解决这个问题,我希望能够写出这样的东西:

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1" {
    buildOptions "debugMode"
}

我没想到这会真正起作用。文档中没有任何内容说它应该。无论如何我都试过了,dub 似乎忽略了buildOptions标签中的dependency标签。配置文件与之前的配置文件相同,我得到相同的问题 #54 编译器错误。

我已阅读有关subConfiguration的信息,这似乎是解决此问题的推荐方法,如该线程中所述。 subConfiguration给了我很多失败的配置来体验。让我们来看看几个:

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1"
configuration "application" {
    targetType "executable"
    targetName "bin/app"
    mainSourceFile "source/app.d"
}
configuration "sdlang-hax" {
    buildOptions "debugMode"
}
subConfiguration "sdlang-d" "sdlang-hax"

这产生:

C:\dprojects\dub_dependency_config>dub build --build=release-debug

## Warning for package dub_dependency_config, configuration sdlang-hax ##

The following compiler flags have been specified in the package description
file. They are handled by DUB and direct use in packages is discouraged.
Alternatively, you can set the DFLAGS environment variable to pass custom flags
to the compiler, or use one of the suggestions below:

debugMode: Call DUB with --build=debug

Could not resolve configuration for package dub_dependency_config

所以它无法理解我的意思,作为安慰奖,我收到一条我无法摆脱的唠叨信息;)

向前!

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1"
configuration "application" {
    targetType "executable"
    targetName "bin/app"
    mainSourceFile "source/app.d"
    subConfiguration "sdlang-d" "sdlang-hax"
}
configuration "sdlang-hax" {
    buildOptions "debugMode"
}

输出:

C:\dprojects\dub_dependency_config>dub build --build=release-debug

## Warning for package dub_dependency_config, configuration sdlang-hax ##

The following compiler flags have been specified in the package description
file. They are handled by DUB and direct use in packages is discouraged.
Alternatively, you can set the DFLAGS environment variable to pass custom flags
to the compiler, or use one of the suggestions below:

debugMode: Call DUB with --build=debug

Performing "release-debug" build using dmd for x86_64.
dub_dependency_config ~master: target for configuration "sdlang-hax" is up to date.

C:\dprojects\dub_dependency_config>bin\app.exe
'bin\app.exe' is not recognized as an internal or external command,
operable program or batch file.

好吧,这很有趣,我们让它来构建……一些东西(我不知道是什么,但这不是我的程序)。

更多组合!让我们递归!

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1"
configuration "application" {
    targetType "executable"
    targetName "bin/app"
    mainSourceFile "source/app.d"
    subConfiguration "sdlang-d" "sdlang-hax"
    configuration "sdlang-hax" {
        buildOptions "debugMode"
    }
}

输出:

C:\dprojects\dub_dependency_config>dub build --build=release-debug
Could not resolve configuration for package dub_dependency_config

老马走了!但我认为这只是意味着我失败得更惨。

为了学习,我尝试了一些我知道不会起作用的方法,因为我希望从 subConfiguration 标记中获取任何信息:

// dub.sdl
name "dub_dependency_config"
description "Example of configuring dependencies in dub.sdl."
authors "chadjoan"
copyright "Copyright © 2017, cjoan"
license "BSL-1.0"
dependency "sdlang-d" version="~>0.10.1"
configuration "application" {
    targetType "executable"
    targetName "bin/app"
    mainSourceFile "source/app.d"
}
subConfiguration "sdlang-d" "application"

不,我的错误尝试产生了错误的结果:

C:\dprojects\dub_dependency_config>dub build --build=release-debug
Could not resolve configuration for package dub_dependency_config

我如何使它工作?

(顺便说一句:我非常感谢 .sdl 格式。我在 .json 版本中遇到了同样的问题,只是缺乏评论能力就很难解决,更不用说文档了。)

4

1 回答 1

0

我认为您需要参考依赖项本身中可用的配置。Dub doco 不清楚,我之前也犯过类似的错误。对于 sdlang-d,该软件包中似乎有四种配置dub.sdl

  • cli
  • 图书馆
  • 内置单元测试
  • 单元测试

这些是块中可供选择的选项subConfiguration。我认为您实际上不能像您正在做的那样在您的包 dub.sdl 中声明它们。在您的第一个输出块中,它显示 sdlang-d 正在构建library配置。

于 2017-08-22T00:15:38.537 回答