Thread overview
Static if on release build
Oct 20, 2017
Fra Mecca
Oct 20, 2017
bauss
Oct 20, 2017
rikki cattermole
Oct 20, 2017
b4s1l3
Oct 21, 2017
Guillaume Piolat
October 20, 2017
I can't find any documentation regarding conditional compilation in release and debug mode.

I have read the page regarding the topicon dlang.org but adding the snippet below makes no difference when compiling with dub -b release
{
version(full) {
 //do something
} else {
//do something else
}

How can I produce a release version with different parameters from debug using dub and static if's?
October 20, 2017
On Friday, 20 October 2017 at 02:36:37 UTC, Fra Mecca wrote:
> I can't find any documentation regarding conditional compilation in release and debug mode.
>
> I have read the page regarding the topicon dlang.org but adding the snippet below makes no difference when compiling with dub -b release
> {
> version(full) {
>  //do something
> } else {
> //do something else
> }
>
> How can I produce a release version with different parameters from debug using dub and static if's?

Take a look at this:
https://dlang.org/spec/version.html#DebugCondition
October 20, 2017
On 20/10/2017 3:36 AM, Fra Mecca wrote:
> I can't find any documentation regarding conditional compilation in release and debug mode.
> 
> I have read the page regarding the topicon dlang.org but adding the snippet below makes no difference when compiling with dub -b release
> {
> version(full) {
>   //do something
> } else {
> //do something else
> }
> 
> How can I produce a release version with different parameters from debug using dub and static if's?

Well yeah... full doesn't exist[0].

If debug is turned on:

debug {

} else {

}

That else isn't for 'release'. Release turns on optimizations in the compiler and disables a few other things like asserts.

If you want to specify a version at the command line use ``-version=MyVersion``. For a debug identifier use ``--debug=MyDebug`` and yes, debug conditions can have identifiers like versions require.

For dub you can specify it via ``versions`` and ``debugVersions``.

[0] https://dlang.org/spec/version.html
[1] http://code.dlang.org/package-format?lang=json
October 20, 2017
On Friday, 20 October 2017 at 02:36:37 UTC, Fra Mecca wrote:
> I can't find any documentation regarding conditional compilation in release and debug mode.
>
> I have read the page regarding the topicon dlang.org but adding the snippet below makes no difference when compiling with dub -b release
> {
> version(full) {
>  //do something
> } else {
> //do something else
> }
>
> How can I produce a release version with different parameters from debug using dub and static if's?

The most close compile condition is

version(assert)
{
    // build for testing
}
else
{
    // build for release
}

see https://dlang.org/spec/version.html#predefined-versions:

"assert	Checks are being emitted for AssertExpressions"

And at the same time

https://dlang.org/dmd-linux.html#switch-release

"compile release version, which means not emitting run-time checks for contracts and asserts. Array bounds checking is not done for system and trusted functions, and assertion failures are undefined behaviour."
October 21, 2017
On Friday, 20 October 2017 at 02:36:37 UTC, Fra Mecca wrote:
> I can't find any documentation regarding conditional compilation in release and debug mode.
>
> I have read the page regarding the topicon dlang.org but adding the snippet below makes no difference when compiling with dub -b release
> {
> version(full) {
>  //do something
> } else {
> //do something else
> }
>
> How can I produce a release version with different parameters from debug using dub and static if's?

Note thatwith D compilers -debug and -release are not opposed to each other. A program can have both flags, or none.