Add optional CMake presets to the repo. (#15581)
Since people have complained about this in the past with respect to IDEs
doing weird things, I created these in a sub-directory with the
intention to just have a small include file in the root. Leaving that up
to the user to do until we can test it more with real dev flows.
With this, I was able to get:
* Minimal dev down to 3800 ninja actions to build iree-compile.
* ~5900 ninja actions for Turbine with a host-only CPU backend.
There are on the order of several hundred C++ files that I expect will
be eliminated once more of the compiler components are turned into
plugins with their dependent pieces contained (i.e. as opposed to having
dependencies for all targets implicitly included in top-level
registrations). Currently, this includes common code needed for SPIRV,
CPU compilation, various GPUs, etc (even when the corresponding target
is not enabled).
Further, I will do more surgery to make the clang build optional for
people who can satisfy the dep with a host clang. This will drop true
min-spec CPU builds by ~1000 targets.
Progress on #5804
skip-ci: none
diff --git a/build_tools/cmake/presets/README.md b/build_tools/cmake/presets/README.md
new file mode 100644
index 0000000..9624f37
--- /dev/null
+++ b/build_tools/cmake/presets/README.md
@@ -0,0 +1,58 @@
+# CMake Presets
+
+We are experimenting with CMake presets for setting up the project in
+various ways. Because these can interact badly with tools, we do not
+yet have a `CMakePresets.json` in the root project folder, instead
+requiring someone to add one themselves and include presets from here.
+
+Once this is tested some more, we will enable by default. For now,
+create a `CMakeUserPresets.json` in the project root and put this in it:
+
+```
+{
+ "version": 4,
+ "cmakeMinimumRequired": {
+ "major": 3,
+ "minor": 23,
+ "patch": 0
+ },
+ "include": [
+ "build_tools/cmake/presets/all.json"
+ ]
+}
+```
+
+## Using Presets
+
+There are two variants of presets that we use:
+
+* `new-{os}-{variant}`: Sets up a new dev directory as documented
+[on the website](https://iree.dev/building-from-source/getting-started/#quickstart-clone-and-build)
+with various further options. This is run from a source directory and will
+set up the generator and build into `../iree-build`.
+* `{variant}`: The raw variant options can be set at any time from
+a build directory with `cmake --preset {variant} .`.
+
+Since the 'new' variants are OS specific, you must use the one appropriate
+for your operating system. One of "linux", "macos", "windows".
+
+## New Project Presets
+
+* `cmake --preset new-{os}-dev`: Start a new dev build with CMake defaults for
+ all project features.
+* `cmake --preset new-{os}-minimal`: Start a new dev build with all optional
+ project features disabled. While not particularly useful, this lets selected
+ features be enabled as needed.
+* `cmake --preset new-{os}-turbine`: Start a new dev build with all optional
+ project features disabled except those needed to do Turbine development (
+ currently CPU backend, Torch input, and Python bindings).
+
+## Existing Project Presets
+
+An existing build directory can have its CMake options redefined with
+these presets:
+
+* `cmake . --preset minimal`: Disable all optional project features.
+* `cmake . --preset python-bindings`: Enable Python bindings in dev mode.
+* `cmake . --preset turbine`: Disable all optional project features except
+ those needed for Turbine development on CPU.
diff --git a/build_tools/cmake/presets/all.json b/build_tools/cmake/presets/all.json
new file mode 100644
index 0000000..2e32b68
--- /dev/null
+++ b/build_tools/cmake/presets/all.json
@@ -0,0 +1,13 @@
+{
+ "version": 4,
+ "cmakeMinimumRequired": {
+ "major": 3,
+ "minor": 23,
+ "patch": 0
+ },
+ "include": [
+ "new.json",
+ "options.json",
+ "turbine.json"
+ ]
+}
diff --git a/build_tools/cmake/presets/new.json b/build_tools/cmake/presets/new.json
new file mode 100644
index 0000000..fffc848
--- /dev/null
+++ b/build_tools/cmake/presets/new.json
@@ -0,0 +1,118 @@
+{
+ "version": 4,
+ "cmakeMinimumRequired": {
+ "major": 3,
+ "minor": 23,
+ "patch": 0
+ },
+ "configurePresets": [
+ {
+ "name": "new-linux-dev",
+ "displayName": "(START HERE) Set up a new dev directory with recommended generator and layout",
+ "description": "Matches https://iree.dev/building-from-source/getting-started/#quickstart-clone-and-build",
+ "condition":{
+ "type": "equals",
+ "lhs": "${hostSystemName}",
+ "rhs": "Linux"
+ },
+ "inherits": [
+ "_new_dev"
+ ],
+ "cacheVariables": {
+ "CMAKE_C_COMPILER": {
+ "type": "STRING",
+ "value": "clang"
+ },
+ "CMAKE_CXX_COMPILER": {
+ "type": "STRING",
+ "value": "clang++"
+ },
+ "CMAKE_C_COMPILER_LAUNCHER": {
+ "type": "STRING",
+ "value": "ccache"
+ },
+ "CMAKE_CXX_COMPILER_LAUNCHER": {
+ "type": "STRING",
+ "value": "ccache"
+ },
+ "IREE_ENABLE_SPLIT_DWARF": {
+ "type": "BOOL",
+ "value": "ON"
+ },
+ "IREE_ENABLE_THIN_ARCHIVES": {
+ "type": "BOOL",
+ "value": "ON"
+ },
+ "IREE_ENABLE_LLD": {
+ "type": "BOOL",
+ "value": "ON"
+ }
+ }
+ },
+ {
+ "name": "new-macos-dev",
+ "displayName": "(START HERE) Set up a new dev directory with recommended generator and layout",
+ "description": "Matches https://iree.dev/building-from-source/getting-started/#quickstart-clone-and-build",
+ "inherits": [
+ "_new_dev"
+ ],
+ "condition":{
+ "type": "equals",
+ "lhs": "${hostSystemName}",
+ "rhs": "Darwin"
+ },
+ "cacheVariables": {
+ "IREE_ENABLE_SPLIT_DWARF": {
+ "type": "BOOL",
+ "value": "ON"
+ },
+ "CMAKE_C_COMPILER": {
+ "type": "STRING",
+ "value": "clang"
+ },
+ "CMAKE_CXX_COMPILER": {
+ "type": "STRING",
+ "value": "clang++"
+ },
+ "CMAKE_C_COMPILER_LAUNCHER": {
+ "type": "STRING",
+ "value": "ccache"
+ },
+ "CMAKE_CXX_COMPILER_LAUNCHER": {
+ "type": "STRING",
+ "value": "ccache"
+ },
+ "IREE_ENABLE_LLD": {
+ "type": "BOOL",
+ "value": "ON"
+ }
+ }
+ },
+ {
+ "name": "new-windows-dev",
+ "displayName": "(START HERE) Set up a new dev directory with recommended generator and layout",
+ "description": "Matches https://iree.dev/building-from-source/getting-started/#quickstart-clone-and-build",
+ "inherits": [
+ "_new_dev"
+ ],
+ "condition":{
+ "type": "equals",
+ "lhs": "${hostSystemName}",
+ "rhs": "Windows"
+ }
+ },
+ {
+ "name": "_new_dev",
+ "hidden": true,
+ "generator": "Ninja",
+ "binaryDir": "${sourceDir}/../iree-build",
+ "cacheVariables": {
+ "CMAKE_BUILD_TYPE": "RelWithDebInfo",
+ "IREE_ENABLE_ASSERTIONS": {
+ "type": "BOOL",
+ "value": "ON"
+ }
+ }
+ }
+ ]
+}
diff --git a/build_tools/cmake/presets/options.json b/build_tools/cmake/presets/options.json
new file mode 100644
index 0000000..3565369
--- /dev/null
+++ b/build_tools/cmake/presets/options.json
@@ -0,0 +1,149 @@
+{
+ "version": 4,
+ "cmakeMinimumRequired": {
+ "major": 3,
+ "minor": 23,
+ "patch": 0
+ },
+ "include": [
+ "new.json"
+ ],
+ "configurePresets": [
+ {
+ "name": "minimal",
+ "displayName": "Minimal config",
+ "description": "Project configured with minimal features enabled",
+ "cacheVariables": {
+ "IREE_DEFAULT_CPU_LLVM_TARGETS": {
+ "type": "STRING",
+ "value": "host"
+ },
+ "IREE_BUILD_SAMPLES": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_BUILD_PYTHON_BINDINGS": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_BUILD_BINDINGS_TFLITE": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_EXTERNAL_HAL_DRIVERS": {
+ "type": "STRING",
+ "value": ""
+ },
+ "IREE_HAL_DRIVER_DEFAULTS": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_HAL_DRIVER_CUDA": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_HAL_DRIVER_LOCAL_SYNC": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_HAL_DRIVER_VULKAN": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_HAL_DRIVER_METAL": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_TARGET_BACKEND_DEFAULTS": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_TARGET_BACKEND_LLVM_CPU": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_TARGET_BACKEND_LLVM_CPU_WASM": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_TARGET_BACKEND_ROCM": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_TARGET_BACKEND_METAL_SPIRV": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_TARGET_BACKEND_VULKAN_SPIRV": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_TARGET_BACKEND_CUDA": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_TARGET_BACKEND_WEBGPU": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_INPUT_STABLEHLO": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_INPUT_TORCH": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_INPUT_TOSA": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "IREE_OUTPUT_FORMAT_C": {
+ "type": "BOOL",
+ "value": "OFF"
+ }
+ }
+ },
+ {
+ "name": "python-bindings",
+ "displayName": "Python Development",
+ "cacheVariables": {
+ "IREE_BUILD_PYTHON_BINDINGS": {
+ "type": "BOOL",
+ "value": "OFF"
+ },
+ "Python3_FIND_VIRTUALENV": {
+ "type": "STRING",
+ "value": "ONLY"
+ }
+ }
+ },
+ {
+ "name": "new-linux-minimal",
+ "displayName": "(START HERE) Set Up New Minimal Dev Config",
+ "description": "Project configured with minimal features enabled",
+ "inherits": [
+ "new-linux-dev",
+ "minimal"
+ ]
+ },
+ {
+ "name": "new-macos-minimal",
+ "displayName": "(START HERE) Set Up New Minimal Dev Config",
+ "description": "Project configured with minimal features enabled",
+ "inherits": [
+ "new-macos-dev",
+ "minimal"
+ ]
+ },
+ {
+ "name": "new-windows-minimal",
+ "displayName": "(START HERE) Set Up New Minimal Dev Config",
+ "description": "Project configured with minimal features enabled",
+ "inherits": [
+ "new-windows-dev",
+ "minimal"
+ ]
+ }
+ ]
+}
diff --git a/build_tools/cmake/presets/turbine.json b/build_tools/cmake/presets/turbine.json
new file mode 100644
index 0000000..acfe0bf
--- /dev/null
+++ b/build_tools/cmake/presets/turbine.json
@@ -0,0 +1,60 @@
+{
+ "version": 4,
+ "cmakeMinimumRequired": {
+ "major": 3,
+ "minor": 23,
+ "patch": 0
+ },
+ "include": [
+ "new.json",
+ "options.json"
+ ],
+ "configurePresets": [
+ {
+ "name": "turbine",
+ "displayName": "Minimal Turbine Dev",
+ "description": "Enable minimal development of SHARK-Turbine with a CPU backend",
+ "inherits": [
+ "minimal",
+ "python-bindings"
+ ],
+ "cacheVariables": {
+ "IREE_INPUT_TORCH": {
+ "type": "BOOL",
+ "value": "ON"
+ },
+ "IREE_TARGET_BACKEND_LLVM_CPU": {
+ "type": "BOOL",
+ "value": "ON"
+ }
+ }
+ },
+ {
+ "name": "new-linux-turbine",
+ "displayName": "(START HERE) Set Up New Minimal Turbine Dev",
+ "description": "Recommended minimal config for new Turbine dev directory",
+ "inherits": [
+ "new-linux-dev",
+ "turbine"
+ ]
+ },
+ {
+ "name": "new-macos-turbine",
+ "displayName": "(START HERE) Set Up New Minimal Turbine Dev",
+ "description": "Recommended minimal config for new Turbine dev directory",
+ "inherits": [
+ "new-macos-dev",
+ "turbine"
+ ]
+ },
+ {
+ "name": "new-windows-turbine",
+ "displayName": "(START HERE) Set Up New Minimal Turbine Dev",
+ "description": "Recommended minimal config for new Turbine dev directory",
+ "inherits": [
+ "new-windows-dev",
+ "turbine"
+ ]
+ }
+ ]
+}