www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Using core/sys/posix/mqueue.d on FreeBSD

reply Arjan <arjan ask.me.to> writes:
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/druntime/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?
Apr 06
next sibling parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
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
Apr 06
prev sibling parent reply Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
Actually, since I'm usually the one who does the FreeBSD ones anyway, here
you go:

https://github.com/dlang/dmd/pull/16359

The declarations compile, and they should match the ones in C, since I
copied them over and then tweaked them, but I haven't actually tested them.

All that being said, even if they're merged immediately, they won't be
available as part of druntime until dmd 2.109.0 is released (and 2.108.0 was
released less than a week ago), so you'll probably need to copy them into
your own install or use the development version of dmd to get the updated
bindings if you want to use them now.

- Jonathan M Davis
Apr 06
parent Arjan <arjan ask.me.to> writes:
On Saturday, 6 April 2024 at 12:05:56 UTC, Jonathan M Davis wrote:
 Actually, since I'm usually the one who does the FreeBSD ones 
 anyway, here you go:

 https://github.com/dlang/dmd/pull/16359

 The declarations compile, and they should match the ones in C, 
 since I copied them over and then tweaked them, but I haven't 
 actually tested them.

 All that being said, even if they're merged immediately, they 
 won't be available as part of druntime until dmd 2.109.0 is 
 released (and 2.108.0 was released less than a week ago), so 
 you'll probably need to copy them into your own install or use 
 the development version of dmd to get the updated bindings if 
 you want to use them now.

 - Jonathan M Davis
This is awesome, Jonathan! Thanks a lot for your elaboration on the issue, no wonder I got confused, and of course the PR! Really appreciated. Thanks!
Apr 06