Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[build] Apple Silicon M1 build support
Fixes: dotnet#5518 Context: https://github.com/xamarin/xamarin-android/projects/16 [Apple announced new Mac hardware][0], which use an [M1 CPU][1], which is an arm64-compatible ABI, *not* intel based. Legacy software built for intel CPUs will still run via the [Rosetta][3] translation environment. Because of Rosetta, existing Xamarin.Android binaries will work as-is on Mac hardware with M1 CPUs. However, what if you want to *build* the xamarin-android repo on an M1 CPU? Previously, that would fail: % make prepare PREPARE_AUTOPROVISION=true … Error: Could not find Homebrew on this system, please install it from https://brew.sh/ Unfortunately, [Homebrew][4] won't install by default: % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" Password: Homebrew is not (yet) supported on ARM processors! Rerun the Homebrew installer under Rosetta 2. If you really know what you are doing and are prepared for a very broken experience you can use another installation option for installing on ARM: https://docs.brew.sh/Installation However, there *is* a way to install Homebrew! You "just" need to "lie" about the processor being used! % arch -arch x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # works! This works by using the [**arch**(1)][5] command, which allows explicitly specifying (overriding) the CPU environment that the child process runs within. Within `arch -arch x86_64 command`, `command` believes it's running on an x86_64 CPU. Update the Unix `dependencies.md` documentation to document how to install Homebrew on an M1 CPU. Update `xaprepare` so that whenever a `brew` command is executed on an M1 CPU, the command is prefixed with `arch -arch x86_64`. `xaprepare` uses the [`sysctl.proc_translated` system control][6] to determine if it's currently running within a Rosetta environment, so that `arch -arch x86_64` is not used unless required. [0]: https://www.apple.com/newsroom/2020/11/introducing-the-next-generation-of-mac/ [1]: https://www.apple.com/newsroom/2020/11/apple-unleashes-m1/ [2]: https://www.apple.com/newsroom/2020/11/apple-unleashes-m1/ [3]: https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment [4]: https://brew.sh [5]: https://www.unix.com/man-page/osx/1/arch/ [6]: https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment#3616845
- Loading branch information