digitalmars.D.learn - DUB: Sometimes generates .di file and sometimes do not.
- BoQsc (31/31) Nov 05 2023 I would like to know how to solve this problem with `dub`.
- Imperatorn (2/33) Nov 05 2023 Try add quotes to the Hf param
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.
Nov 05 2023
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
Nov 05 2023
On Sunday, 5 November 2023 at 10:54:35 UTC, Imperatorn wrote:On Sunday, 5 November 2023 at 10:53:33 UTC, BoQsc wrote:Didn't help.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
Nov 05 2023
**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. * 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.[**excludedSourceFiles**](https://dub.pm/package-format-sdl#build-settings) 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**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" } ```
Nov 05 2023
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.](https://dlang.org/dmd-windows.html#switch-o-) Similarly [`buildOptions "syntaxOnly"`](https://dub.pm/package-format-sdl#build-options) 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" } ```
Nov 05 2023
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.
Nov 06 2023
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.
Nov 06 2023
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 ```
Nov 06 2023