-
-
Notifications
You must be signed in to change notification settings - Fork 8
Description
It looks like this project might be a little stagnant but I thought I'd show some interest and write some words on generating rust bindings from swift.
The front end of this (or one of the crates in here) should be both a library and an executable similar to cbindgen or rust-bindgen.
Some notes:
cbindgenusessynto parse the rust source to generate some of the C bindings.rust-bindgenusesclang-systo get the AST of the C, C++ or Objective-C and then usessynas part of the rust generation phase.
To move forward with this, I think we should try to follow similar choices in design. To parse the swift and parse the AST, we should use the swift tooling.
swiftc has some functionality to spit out the AST for a given file as shown here. After a bit of messing around, it would seem that we'd want to parse the swiftinterface. At least, that's what seems to be the closes thing to a header file.
I managed to get:xcrun swiftc -frontend -emit-syntax -target x86_64-apple-ios13.2-simulator -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -Osize -module-name SwiftUI $(xcrun --show-sdk-path -sdk iphonesimulator)/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/x86_64.swiftinterface to produce a syntax tree. It doesn't like @objc syntax but I think there's a way to ignore that.
Anyway, the above spits out a lot of json. I'm not super into the idea of parsing that. We could look into getting some bindings to lib/Syntax using cmake-rs/bindgen or something.