On Thursday, 10 January 2019 at 05:44:22 UTC, Russel Winder wrote:
It appears that libdvbv5 has undergone an (unnoticed by me till
just now) version change. This raises a general question for
creators of D bindings.
libdvbv5 has versions 1.12.x, 1.14.x, 1.16.x, etc, following
the "odd is internal, even is released" minor version number
strategy. It seems wrong somehow to follow that numbering for
the D binding; the binding needs to have a separate evolution.
However the binding has to allow the user to choose the
major.minor number of the underlying library they have – though
that should perhaps be done automatically using the pkg-config
system.
Has anyone had previous experience of this situation and can
give advice/direction so I don't have to build a solution from
first principles?
Use version conditions for the different library versions to set
up compile-time versions you can static if on:
```
enum DVBVSupport {
v112 = 112,
v114 = 114,
v116 = 116,
}
version(DVBV_114) {
enum dvbvSupport = DVBVSupport.v114;
}
else version(DVBV_116) {
enum dvbvSupport = DVBVSupport.v116;
}
else enum dvbvSupport = DVBVSupport.v114;
// Declarations supported in 1.12
...
static if(dvbvSupport >= DVBVSupport.v114) {
...
}
static if(dvbvSupport >= DVBVSupport.v116) {
...
}
```
This is how I handle it in the BindBC libraries, to which I'm
porting all the active bindings from the DerelictOrg group (where
I handled it with different git branches, which is a horribly
confusing and inefficient way to go about it):
https://github.com/BindBC
The only drawback to it right now is that static if isn't
supported inside enum declarations, so you'll wind up with
multiple declarations of the enum, as I did with SDL_EventType
here:
https://github.com/BindBC/bindbc-sdl/blob/master/source/bindbc/sdl/bind/sdlevents.d#L25
static if *is* supported in class & struct delcarations, though,
and you can see it used in that same file in some of the event
types, like SDL_MouseButtonEvent and SDL_MouseWheelEvent:
https://github.com/BindBC/bindbc-sdl/blob/master/source/bindbc/sdl/bind/sdlevents.d#L347