automerge / automerge-swift

Swift language bindings presenting Automerge
https://automerge.org/automerge-swift/documentation/automerge/
MIT License
243 stars 14 forks source link

Linux Support #201

Open samisuteria opened 6 days ago

samisuteria commented 6 days ago

Is there a way to run this package in server environments? I saw https://github.com/automerge/automerge-swift/blob/main/Sources/Automerge/_AutomergeLinux.swift#L8 after trying to run a grpc server in docker/linux instead of macOS.

heckj commented 5 days ago

Hey @samisuteria

I believe it's technically possible, but it's not a drop-in-and-work kind of thing. The complicating bit of this is the core library of Automerge is written in Rust, which we expose to Apple platforms through XCFramework. The XCFramework is a means of packaging a pre-compiled binary for the relevant platform - and XCFramework is an Apple platform specific thing, meaning there's no support for using binaries compiled for linux platforms.

There's two ways of tackling this - the first is to leverage the WASM compilation of this suite, along with the WASM compilation of Automerge, and run the whole bit within a WASM runtime, possible WASMKit or WASMER. This whole space isn't well fleshed out, but we have seen the whole kit working through WASM (primarily running in a browser) and have the WASM compilation support built in for that.

The other path would be to use this same code, but change the dependencies in Package.swift so that instead of referencing an XCFramework, you're loading and referencing a pre-compiled C library.

To my mind, the last would be the "easiest" route to get working - you'd need to compile the automerge core library as a binary library for the linux platform you're running on with Rust, put it into the system library path, and then update the dependencies to use it as a "C system library" from Swift. I'm not certain if there's a clean way to incorporate this setup without forking the repository though.

It's probably worth noting that you utilize Automerge on linux through Deno or NodeJS, which has really very good support, as this library is intentionally cross-platform and cross-language compatible (using the Rust language as a core). The majority of the folks I'm aware of using Automerge on Linux are doing so through that path, that's already been pretty well tread.

heckj commented 5 days ago

If this is something you'd be interested in helping to sort out - to run Automerge swift natively on Linux - I'd be happy to help work with you through it.