Post ANSpn2YbYdLb1ClPBA by shadowfacts@social.shadowfacts.net
 (DIR) More posts by shadowfacts@social.shadowfacts.net
 (DIR) Post #ANSNXj3QzMU3TI5pGy by stevestreza@mastodon.social
       2022-09-11T07:27:19Z
       
       1 likes, 0 repeats
       
       Not as easy as I would've liked but I have a working setup where Rust crate builds into static library into manually written Swift adapter package into Mac/iOS app. Resulting Mac app binary (x86_64 + aarm64) is only 2.3 MB.
       
 (DIR) Post #ANSNXkbrCrc4ILCpZA by stevestreza@mastodon.social
       2022-09-11T07:32:43Z
       
       0 likes, 0 repeats
       
       This should enable having a shared Rust core of data structures and business logic that can be bridged into basically any platform, and a native UI can be derived from library calls that are exposed to it. This covers Mac and iOS, Rust itself can be used to build Linux apps, so next would be writing adapters for Kotlin/Java on Android and … whatever you use to build Windows apps these days.
       
 (DIR) Post #ANSNsjmpSgQ9p7LSnA by shadowfacts@social.shadowfacts.net
       2022-09-11T14:00:36.451068Z
       
       0 likes, 0 repeats
       
       @stevestreza I'm curious what you're passing in as the pointer arg? the *mut BeamoClient type suggests it's a pointer to the swift type of the same name, but I was under the impression that you can't really do anything with that since swift doesn't have an equivalent #[repr("C")]or is it just an opaque (from the rust pov) pointer that it can pass back into other swift functions?
       
 (DIR) Post #ANSfIbsnAWti3n3bM0 by stevestreza@mastodon.social
       2022-09-11T16:52:03Z
       
       1 likes, 0 repeats
       
       @shadowfacts There's a Rust BeamoClient and a Swift BeamoClient, they have no knowledge of each other. The business logic is implemented in Rust, which doesn't really interact with Swift (though hopefully there can be a little through things like callbacks).Here's the fuller code, but renamed those types to RustBeamoClient and SwiftBeamoClient. https://gist.github.com/stevestreza/80f11d095c024743281de9de0be5432d
       
 (DIR) Post #ANSfgZtuBok8rZ0TOi by shadowfacts@social.shadowfacts.net
       2022-09-11T17:20:05.861014Z
       
       0 likes, 0 repeats
       
       @stevestreza does String(cString:) take ownership of the memory at that address? if it doesn't, or if it copies, that would leak the cloned String you created in Rust, right?when doing ffi stuff, I wish the swift docs were half as clear about ownership as rust lol
       
 (DIR) Post #ANSkSfieG9k0covha4 by stevestreza@mastodon.social
       2022-09-11T18:07:42Z
       
       1 likes, 0 repeats
       
       @shadowfacts A great question that I should probably figure out the answer to, huh
       
 (DIR) Post #ANSkdq6fym8S1jUf6e by shadowfacts@social.shadowfacts.net
       2022-09-11T18:15:37.785416Z
       
       0 likes, 0 repeats
       
       @stevestreza i spent too much time trying to figure out which string initializers to use for my rust/c bridgethe one I settled on was the bytesNoCopy one which has an explicit freeWhenDone param. and of course, i went to look at the docs just now and find out it's been deprecated this cycle:
       
 (DIR) Post #ANSpn1yRj4QLD3qWoq by stevestreza@mastodon.social
       2022-09-11T18:41:16Z
       
       0 likes, 0 repeats
       
       @shadowfacts Probably for the best, if the goal is to make a memory safe language, you can't really assume anything about that String beyond the lifetime of that initializer without copying.
       
 (DIR) Post #ANSpn2YbYdLb1ClPBA by shadowfacts@social.shadowfacts.net
       2022-09-11T19:13:17.477734Z
       
       0 likes, 0 repeats
       
       @stevestreza yeah, that's true. but it would be nice to do my weird syntax highlighting  setup work without having to copy the input string when it's only going to be read and not modifiedi guess caring about that potential (minute) bit of overhead is what differentiates a systems language from an application one
       
 (DIR) Post #ANT1ZjdzlOuQ2uhtiK by stevestreza@mastodon.social
       2022-09-11T19:25:49Z
       
       0 likes, 0 repeats
       
       @shadowfacts It may have ultimately been a lie due to NSString bridging: https://forums.swift.org/t/does-string-bytesnocopy-copy-bytes/51643
       
 (DIR) Post #ANT1Zk9BtPrXbfIoL2 by shadowfacts@social.shadowfacts.net
       2022-09-11T21:25:21.444363Z
       
       0 likes, 0 repeats
       
       @stevestreza ah, how foolish of me to believe the namelooking at the results from the end of that thread, it seems like i could avoid the copy by bridging from CFString; but that seems excessive, even for me
       
 (DIR) Post #ANUmkyZ2x6oh5JSVs0 by stevestreza@mastodon.social
       2022-09-12T08:19:37Z
       
       1 likes, 0 repeats
       
       Me: Ok I, a complete Rust newbie, have a working Rust bridge to C/Swift, so let me try to get it to do some async multi-threaded stuff in Rust with a callback to Swift.Rust and the Send trait: