Dynamically Linking Rust Crates to Rust Crates

I’ve been thinking about a rust swift abi bridge after reading their abi proposal. I would love to work on it, I think it would be massively cool (imagine writing the brand new swift ui in rust :slight_smile: ), but I don’t see myself having time in the near future so I’m hoping some adventurous soul will take up the mantle!

So my first thought, to be honest I think a lot of it could be implemented with a procedural macro, eg #[derive(Swift)]

I implemented a basically seamless ffi between OCaml and rust here using regular macros! https://github.com/m4b/raml

Someone started implementing a coq <-> rust proc macro too; and these are in some sense more complicated than Swift’s abi because you need to interact with the gc, link against (and use) static symbols out of the runtime, etc.

The ABI of swift afaics is programmatic; you provide witness tables and bla bla for various generics implementations, which should all be codegennable. Once the abi qua api is understood I think many parts will just fall out.

Probably the only hard part will be the calling convention if it changed, but that should also technically be implementable if necessary via a proxy assembly stub to forward arguments correctly.

I’m sure I’m glossing over important details (the devil is always in the details) but I didn’t see anything particular difficult from a programmatic point of view; at the end of the day there are just calling conventions struct layouts and runtime apis that manage the bridge. We just need some people with some time and I can see a really beautiful and seamless swift abi bridge quite naturally forming

2 Likes