| Phoenix Meadowlark | 1633aa3 | 2020-06-17 12:28:58 -0700 | [diff] [blame] | 1 | # Getting Started on macOS with CMake |
| 2 | |
| 3 | <!-- |
| 4 | Notes to those updating this guide: |
| 5 | |
| 6 | * This document should be __simple__ and cover essential items only. |
| 7 | Notes for optional components should go in separate files. |
| 8 | |
| 9 | * This document parallels getting_started_linux_cmake.md and |
| 10 | getting_started_windows_cmake.md |
| 11 | Please keep them in sync. |
| 12 | --> |
| 13 | |
| 14 | This guide walks through building the core compiler and runtime parts of IREE |
| 15 | from source. Auxiliary components like the Python bindings and Vulkan driver are |
| 16 | not documented for macOS at this time. |
| 17 | |
| 18 | IREE is not officially supported on macOS at this time. It may work, but it is |
| 19 | not a part of our open source CI, and may be intermittently broken. |
| 20 | Contributions related to macOS support and documentation are welcome however. |
| 21 | |
| 22 | ## Prerequisites |
| 23 | |
| 24 | ### Install Homebrew |
| 25 | |
| 26 | This guide uses [Homebrew](https://brew.sh/) to install IREE's dependencies. |
| 27 | |
| 28 | ```shell |
| 29 | $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" |
| 30 | ``` |
| 31 | |
| 32 | ### Install CMake |
| 33 | |
| 34 | IREE uses [CMake](https://cmake.org/) version `>= 3.13`. Brew ships the latest |
| 35 | release. |
| 36 | |
| 37 | ```shell |
| 38 | $ brew install cmake |
| 39 | $ cmake --version # >= 3.13 |
| 40 | ``` |
| 41 | |
| 42 | ### Install Ninja |
| 43 | |
| 44 | [Ninja](https://ninja-build.org/) is a fast build system that you can use as a |
| 45 | CMake generator. |
| 46 | |
| 47 | ```shell |
| 48 | $ brew install ninja |
| 49 | ``` |
| 50 | |
| 51 | ## Clone and Build |
| 52 | |
| 53 | ### Clone |
| 54 | |
| 55 | Clone the repository and initialize its submodules: |
| 56 | |
| 57 | ```shell |
| 58 | $ git clone https://github.com/google/iree.git |
| 59 | $ cd iree |
| 60 | $ git submodule update --init |
| 61 | ``` |
| 62 | |
| 63 | > Tip:<br> |
| 64 | > Editors and other programs can also clone the |
| 65 | > repository, just make sure that they initialize the submodules. |
| 66 | |
| 67 | ### Build |
| 68 | |
| 69 | Configure: |
| 70 | |
| 71 | ```shell |
| 72 | $ cmake -G Ninja -B build/ . |
| 73 | ``` |
| 74 | |
| 75 | Note: this should use `Clang` by default on macOS. `GCC` is not fully supported |
| 76 | by IREE. |
| 77 | |
| 78 | > Tip:<br> |
| 79 | > The root |
| Scott Todd | 4e5167d | 2020-06-29 09:30:35 -0700 | [diff] [blame] | 80 | > [CMakeLists.txt](https://github.com/google/iree/blob/main/CMakeLists.txt) |
| Marius Brehler | c5c8b7c | 2020-06-22 14:38:05 -0700 | [diff] [blame] | 81 | > file has options for configuring which parts of the project to enable.<br> |
| 82 | > These are further documented in [CMake Options and Variables](cmake_options_and_variables.md). |
| Phoenix Meadowlark | 1633aa3 | 2020-06-17 12:28:58 -0700 | [diff] [blame] | 83 | |
| 84 | Build all targets: |
| 85 | |
| 86 | ```shell |
| 87 | $ cmake --build build/ |
| 88 | ``` |
| 89 | |
| 90 | ## What's next? |
| 91 | |
| 92 | ### Take a Look Around |
| 93 | |
| 94 | Check out the contents of the 'tools' build directory: |
| 95 | |
| 96 | ```shell |
| 97 | $ ls build/iree/tools |
| 98 | $ ./build/iree/tools/iree-translate --help |
| 99 | ``` |
| 100 | |
| 101 | Translate a |
| Scott Todd | 4e5167d | 2020-06-29 09:30:35 -0700 | [diff] [blame] | 102 | [MLIR file](https://github.com/google/iree/blob/main/iree/tools/test/simple.mlir) |
| Phoenix Meadowlark | 1633aa3 | 2020-06-17 12:28:58 -0700 | [diff] [blame] | 103 | and execute a function in the compiled module: |
| 104 | |
| 105 | ```shell |
| 106 | $ ./build/iree/tools/iree-run-mlir $PWD/iree/tools/test/simple.mlir \ |
| 107 | -input-value="i32=-2" -iree-hal-target-backends=vmla -print-mlir |
| 108 | ``` |
| 109 | |
| 110 | ### Further Reading |
| 111 | |
| 112 | * For an introduction to IREE's project structure and developer tools, see |
| Lei Zhang | 6171a98 | 2020-09-08 12:48:25 -0400 | [diff] [blame] | 113 | [Developer Overview](../developing_iree/developer_overview.md). |
| 114 | * To understand how IREE implements HAL over Metal, see |
| Copybara-Service | 955256c | 2020-09-08 14:39:07 -0700 | [diff] [blame] | 115 | [Metal HAL Driver](../design_docs/metal_hal_driver.md). <!-- TODO: Link to |
| 116 | macOS versions of these guides once they are developed. |
| Phoenix Meadowlark | 1633aa3 | 2020-06-17 12:28:58 -0700 | [diff] [blame] | 117 | * To use IREE's Python bindings, see |
| 118 | [Getting Started with Python](getting_started_python.md) --> |