dlang-community / mecca

Weka.IO's userland OS
Boost Software License 1.0
64 stars 16 forks source link

Cross-Platform support #9

Open jacob-carlborg opened 6 years ago

jacob-carlborg commented 6 years ago

I don't expect Weka to implement support for other platforms since they only use Linux 64bit. But would pull requests adding support for other platforms be accepted? I'm mostly thinking of Posix platforms like macOS and FreeBSD.

Shachar commented 6 years ago

Of course they would!

jacob-carlborg commented 6 years ago

I'm been thinking about how to organize the code. How about a structure like this:

platform
├── linux
│   ├── a.d
│   ├── b.d
│   └── inotify.d
└── macos
    ├── a.d
    └── b.d

All the platform specific code would live in platform. What's currently in the platform package is not the only place containing platform specific code. Limiting the platform specific code to one place would make it easier to port to new platforms.

Shachar commented 6 years ago

That's not what I had in mind, no.

First of all, I really want to keep all code outside of mecca.reactor independent on mecca.reactor. As such, having reactor aware code (such as inotify) under mecca.platform will simply not do.

My plan was to have something along the lines of mecca.platform.os and mecca.platform.cpu. Importing the former would, on my platform, import mecca.platform.os.linux and for you mecca.platform.os.maxos. With the later, it might be mecca.platform.cpu.x86_64 or mecca.platform.cpu.arm.

Under the reactor, we need mostly a poller, that knows how to schedule fibers based on file activity, and a notifier, that knows how follow file changes. Ideally (and I'm not sure it will be completely possible), there would be one unified interface, and implementations based on the various platforms' capabilities. Like I said, this might not be 100% possible, but I'd like to come as close as we can.

The above two are definitely not the only two. For example, signals handling are done via signalfd, which is, AFAIK, a Linux only interface. There I'm fairly certain that we can find a cross-platform solution that provides a unified interface. It might require to change the argument passed to the signal handler (it currently gets a signalfd_siginfo), but I'm fine with that.

I hope this gives you an idea on what I had in mind.

Shachar

jacob-carlborg commented 6 years ago

I haven’t looked at the reactor code yet, but you don’t think it’s possible to create a cross-platform API on top of inotify and the corresponding systems on the other platforms?

Shachar commented 6 years ago

On the contrary. I think it should be possible (though inotify have some semantics very different than the BSD counter-part).

What I think it impossible is to create an API for inotify, platform dependent or otherwise, that is divorced from the reactor. I do not want code under mecca.platform to depend on mecca.reactor.

So, pretty much, keep to that last rule, and the very least is we'll have a patch which will serve as basis for discussion. Feel free to create mecca.reactor.platform if so needed.

jacob-carlborg commented 6 years ago

Ok.

jacob-carlborg commented 5 years ago

Support for macOS has been implemented. In that process I also separated some platform specific code from the platform agnostic code, which will make it easier to add support for future platforms. Not sure if this issue still needs to be opened.