-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compare current bindings to automatic Swift/C++ interpo #53
Comments
I might suggest a few metrics for evaluation. There may be others, but I'll throw these ones out to start ~
|
In terms of maintainability we are restructuring our approach to pull from the official source, there are no generators we are using as Swift 5.9 provides this out of the box by enabling OpenTimelineIO is the next library I am working on to bring over, which will hopefully allow you guys to look over the steps we took and give an apt comparison to your existing Swift bindings.
There is a /// Specifies that a C++ `class` or `struct` is reference-counted using
/// the given `retain` and `release` functions. This annotation lets Swift import
/// such a type as reference counted type in Swift, taking advantage of Swift's
/// automatic reference counting.
///
/// This example shows how to use this macro to let Swift know that
/// a non-copyable reference counted C++ class can be imported as a reference counted type in Swift:
/// ```c++
/// class SWIFT_SHARED_REFERENCE(retainSharedObject, releaseSharedObject)
/// SharedObject : NonCopyable, IntrusiveReferenceCounted<SharedObject> {
/// public:
/// static SharedObject* create();
/// void doSomething();
/// };
///
/// void retainSharedObject(SharedObject *);
/// void releaseSharedObject(SharedObject *);
/// ```
///
/// Then, the Swift programmer would be able to use it in the following manner:
///
/// ```swift
/// let object = SharedObject.create()
/// object.doSomething()
/// // The Swift compiler will release object here.
/// ```
#define SWIFT_SHARED_REFERENCE(_retain, _release) \
__attribute__((swift_attr("import_reference"))) \
__attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(retain:_retain)))) \
__attribute__((swift_attr(_CXX_INTEROP_STRINGIFY(release:_release)))) Fortunately the addition of adding clang attributes to existing classes will be simply ignored in all other contexts outside of Swift, as to not introduce any portability issues with its existing implementation, some further documentation regarding This comes from a file called |
Thanks for the notes! |
@meshula quick update! The (initial out-of-the-box automatically generated) bindings are now available from here if you'd like to check them out: // swift-tools-version: 5.9
dependencies: [
.package(url: "https://github.com/wabiverse/MetaverseKit", from: "1.5.1")
]
...
.executableTarget(
name: "MyOTIOApp",
dependencies: [
.product(name: "OpenTimelineIO", package: "MetaverseKit"),
]
swiftSettings: [
.interoperabilityMode(.Cxx)
]
) It however did require moving the headers into |
@meshula @jminor quick update on this:
If you guys are doing something similar - be sure to keep it portable with the "vanilla swift toolchain" if you (or your users) are not using the Xcode toolchain with this addition. Though in hindsight, you can probably just do away with that include altogether since |
Swift/C++ interoperation support has come a long way since we last looked. We should re-evaluate and compare to the approach taken in this repo to see which strategy is best.
See also this proposal: AcademySoftwareFoundation/tac#578 including @furby-tm's slides which give an overview: Swift_Working_Group.pdf
The text was updated successfully, but these errors were encountered: