gtkd-developers / GlibD

D bindings for the GLib C Utility Library.
Other
5 stars 3 forks source link

Using as dub dependency is quite painful #6

Open andre2007 opened 4 years ago

andre2007 commented 4 years ago

I have an application which uses GlibD as dependency (as I have created a binding for Parquet).

Every time I compile now my application, it looks like this:

dub build
Running pre-generate commands for glibd...
Please note that you need to use `dub run <pkgname>` or add it to dependencies of your package to actually use/run it. dub does not do actual installation of packages outside of its own ecosystem.
Building package girtod in /home/user/.dub/packages/girtod-0.20.0/girtod/
Running pre-generate commands for girtod...
Performing "$DFLAGS" build using /usr/bin/dmd for x86_64.
girtod 0.20.0: building configuration "application"...
Linking...
Running ../../girtod-0.20.0/girtod/girtod -i src -o generated --use-runtime-linker
copying file [src/gtkd] to [generated/gtkd]
Performing "debug" build using /usr/bin/dmd for x86_64.
glibd 2.1.0: building configuration "library"...
parquet-d ~master: building configuration "application"...
Linking...

Even if I do not change anything in my application, girtod is build and executed for glibd every time. This makes the usage of GlibD almost unusable. I wonder whether this could be improved?

andre2007 commented 4 years ago

There is following behavior:

If you change to preBuildCommands, there will be another error message like "No source files found". You can solve this by adding the "src" folder here: https://github.com/gtkd-developers/GlibD/blob/1f2f06aecc97547bcede0d1511c1f2dd18896452/dub.json#L5

MikeWey commented 4 years ago

AFAIK, for things to work the first time you build GlibD the command to generate the source needs to be in the pregeneratecommands otherwise dub won't build the generated source. On a second run it picks up the already generated (old) source code and it will usually compile successfully.

I don't have time to test it now, but judging from the dub documentation, pregeneratecommands is only executed once, and prebuildcommands is executed on every build, so this might be a dub issue.

The src directory doesn't contain any code that should be compiled, so it shouldn't be part of the sourcepaths.

andre2007 commented 4 years ago

I also asked this question in dub dlang slack, as I am not an expert here. I will post the answer here... The documentation might be too short and misleading.

But what I can see from the Dub source code, preGenerateCommands works straight forward. https://github.com/dlang/dub/blob/master/source/dub/generators/generator.d#L102

While the whole project is generated, preGenerateCommands will be executed for each dependency of the whole project, independent whether it is already built or not. As the preGenerateCommands touching D modules (girtod), this will be detected by dub as code change and will cause rebuild of glibd

andre2007 commented 4 years ago

@MikeWey I created a pull request to align the dub documentation with the actual implementation https://github.com/dlang/dub-docs/pull/23

MikeWey commented 4 years ago

Thanks, i will look at it when i'm back home, next week.

MikeWey commented 4 years ago

When working with a clean git checkout, and doing the generation in the preBuildCommands and adding src as a source directory (even tough it doesn't contain any source to compile). Running dub build will fail with a message about missing source files.

The dub example about generating source files also uses preGenerateCommands. Only it seem to broken currently due to dub bug dlang/dub#1474