Apple Silicon – Compiling UNIX Command Line Programs on Intel-Based Macs

apple-siliconcommand lineterminalunix

I have a GUI wrapper of UNIX command line program. I noticed that Apple announced Apple Silicon Mac. Sooner or later I need to build Universal Binary of my GUI wrapper. But at first, I need to build UNIX command line program for Apple Silicon. Currently I only have Intel-based Mac. Is it possible to compile UNIX command line program for Apple Silicon architecture on Intel-based Mac?

Note: I know Apple provides Apple Silicon Mac mini for $500, but I don't have the a money now.

Best Answer

The process of building a binary for a different architecture than the one you're running is called cross compilation.

As highlighted by the other answers, this is a relatively common occurence, especially in the history of Apple which switched from 68K processors to Power PC, then to Intel, and now to ARM.

Mind you, anyone building an app for iPhone or iPad on their Mac has been cross-compiling, as those already use ARM architecture while their Mac currently uses the Intel architecture. It's even common to build multi-architecture iOS apps, as various CPU versions actually use different variants of the ARM architecture (armv7, armv8...).

Likewise, it's common to build i386 (Intel 32-bit) and amd64/x64 (Intel 64-bit) variants, either independently or as fat/universal binaries.

The process for cross-compiling and building fat/universal binaries depends a lot on the environment and toolchain you use. If you use Xcode, then it's going to be a matter of changing project settings, and voilĂ !, it's done.

If you are using Unix-type tools (mostly on the command line), including make or variants, gcc or clang, etc, then it may require more or less tinkering of your build process to achieve all that, with quite a few options to change (architecture, but also header files and libraries locations), as well as adding the step which combines the multiple architecture-dependent binaries into a single fat/universal binary.

So it all really depends on your current build process and the tools you use. But it will definitely be possible.

Of course, this is all based on the code to compile actually being portable, i.e. not making assumptions about things (like integer or pointer sizes) and not requiring any assembler code. That used to be a big issue in the past (especially with pure C code), but nowadays with the number of architectures software is currently built for, it's much less common to encounter issues with this.