-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add some examples/documentation for standard use cases (e..g, getting an ObjC struct into rust) #582
Comments
I think I will need to revise this question - turns out this is probbaly related with how Objective C handled SIMD types. I will close this one (tho I think this librry still lacks examples) and open a new one. |
Well, it does say in the docs for
And But I definitely recognize that this is not visible, and there should be some more introductory-level docs for this! |
I think I was a bit tired and frustrated when writing this, my aplogies for that. I actually tried implementing Now using some ObjectiveC glue code (basically reading all elements out and creating an array from that on the Objective C side) it works. But maybe worth keeping in mind when support for |
No problem, it didn't register as rude to me.
Huh, yeah, I see what you mean, This may actually a problem ABI-wise, because we use the encoding as part of figuring out the correct calling convention; but then again, a type like I'll reopen this until I've investigated things a bit more, this is an issue that should be fixed. |
Just to add some context, using |
From my reading of Clang's source code, the ABI expects us to use
Though the code is quite involved, and I glossed over a lot of the details. But it does seem like vector types at the very least need some sort of different handling to have the correct message-sending ABI. I don't know how vector types relate to SIMD, but they sound similar, so maybe SIMD types do also use a different ABI? |
Yep, that's what I saw as well. I'm on |
objc2/crates/objc2/src/runtime/message_receiver.rs Lines 53 to 154 in 155edc1
But I think this logic is subtly wrong for vector types, and that's what I want to fix. All of this is only tangentially related to your problem of not being able to implement |
But I tried with the |
I actually suspect the code example you provided might technically be wrong too on Aarch64, as the ABI of SIMD types isn't the same as the ABI of a C struct - it happens to work since you use the large In general, I'm unsure of the state of SIMD FFI support? There's |
Re examples: There are some in |
I think the examples are quite good already, but as some point it might be worth to add a short user guide / getting started page and then link to the examples. |
I've added Note that this does not mean that |
Great, thank you! I haven't looked into this for a while but will definitely come back to this shortly for an ongoing project. |
Returning to this, before I give it another shot - do you think accessing SIMD vectors will now work?
Not entirely sure how to interpret this - does this mean that we still need upstream support, or is there a chance it might just work? |
I think you can try it out with the new encoding, might be that you're lucky, and that you can get the specific methods to work that you need - though I will still warn that it's fully undefined behaviour until we get support for SIMD in FFI in Rust (the |
I'm attempting to use
objc2
for Apple iOS API interoperability, and I'm really struggling with basic tasks, such as retrieving an Objective-C struct (simd_float4x4, https://developer.apple.com/documentation/arkit/aranchor/2867981-transform?language=objc) from an object into Rust. Naively, I assumed this would work, but it doesn't:and then
Could we have some more examples for things like this?
The text was updated successfully, but these errors were encountered: