News for hackers. Stuff that matters.
Re:What's Going Down at the Tiobe Index? Swift, Surprisingly by raphlinus on Saturday April 27, 2019 @05:45PM (#19767813)
I'm an extreme outlier, but I'm about to start an Objective-C codebase (a 2D renderer on top of Metal), because I suspect interop with Rust will be a lot easier. In particular, it looks like you can just build .m files from a build.rs, and I'm pretty sure that's not true with Swift. It's also possible to invoke Obj-C from Rust using the dynamic features, but I think that's both code bloat and a runtime cost. [I'm interested in exploring these issues further, but it's probably outside the scope of this HN thread, get in touch if you want to discuss.]

Example build.rs: https://github.com/emoon/rust_minifb/blob/master/build.rs

Re:What's Going Down at the Tiobe Index? Swift, Surprisingly by suraj on Saturday April 27, 2019 @07:37PM (#19768341)
If you want to call rust from Swift, it should be easy. I work with C libraries and it easy to interface with module maps. However, with objective C the interoperability is trivial. As long as you pay attention to retain cycles, you can hold reference and call objc methods directly. That said, please make sure your framework can be imported into Swift properly. As most of the users will be using Swift.
Re:What's Going Down at the Tiobe Index? Swift, Surprisingly by raphlinus on Saturday April 27, 2019 @07:50PM (#19768406)
Yes, I've seen examples of calling Rust from Swift, and I do plan to support that. This particular thing is about calling macOS platform functions from Rust code. Projects either call Objective-C API's from native Rust code using the dynamic invocation mechanism (which I think is slow and code-bloaty but want to measure more carefully), or they use the "cc" crate to include Objective-C code (and then generally use C ABI calls from Rust code into that). I've never seen Rust code that compiles Swift from a "cargo build" but of course would love to be proven wrong.
Re:What's Going Down at the Tiobe Index? Swift, Surprisingly by saagarjha on Saturday April 27, 2019 @07:35PM (#19768329)
Why can’t you build Swift from your build.rs?
Re:What's Going Down at the Tiobe Index? Swift, Surprisingly by raphlinus on Saturday April 27, 2019 @07:47PM (#19768389)
Maybe I can, I just haven't found an example of it. Certainly the "cc" crate doesn't seem to know how to compile Swift files. This might be more of a documentation issue than a real technical limitation though.
Re:What's Going Down at the Tiobe Index? Swift, Surprisingly by saagarjha on Saturday April 27, 2019 @08:22PM (#19768533)
If you can figure out a way to run arbitrary commands, I’d suggest looking at swift -frontend, which works like you’d expect a normal compiler to.