How do i get rust working in xcode

so i've been working with rust for abt 3 months now and i'm developing an app for macOS.
I did my research and found out that i have to use XCode--my most hated ide cos of its poor language support. I could not find anyway to get it working in xcode that actually works. does anyone have any idea of how to do this?

Wy would you have to use XCode? Does your employer require it?

yep

I have never tried it -- but while looking for instruments support for cargo (cargo-instruments, btw) I stumbled on cargo-xcode.

TBH I wouldn't expect the DX of XCode to be a good one for any language (and associated ecosystems) not developed by Apple.
For example, I wouldn't expect any editor services (eg syntax highlighting, navigate-to-definition, inline error display etc) to work for Rust, nor would I expect support for LSP. If XCode opens Rust code at all, it'll likely be flat monochrome text rendering, and nothing more.

So if I had to develop an iOS/iPadOS/MacOS app now that contained Rust code, I'd minimize the time spent editing Rust in XCode. Instead I would develop the Rust code in my usual editor (Emacs in my case but that's not too relevant), create a nice C FFI, and just use that FFI from the Swift/ObjC code.

As for the employer requiring it, this would be a good moment to inform them that XCode is just the wrong tool for the job, and some flexibility on their part is required.

Unless they'd also make an electrician do their job with a proverbial shovel, they're likely to listen to you on this.

2 Likes

Why would your employer require use of Xcode for writing Rust? I’m not sure that makes sense. Or do they not know you’re planning on using Rust?

Xcode is really for Swift and Objective-C, and to some extent C(++).

If you’re making the app using Rust you’ll likely want to use a different IDE/editor. What you might need Xcode for however, depending on your setup, is submitting the app to App Store.

1 Like

we're using it incase the libraries we're using doesn't work and so swift devs can use our libraries

So the main app is written in Swift and you’re writing the libraries it will/might use in Rust?

In which case yeah I’d follow what @jjpe said and expose a C FFI to the Swift code. There are also other approaches to Swift-Rust interop but I’m not familiar with them.

But I think the main thing is that you probably don’t want to be writing the actual Rust code using Xcode as it’s just not set up for Rust development.

Xcode comes into play when writing the Swift, and wiring up the libraries, and perhaps performing actions related to your Apple Developer account and submitting to App Store. But for the Rust itself I’d stick to whatever IDE/editor you’ve been using up to this point.

@blonk's post about cargo-xcode sounds like it may be useful for this part.

that doesn't make any sense – Swift devs will use whatever IDE they please (yes, likely Xcode), which is completely independent of whatever IDE you use to develop the library. There's no rule such as "a library can only be used in Xcode if it was developed in Xcode".

An IDE is just a fancy text editor that happens to have some built-in macros for also invoking a compiler. It doesn't matter what editor the source text is written in. It doesn't matter whether an IDE invokes the compiler or you do it by hand. It's going to be the same source text and the same compiler. It just doesn't matter at all.

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.