How do I set up rust to cross compile for Mac on a Windows machine?

I want to develop a small application (in rust) for a friend, who uses a Mac. I, however, have a Windows PC. My understanding is that it's possible to cross-compile, so I (naively!) went ahead and ran rustup target add aarch64-apple-darwin. That worked fine. But when I tried to build a simple "Hello, world" example, I got an error

❯ cargo build --release --target aarch64-apple-darwin
   Compiling test_exe v0.1.0 (C:\Work\Scratch\test_exe)
error: linker `cc` not found
  |
  = note: The system cannot find the file specified. (os error 2)

error: could not compile `test_exe` due to previous error

I suppose it was a bit optimistic to expect things to "just work"...

I've done some hunting around, and there's a number of articles on cross-compiling for mac, but they all seem to be for people on Linux, I wasn't able to find anything for Windows. I'm assuming the problem is that rust needs some form of linker that understands MacOS, but I don't know how I'd provide something like that. I do have gcc and clang installed on my PC (windows ports), but neither provide the cc command that rust seems to be looking for.

I guess the first question is, is this something that it's reasonable for me to be even trying to do? And if it is, where can I find some information on what I need? I did some searches, but couldn't find anything that seemed relevant.

Just to be clear, I can solve the underlying issue here (sending my friend a program to solve his problem) in many ways. It's not by any means essential to write it in rust and cross-compile. My main interest in cross-compiling is to learn more about how it works, find out what is and isn't possible, and generally experiment. So, for example, while I could use WSL and set up a linux-to-mac cross-compilation environment following the articles I've found, it's not really what I'm trying to achieve here.

Not really. Cross-compiling to Apple's platforms has never really been supported. Getting a cross-compiler to run on Windows is even more of a challenge. If anything, I would try to do it from Linux (WSL2 is pretty decent, actually).

I remember looking into this a while back and there were issues where it's not possible to legally get MacOS system libraries that you can link against for non-mac platforms. I could be mis-remembering or going off outdated information, of course.

For a practical answer to your problem, normally if I need to distribute an application to multiple platforms I'll just set up 3 build jobs in CI, one for Linux, one for Windows, and one for MacOS. Although that's not overly helpful if your real objective is to learn more about cross-compiling...

1 Like

Ah, OK. My need isn't critical enough that it's worth setting up a Linux environment just so I can fight with trying to get cross-to-mac working there. I might one day set up rust on WSL just to get some experience developing on Linux as well as Windows, but I think I'll leave cross-compiling out of it :slightly_smiling_face:

Yep, that's what I was thinking of as a fallback.

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.