Can I wrap libuv with swift-nio?

Hi. As food for thought, I am interested in finding out if swift-nio can be used with libuv. Their architecture seems similar and compatible from a bird's eye view.

However, I am getting a bit lost at what custom parts need to be written and in which order. Any advices / guides?

What is the problem you want to solve?

Other than curiosity? Windows support (lite)

I think looking at NIO transport services should be helpful, it is a core that uses Network framework for use on Darwin platforms.

1 Like

@Helge_Hess1 's suggestion is a good one.

Yes, there is no particular reason you should not be able to use libuv to produce a backend for swift-nio.

I actually managed to wrap libuv event loop into NIO's event loop. You can track the progress here: GitHub - RussBaz/swift-libuv-transport-services: Cross-platform LibUV backed Transport Services for Swift-NIO .

However, when I tried running it on windows, nio immediately failed to compile:
.checkouts\swift-nio\Sources\NIOConcurrencyHelpers\lock.swift:229:37: error: value of type 'LockStorage<Void>' has no member 'mutex' self.mutex._storage.mutex,

It feels like a bug to me because there are clear windows specific conditionals in that source file. Can anyone from the NIO team try compiling it on windows again?

1 Like

Oh, wow. I managed to compile swift-nio on windows (mostly by dropping stuff that required Posix and by fixing some typos in windows related parts)

It even passes the remaining tests. (Lots of warnings while building, however)

I then managed to import it into my transport services project on windows and build them successfully together. Tests are built successfully too.

Unfortunately, my own tests refuseto run and I cannot figure out why... It shows that the build was a success and then drops this message (and nothing else):

error: abnormal(309): C:\Users\RussBaz\Documents\Projects\GitHub\swift-libuv-transport-services\.build\x86_64-unknown-windows-msvc\debug\swift-libuv-transport-servicesPackageTests.xctest --dump-tests-json output:
2 Likes

I'm not experienced enough with Windows errors to diagnose this, but @compnerd may have some insights here.

libuv uses a global lock and for very high IO/throughput loads it tends to struggle. This is a Julia talk recently about using libuv and its bottlenecks.

1 Like

I just wanted to let everyone interested know that I managed to wrap libuv in a swift wrapper and it runs on windows too. I decided to split it into a separate project from the nio transport services. My wrapper currently supports creating a custom executor and a tcp server. But it is rather straightforward to add any other missing features in the future. I still need to apply a few convenience patches because the windows build has some quirks.

4 Likes