简体   繁体   中英

In a DUB config file, how do I change the configuration (buildOptions) of a dependency?

Suppose I have a project called "myapp" and it depends on "sdlang-d". I want to build my project as release-debug, using dub build --build=release-debug from the command line. Due to SDLang issue #54 , I can't have it build sdlang-d as release-debug, so I want to use my dub configuration file to force sdlang-d to build as "debug" or "debugMode" regardless of when build option I choose for "myapp", and then link the debug version of sdlang-d to the release version of myapp (so that my code outside of sdlang-d can benefit from optimization).

For testing purposes, I have created to github project called "dub_dependency_config" to simulate this situation. In the following text I will provide concrete output I've observed from things that I've tried, so I will refer to " dub_dependency_config " instead of "myapp".

I start with a simple dub.sdl config 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"

... and attempt to compile it with dub build --build=release-debug , and of course issue #54 does its thing:

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.

To work around this, I'd expect to be able to write something like this:

// 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"
}

I didn't expect this to actually work; nothing in the documentation said it should. I tried it anyways and dub seems to ignore the buildOptions tag within the dependency tag. The config file becomes equivalent to the one before and I get the same issue #54 compiler error.

I've read about subConfiguration , which seems to be the recommended way to solve this problem as mentioned in this thread . subConfiguration has given me plenty of failing configurations to experience. Let's go over a few:

// 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"

This one yields:

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

So it couldn't figure out what I meant, and as a consolation prize I get a nag message that I can't get rid of ;)

Onwards!

// 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"
}

Output:

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.

Well that's interesting, we get it to build... something (I have no idea what, but it's not my program).

More combinations! Let's recurse!

// 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"
    }
}

Output:

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

The nag went away! But I think that just means I failed harder.

In the interest of learning, I try something that I know won't work as I hope to get any squeak of information out of the subConfiguration tag:

// 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"

Nope, my wrong attempt had the wrong outcome:

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

How do I make it work?

(As an aside: I am very thankful for the .sdl format. I encountered this same problem in the .json version, and just the lack of commenting ability alone made this intractable to troubleshoot, let alone document.)

I think you need to reference the configurations available in the dependency itself. Dub doco isn't clear and I have made a similar mistake before. For sdlang-d it appears there are four configurations in that packages dub.sdl

  • cli
  • library
  • unittest-builtin
  • unittest

These are the options to choose from in the subConfiguration block. I don't think you can actually declare them in your packages dub.sdl like you are doing. In your first block of output it show that sdlang-d is building the library configuration.

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