Using core/sys/posix/mqueue.d on FreeBSD
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Sat Apr 6 11:28:59 UTC 2024
On Saturday, April 6, 2024 3:57:46 AM MDT Arjan via Digitalmars-d-learn wrote:
> I'm using posix mqueue in a D application on Linux. Works fine.
> But on FreeBSD it fails to compile due to the version statement:
>
> [version (CRuntime_Glibc):](
> https://github.com/dlang/dmd/blob/0cfdd7a589fd34fdf91db72e4999b4920efe5dc2/d
> runtime/src/core/sys/posix/mqueue.d#L31)
>
> While the file seems to be perfectly fine for FreeBSD too.
>
> If I comment that line out, the app builds but have to supply the
> linker the lib -ltr in dub.sdl to get it linking too:
>
> ```
> lflags "-lrt"
> ```
>
> Which I don't have to do on Linux.
>
> How to process from here to supply a PR?
> Supposedly that version statement is there for a reason. How do I
> also incorporate FreeBSD?
Everything in core.sys is supposed to be in version statements specific to
each OS (and Linux complicates that further by having different libcs,
resulting in even more version statements). The core.sys.posix files are
supposed to contain only stuff from standard POSIX, whereas core.sys.linux
contains Linux-specific stuff, core.sys.freebsd contains FreeBSD-specific
stuff, etc.
So, a file in core.sys.posix really shouldn't be doing
version (CRuntime_Glibc):
Rather, it should be
version (CRuntime_Glibc)
{
}
and the other POSIX OSes should have their own version statements in there
with declarations which match what they have (which isn't necessarily the
same as Glibc on Linux) - though only the standard POSIX declarations should
be in there. So, for instance, FreeBSD's standard POSIX declarations for
mqueue should go in
version (FreeBSD)
{
}
within that core.sys.posix.mqueue, but if it has stuff in mqueue.h which is
not standard POSIX, then it would need to go in core.sys.freebsd.mqueue
instead.
You can see this pattern with other files in core.sys, e.g.
https://github.com/dlang/dmd/blob/0cfdd7a589fd34fdf91db72e4999b4920efe5dc2/
druntime/src/core/sys/posix/time.d
vs
https://github.com/dlang/dmd/blob/0cfdd7a589fd34fdf91db72e4999b4920efe5dc2/
druntime/src/core/sys/freebsd/time.d
So, the correct thing to do with core.sys.posix.mqueue is to fix it so that
all of the existing declarations are in
version (CRuntime_Glibc)
{
}
and
version (CRuntime_Glibc):
is gone. Then
version (FreeBSD)
{
}
needs to be added with the standard POSIX declarations from FreeBSD. None of
the declarations should be shared across OSes.
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/mqueue.h.html
shows what's standard, but you'll have to get the actual C declarations from
/usr/include/mqueue.h
on FreeBSD and convert them to the appropriate declarations for D.
As for any linker commands, they may vary between OSes. All that druntime
provides for language bindings is the declarations. If a particular OS
requires any linker flags for any particular symbols, then you'll need to
take care of that with your build just like you would with C/C++.
But ultimately, which bindings druntime has is highly dependent on what
someone needed previously, since usually, they get put in there when someone
needs them rather than anyone trying to add them all. And in this case,
Sociomantic needed them for Linux, so they got them added, but either no one
else has needed the bindings, or no one else has needed them for anything
other than Linux with glibc - or if they did, they didn't get them into
druntime.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list