Thread overview
DUB: Sometimes generates .di file and sometimes do not.
Nov 05
BoQsc
Nov 05
BoQsc
Nov 05
BoQsc
Nov 05
BoQsc
Nov 06
BoQsc
Nov 06
BoQsc
Nov 06
BoQsc
November 05

I would like to know how to solve this problem with dub.

dub.sdl

name "dheaders"
description "generates .di header file for a static library."
authors "public domain"
copyright "Public Domain. No rights reserved."
license "public domain"

configuration "staticLibrary" {
	dflags "-Hf=$PACKAGE_DIR/builds/library.di"
	targetName "library"
	targetType "library"
	targetPath "builds"
	sourceFiles "library.d"	
}

library.d

module library;

int func(int x)
{
    return x+1;
}

Command Line:

dub

Problem:
After running dub command: library.di file is rarely/inconsistenly generated inside builds directory.

November 05

On Sunday, 5 November 2023 at 10:53:33 UTC, BoQsc wrote:

>

I would like to know how to solve this problem with dub.

dub.sdl

name "dheaders"
description "generates .di header file for a static library."
authors "public domain"
copyright "Public Domain. No rights reserved."
license "public domain"

configuration "staticLibrary" {
	dflags "-Hf=$PACKAGE_DIR/builds/library.di"
	targetName "library"
	targetType "library"
	targetPath "builds"
	sourceFiles "library.d"	
}

library.d

module library;

int func(int x)
{
    return x+1;
}

Command Line:

dub

Problem:
After running dub command: library.di file is rarely/inconsistenly generated inside builds directory.

Try add quotes to the Hf param

November 05

On Sunday, 5 November 2023 at 10:54:35 UTC, Imperatorn wrote:

>

On Sunday, 5 November 2023 at 10:53:33 UTC, BoQsc wrote:

>

I would like to know how to solve this problem with dub.

dub.sdl

name "dheaders"
description "generates .di header file for a static library."
authors "public domain"
copyright "Public Domain. No rights reserved."
license "public domain"

configuration "staticLibrary" {
	dflags "-Hf=$PACKAGE_DIR/builds/library.di"
	targetName "library"
	targetType "library"
	targetPath "builds"
	sourceFiles "library.d"	
}

library.d

module library;

int func(int x)
{
    return x+1;
}

Command Line:

dub

Problem:
After running dub command: library.di file is rarely/inconsistenly generated inside builds directory.

Try add quotes to the Hf param

Didn't help.

November 05

Conclusive observation:
This can be resolved by informing dub of extraDependencyFiles to rebuild itself.
library.di non-existance simply does not trigger rebuild of the package and instead only library.lib is being copied from the cache folder into build folder. Leaving library.di not being generated.

if cache folder exists with a output file, it does not trigger build, only copies from the \cache's \build folder. If build is not triggered, .di file is not being generated.

Observations:

  • Happens with dub.json as well.

  • Mostly .di stops generating after the first output of dub.

  • Making any text changes to content of dub.sdl triggers dub to rebuild package and generate.di

  • Deleting the cache output file will trigger to rebuild the package and generate .di

    • C:\Users\Windows10\AppData\Local\dub\cache\dheaders\~master\build
    • After deleting library.lib inside latest cache folder build: The .di starts to generate.

Solution:

>

excludedSourceFiles Files that should be removed for the set of already added source files (takes precedence over "sourceFiles" and "sourcePaths") - Glob matching can be used to pattern match multiple files at once

Working example:

dub.sdl

name "dheaders"
description "generates .di header file for a static library."
authors "public domain"
copyright "Public Domain. No rights reserved."
license "public domain"

configuration "staticLibrary" {
	dflags "-Hf=$PACKAGE_DIR/builds/library.di"
	targetName "library"
	targetType "library"
	targetPath "builds"
	sourceFiles "library.d"	
	extraDependencyFiles "$PACKAGE_DIR/builds/library.di"
}
November 05

Configuration to generate only .di (D Header file)

name "dheaders"
description "generates .di header file for a static library."
authors "public domain"
copyright "Public Domain. No rights reserved."
license "public domain"

configuration "staticLibrary" {
	dflags "-Hf=$PACKAGE_DIR/builds/library.di"
	targetName "library"
	targetType "library"
	targetPath "builds"
	sourceFiles "library.d"	
	extraDependencyFiles "$PACKAGE_DIR/builds/library.di"
	dflags "-o-"
}

-o- Suppress generation of object file. Useful in conjuction with -D or -H flags.

Similarly buildOptions "syntaxOnly" can also be used in-place of dflag "-o-" they are correspondingly the same.

configuration "staticLibrary" {
	dflags "-Hf=$PACKAGE_DIR/builds/library.di"
	targetName "library"
	targetType "library"
	targetPath "builds"
	sourceFiles "library.d"	
	extraDependencyFiles "$PACKAGE_DIR/builds/library.di"
	buildOptions "syntaxOnly"
}
November 06

Update:

To allow only .di (D Header) output:

Instead of configuration, it would be more correct to make a new build type.

buildType "headerFileOnly" {
	extraDependencyFiles "$PACKAGE_DIR/builds/library.di"
	dflags "-Hf=$PACKAGE_DIR/builds/library.di"
	dflags "-o-"
	SourceFile "library.d"
}

Usage:

dub --build=headerFileOnly

This will produce only the .di D header file without .lib file.

November 06

In summary this is what it all combined could look like.

dub.sdl

name "dheaders"
description "generates .di header file for a static library."
authors "public domain"
copyright "Public Domain. No rights reserved."
license "public domain"

configuration "staticLibrary" {
	dflags "-Hf=$PACKAGE_DIR/builds/library.di"
	targetName "library"
	targetType "library"
	targetPath "builds"
	sourceFiles "library.d"	
	extraDependencyFiles "$PACKAGE_DIR/builds/library.di"
}

configuration "staticLibraryNoDIHeader" {
	targetName "library"
	targetType "library"
	targetPath "builds"
	sourceFiles "library.d"
}

buildType "headerFileOnly" {
	extraDependencyFiles "$PACKAGE_DIR/builds/library.di"
	dflags "-Hf=$PACKAGE_DIR/builds/library.di"
	dflags "-o-"
	sourceFiles "library.d"
}

library.d

module library;

int func(int x)
{
    return x+1;
}

Command Line:

dub --build=headerFileOnly
dub --config=staticLibraryNoDIHeader
dub --config=staticLibrary

First one creates only .di d header file
Second one creates only .lib static library file.
Third one creates both .lib and .di files.

November 06

To test the behaviour of static library.

program.d

module program;
import std.stdio;
import library;

void main(string[] args)
{
    writeln("func(3) = ", library.func(3));
}

Command Line:

dmd "./program.d" "./builds/library.di" "./builds/library.lib" -ofProgram.exe
Program.exe

Output:

func(3) = 4