Rework cmake test deps, target selection and presets. (#8423)
* Rework cmake test deps, target selection and presets.
This patch does a few things:
* Marks all targets under iree/test/ as EXCLUDE_FROM_ALL.
* Configures check-tests to add a dependency to the global iree-test-deps target.
* Added a seperate build step for CIs to build iree-test-deps.
* Reworks compiler target selection to distinguish between "default" targets and those not built by default.
* Fine-grained LLVM_TARGETS_TO_BUILD are added based on the IREE targets.
* lld is built if CPU targets are enabled.
* CPU targets are expanded from a new IREE_CPU_LLVM_TARGETS option (defaults to what we had previously hard-coded).
diff --git a/.gitignore b/.gitignore
index daed71b..a6b3352 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,6 +27,7 @@
configured.bazelrc
user.bazelrc
version_info.json
+CMakeUserPresets.json
# Dear ImGui Ini files
imgui.ini
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0401f10..317b129 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,6 +29,7 @@
#-------------------------------------------------------------------------------
# Project component configuration
+# See also: build_tools/cmake/iree_cmake_options.cmake
#-------------------------------------------------------------------------------
option(IREE_ENABLE_RUNTIME_TRACING "Enables instrumented runtime tracing." OFF)
@@ -68,12 +69,13 @@
cmake_dependent_option(IREE_ENABLE_EMITC "Enables MLIR EmitC dependencies." ON ${IREE_BUILD_COMPILER} OFF)
#-------------------------------------------------------------------------------
-# Target and backend configuration
+# Runtime HAL Driver Options
+# By default, all runtime drivers supported by the current platform which do
+# not require external deps are enabled by default. This can be changed with:
+# -DIREE_HAL_DRIVER_DEFAULTS=OFF
#-------------------------------------------------------------------------------
option(IREE_HAL_DRIVER_DEFAULTS "Sets the default value for all runtime HAL drivers" ON)
-option(IREE_TARGET_BACKEND_DEFAULTS "Sets the default value for all compiler target backends" ${IREE_BUILD_COMPILER})
-
# CUDA support must be explicitly enabled.
set(IREE_HAL_DRIVER_CUDA_DEFAULT OFF)
@@ -92,31 +94,25 @@
option(IREE_HAL_DRIVER_VMVX_SYNC "Enables the 'vmvx-sync' runtime HAL driver" ${IREE_HAL_DRIVER_DEFAULTS})
option(IREE_HAL_DRIVER_VULKAN "Enables the 'vulkan' runtime HAL driver" ${IREE_HAL_DRIVER_VULKAN_DEFAULT})
-cmake_dependent_option(IREE_TARGET_BACKEND_CUDA "Enables the 'cuda' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF)
-cmake_dependent_option(IREE_TARGET_BACKEND_DYLIB_LLVM_AOT "Enables the 'dylib-llvm-aot' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF)
-cmake_dependent_option(IREE_TARGET_BACKEND_METAL_SPIRV "Enables the 'metal-spirv' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF)
-cmake_dependent_option(IREE_TARGET_BACKEND_ROCM "Enables the 'rocm' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF)
-cmake_dependent_option(IREE_TARGET_BACKEND_VMVX "Enables the 'vmvx' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF)
-cmake_dependent_option(IREE_TARGET_BACKEND_VULKAN_SPIRV "Enables the 'vulkan-spirv' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF)
-cmake_dependent_option(IREE_TARGET_BACKEND_WASM_LLVM_AOT "Enables the 'wasm-llvm-aot' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF)
-# Disable WebGPU by default - it has complex deps and is under development.
-cmake_dependent_option(IREE_TARGET_BACKEND_WEBGPU "Enables the 'webgpu' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF)
-
-message(VERBOSE "IREE build runtime HAL driver 'cuda': ${IREE_HAL_DRIVER_CUDA}")
-message(VERBOSE "IREE build runtime HAL driver 'dylib': ${IREE_HAL_DRIVER_DYLIB}")
-message(VERBOSE "IREE build runtime HAL driver 'dylib-sync': ${IREE_HAL_DRIVER_DYLIB_SYNC}")
-message(VERBOSE "IREE build runtime HAL driver 'vmvx': ${IREE_HAL_DRIVER_VMVX}")
-message(VERBOSE "IREE build runtime HAL driver 'vmvx-sync': ${IREE_HAL_DRIVER_VMVX_SYNC}")
-message(VERBOSE "IREE build runtime HAL driver 'vulkan': ${IREE_HAL_DRIVER_VULKAN}")
-
-message(VERBOSE "IREE build compiler target backend 'cuda': ${IREE_TARGET_BACKEND_CUDA}")
-message(VERBOSE "IREE build compiler target backend 'dylib-llvm-aot': ${IREE_TARGET_BACKEND_DYLIB_LLVM_AOT}")
-message(VERBOSE "IREE build compiler target backend 'wasm-llvm-aot': ${IREE_TARGET_BACKEND_WASM_LLVM_AOT}")
-message(VERBOSE "IREE build compiler target backend 'metal-spirv': ${IREE_TARGET_BACKEND_METAL_SPIRV}")
-message(VERBOSE "IREE build compiler target backend 'rocm': ${IREE_TARGET_BACKEND_ROCM}")
-message(VERBOSE "IREE build compiler target backend 'vulkan-spirv': ${IREE_TARGET_BACKEND_VULKAN_SPIRV}")
-message(VERBOSE "IREE build compiler target backend 'vmvx': ${IREE_TARGET_BACKEND_VMVX}")
-message(VERBOSE "IREE build compiler target backend 'webgpu': ${IREE_TARGET_BACKEND_WEBGPU}")
+message(STATUS "IREE runtime drivers:")
+if(IREE_HAL_DRIVER_CUDA)
+ message(STATUS " - cuda")
+endif()
+if(IREE_HAL_DRIVER_DYLIB)
+ message(STATUS " - dylib")
+endif()
+if(IREE_HAL_DRIVER_DYLIB_SYNC)
+ message(STATUS " - dylib-sync")
+endif()
+if(IREE_HAL_DRIVER_VMVX)
+ message(STATUS " - vmvx")
+endif()
+if(IREE_HAL_DRIVER_VMVX_SYNC)
+ message(STATUS " - vmvx-sync")
+endif()
+if(IREE_HAL_DRIVER_VULKAN)
+ message(STATUS " - vulkan")
+endif()
#-------------------------------------------------------------------------------
# IREE compilation toolchain configuration
@@ -202,9 +198,10 @@
include(iree_cc_binary)
include(iree_cc_library)
include(iree_cc_test)
+include(iree_cmake_options)
+include(iree_external_cmake_options)
include(iree_tablegen_library)
include(iree_tablegen_doc)
-include(iree_third_party_cmake_options)
include(iree_c_embed_data)
include(iree_bytecode_module)
include(iree_c_module)
@@ -227,6 +224,13 @@
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
#-------------------------------------------------------------------------------
+# Core options initialization (for options defined in macros in
+# iree_cmake_options.cmake).
+#-------------------------------------------------------------------------------
+
+iree_set_compiler_cmake_options()
+
+#-------------------------------------------------------------------------------
# IREE compilation flags
#-------------------------------------------------------------------------------
@@ -399,12 +403,12 @@
# Enable MLIR Python bindings if IREE Python bindings enabled.
if(IREE_BUILD_PYTHON_BINDINGS)
- set(MLIR_ENABLE_BINDINGS_PYTHON ON CACHE BOOL "" FORCE)
- set(MHLO_ENABLE_BINDINGS_PYTHON ON CACHE BOOL "" FORCE)
+ set(MLIR_ENABLE_BINDINGS_PYTHON ON)
+ set(MHLO_ENABLE_BINDINGS_PYTHON ON)
endif()
# Disable LLVM's warnings.
- set(LLVM_ENABLE_WARNINGS OFF CACHE BOOL "don't use global flags /facepalm")
+ set(LLVM_ENABLE_WARNINGS OFF)
# Stash cmake build type in case LLVM messes with it.
set(_CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
@@ -416,7 +420,7 @@
add_subdirectory("third_party/llvm-project/llvm" EXCLUDE_FROM_ALL)
# Reset CMAKE_BUILD_TYPE to its previous setting.
- set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" CACHE STRING "Build type (default ${DEFAULT_CMAKE_BUILD_TYPE})" FORCE)
+ set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" )
# Extend module path to allow submodules to use LLVM and MLIR CMake modules.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_BINARY_DIR}/lib/cmake/mlir")
@@ -530,6 +534,10 @@
add_custom_target(iree-doc ALL)
endif()
+# Testing rules that require generation will add dependencies to this target.
+# This allows them to be EXCLUDE_FROM_ALL but still invokable.
+add_custom_target(iree-test-deps COMMENT "Building IREE test deps")
+
#-------------------------------------------------------------------------------
# IREE top-level libraries
#-------------------------------------------------------------------------------
@@ -544,7 +552,8 @@
add_subdirectory(iree/schemas)
add_subdirectory(iree/task)
add_subdirectory(iree/testing)
-add_subdirectory(iree/test)
+# Note: Test deps are not built as part of all (use the iree-test-deps target).
+add_subdirectory(iree/test EXCLUDE_FROM_ALL)
add_subdirectory(iree/vm)
if(${IREE_BUILD_BENCHMARKS})
@@ -637,10 +646,5 @@
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/.env"
CONTENT "${_pythonpath_env}"
)
-
- # TODO: Remove this after about Dec-2021
- if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/bindings/python/iree/compiler")
- message(FATAL_ERROR "You are running in a build directory which needs some manual cleanup. Please delete the directory ${CMAKE_CURRENT_BINARY_DIR}/bindings/python/iree/compiler")
- endif()
endif()
endif()
diff --git a/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py b/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
index aec51db..eb8b4e9 100644
--- a/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
+++ b/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
@@ -29,9 +29,23 @@
"IREEPyDMPasses"
],
+ # Disable all hard-coded codegen targets (they are expanded dynamically
+ # in CMake).
+ "@llvm-project//llvm:AArch64AsmParser": ["IREELLVMCPUTargetDeps"],
+ "@llvm-project//llvm:AArch64CodeGen": ["IREELLVMCPUTargetDeps"],
+ "@llvm-project//llvm:ARMAsmParser": ["IREELLVMCPUTargetDeps"],
+ "@llvm-project//llvm:ARMCodeGen": ["IREELLVMCPUTargetDeps"],
+ "@llvm-project//llvm:RISCVAsmParser": ["IREELLVMCPUTargetDeps"],
+ "@llvm-project//llvm:RISCVCodeGen": ["IREELLVMCPUTargetDeps"],
+ "@llvm-project//llvm:WebAssemblyAsmParser": ["IREELLVMCPUTargetDeps"],
+ "@llvm-project//llvm:WebAssemblyCodeGen": ["IREELLVMCPUTargetDeps"],
+ "@llvm-project//llvm:X86AsmParser": ["IREELLVMCPUTargetDeps"],
+ "@llvm-project//llvm:X86CodeGen": ["IREELLVMCPUTargetDeps"],
+
# LLVM
+ "@llvm-project//llvm:config": [],
"@llvm-project//llvm:IPO": ["LLVMipo"],
- "@llvm-project//lld": ["lld"],
+ "@llvm-project//lld": ["${IREE_LLD_TARGET}"],
"@llvm-project//llvm:FileCheck": ["FileCheck"],
# MLIR
"@llvm-project//mlir:AllPassesAndDialects": ["MLIRAllDialects"],
diff --git a/build_tools/cmake/iree_bytecode_module.cmake b/build_tools/cmake/iree_bytecode_module.cmake
index 125670c..24d8bbc 100644
--- a/build_tools/cmake/iree_bytecode_module.cmake
+++ b/build_tools/cmake/iree_bytecode_module.cmake
@@ -100,7 +100,6 @@
endif()
iree_get_executable_path(_TRANSLATE_TOOL_EXECUTABLE ${_TRANSLATE_TOOL})
- iree_get_executable_path(_EMBEDDED_LINKER_TOOL_EXECUTABLE "lld")
set(_ARGS "${_RULE_FLAGS}")
@@ -108,7 +107,12 @@
list(APPEND _ARGS "${_TRANSLATE_SRC_PATH}")
list(APPEND _ARGS "-o")
list(APPEND _ARGS "${_MODULE_FILE_NAME}")
- list(APPEND _ARGS "-iree-llvm-embedded-linker-path=\"${_EMBEDDED_LINKER_TOOL_EXECUTABLE}\"")
+
+ # If an LLVM CPU backend is enabled, supply the linker tool.
+ if(IREE_LLD_TARGET)
+ iree_get_executable_path(_EMBEDDED_LINKER_TOOL_EXECUTABLE "lld")
+ list(APPEND _ARGS "-iree-llvm-embedded-linker-path=\"${_EMBEDDED_LINKER_TOOL_EXECUTABLE}\"")
+ endif()
# Depending on the binary instead of the target here given we might not have
# a target in this CMake invocation when cross-compiling.
diff --git a/build_tools/cmake/iree_check_test.cmake b/build_tools/cmake/iree_check_test.cmake
index 98b6ece..05d4f4a 100644
--- a/build_tools/cmake/iree_check_test.cmake
+++ b/build_tools/cmake/iree_check_test.cmake
@@ -178,6 +178,8 @@
"${_RUNNER_TARGET}"
)
+ add_dependencies(iree-test-deps "${_NAME}")
+
iree_native_test(
NAME
"${_RULE_NAME}"
diff --git a/build_tools/cmake/iree_cmake_options.cmake b/build_tools/cmake/iree_cmake_options.cmake
new file mode 100644
index 0000000..0240cef
--- /dev/null
+++ b/build_tools/cmake/iree_cmake_options.cmake
@@ -0,0 +1,41 @@
+# Copyright 2022 The IREE Authors
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+include(CMakeDependentOption)
+
+#-------------------------------------------------------------------------------
+# Core options that may need to be configured in a containing scope when
+# including IREE as a sub-project (otherwise, they are just inline in the
+# main CMakeLists.txt).
+#-------------------------------------------------------------------------------
+
+macro(iree_set_compiler_cmake_options)
+ # These options are also set up in the main CMakeLists (for readability),
+ # but are included here for maximum compatibility with CMP0126 for the
+ # external case (i.e. need to ensure that a cache var is defined before
+ # use as a local).
+ option(IREE_BUILD_COMPILER "Builds the IREE compiler." ON)
+ option(IREE_BUILD_PYTHON_BINDINGS "Builds the IREE python bindings" OFF)
+
+ option(IREE_TARGET_BACKEND_DEFAULTS
+ "Sets the default value for all compiler target backends" ON)
+
+ # The VMVX backend is always enabled.
+ cmake_dependent_option(IREE_TARGET_BACKEND_VMVX "Enables the 'vmvx' compiler target backend" ON ${IREE_BUILD_COMPILER} OFF)
+
+ # Supported default target backends.
+ cmake_dependent_option(IREE_TARGET_BACKEND_DYLIB_LLVM_AOT "Enables the 'dylib-llvm-aot' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF)
+ cmake_dependent_option(IREE_TARGET_BACKEND_METAL_SPIRV "Enables the 'metal-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF)
+ cmake_dependent_option(IREE_TARGET_BACKEND_WASM_LLVM_AOT "Enables the 'wasm-llvm-aot' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF)
+ cmake_dependent_option(IREE_TARGET_BACKEND_VULKAN_SPIRV "Enables the 'vulkan-spirv' compiler target backend" ${IREE_TARGET_BACKEND_DEFAULTS} ${IREE_BUILD_COMPILER} OFF)
+
+ # Non-default target backends either have additional dependencies or are
+ # experimental/niche in some fashion.
+ cmake_dependent_option(IREE_TARGET_BACKEND_CUDA "Enables the 'cuda' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF)
+ cmake_dependent_option(IREE_TARGET_BACKEND_ROCM "Enables the 'rocm' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF)
+ # Disable WebGPU by default - it has complex deps and is under development.
+ cmake_dependent_option(IREE_TARGET_BACKEND_WEBGPU "Enables the 'webgpu' compiler target backend" OFF ${IREE_BUILD_COMPILER} OFF)
+endmacro()
diff --git a/build_tools/cmake/iree_external_cmake_options.cmake b/build_tools/cmake/iree_external_cmake_options.cmake
new file mode 100644
index 0000000..62fdcf4
--- /dev/null
+++ b/build_tools/cmake/iree_external_cmake_options.cmake
@@ -0,0 +1,135 @@
+# Copyright 2021 The IREE Authors
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+#-------------------------------------------------------------------------------
+# Options affecting third-party libraries that IREE depends on.
+#-------------------------------------------------------------------------------
+
+macro(iree_set_benchmark_cmake_options)
+ set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
+ set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
+endmacro()
+
+macro(iree_set_cpuinfo_cmake_options)
+ set(CPUINFO_BUILD_TOOLS ON CACHE BOOL "" FORCE)
+
+ set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE)
+ set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE BOOL "" FORCE)
+ set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE BOOL "" FORCE)
+endmacro()
+
+macro(iree_set_googletest_cmake_options)
+ set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
+ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
+endmacro()
+
+macro(iree_set_llvm_cmake_options)
+ # When enabling an IREE CPU backend, automatically enable these targets.
+ set(IREE_DEFAULT_CPU_LLVM_TARGETS "X86;ARM;AArch64;RISCV"
+ CACHE STRING "Initialization value for default LLVM CPU targets.")
+
+ # These defaults are moderately important to us, but the user *can*
+ # override them (enabling some of these brings in deps that will conflict,
+ # so ymmv).
+ set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
+ set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
+ set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
+ set(LLVM_APPEND_VC_REV OFF CACHE BOOL "")
+ set(LLVM_ENABLE_IDE ON CACHE BOOL "")
+ set(LLVM_ENABLE_BINDINGS OFF CACHE BOOL "")
+
+ # LLVM defaults to building all targets. We always enable targets that we need
+ # as we need them, so default to none. The user can override this as needed,
+ # which is fine.
+ set(LLVM_TARGETS_TO_BUILD "" CACHE STRING "")
+
+ # We enable LLVM projects as needed. The user can override this.
+ set(LLVM_ENABLE_PROJECTS "" CACHE STRING "")
+ set(LLVM_EXTERNAL_PROJECTS "" CACHE STRING "")
+
+ # Default Python bindings to off (for all sub-projects).
+ set(MLIR_ENABLE_BINDINGS_PYTHON OFF CACHE BOOL "")
+ set(MHLO_ENABLE_BINDINGS_PYTHON OFF CACHE BOOL "")
+
+ # If we are building LLD, this will be the target. Otherwise, empty.
+ set(IREE_LLD_TARGET)
+
+ # Unconditionally enable mlir.
+ list(APPEND LLVM_ENABLE_PROJECTS mlir)
+
+ # Configure LLVM based on enabled IREE target backends.
+ message(STATUS "IREE compiler target backends:")
+ if(IREE_TARGET_BACKEND_CUDA)
+ message(STATUS " - cuda")
+ list(APPEND LLVM_TARGETS_TO_BUILD NVPTX)
+ endif()
+ if(IREE_TARGET_BACKEND_DYLIB_LLVM_AOT)
+ message(STATUS " - dylib-llvm-aot")
+ list(APPEND LLVM_TARGETS_TO_BUILD "${IREE_DEFAULT_CPU_LLVM_TARGETS}")
+ set(IREE_LLD_TARGET lld)
+ endif()
+ if(IREE_TARGET_BACKEND_WASM_LLVM_AOT)
+ message(STATUS " - wasm-llvm-aot")
+ list(APPEND LLVM_TARGETS_TO_BUILD WebAssembly)
+ set(IREE_LLD_TARGET lld)
+ endif()
+ if(IREE_TARGET_BACKEND_METAL_SPIRV)
+ message(STATUS " - metal-spirv")
+ endif()
+ if(IREE_TARGET_BACKEND_ROCM)
+ message(STATUS " - rocm")
+ list(APPEND LLVM_TARGETS_TO_BUILD AMDGPU)
+ endif()
+ if(IREE_TARGET_BACKEND_VULKAN_SPIRV)
+ message(STATUS " - vulkan-spirv")
+ endif()
+ if(IREE_TARGET_BACKEND_VMVX)
+ message(STATUS " - vmvx")
+ endif()
+ if(IREE_TARGET_BACKEND_WEBGPU)
+ message(STATUS " - webgpu")
+ endif()
+
+ if(IREE_LLD_TARGET)
+ list(APPEND LLVM_ENABLE_PROJECTS lld)
+ endif()
+
+ list(REMOVE_DUPLICATES LLVM_ENABLE_PROJECTS)
+ list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
+ message(VERBOSE "Building LLVM Targets: ${LLVM_TARGETS_TO_BUILD}")
+ message(VERBOSE "Building LLVM Projects: ${LLVM_ENABLE_PROJECTS}")
+endmacro()
+
+macro(iree_add_llvm_external_project name identifier location)
+ message(STATUS "Adding LLVM external project ${name} (${identifier}) -> ${location}")
+ if(NOT EXISTS "${location}/CMakeLists.txt")
+ message(FATAL_ERROR "External project location ${location} is not valid")
+ endif()
+ list(APPEND LLVM_EXTERNAL_PROJECTS ${name})
+ list(REMOVE_DUPLICATES LLVM_EXTERNAL_PROJECTS)
+ set(LLVM_EXTERNAL_${identifier}_SOURCE_DIR ${location})
+endmacro()
+
+macro(iree_set_spirv_headers_cmake_options)
+ set(SPIRV_HEADERS_SKIP_EXAMPLES ON CACHE BOOL "" FORCE)
+ set(SPIRV_HEADERS_SKIP_INSTALL ON CACHE BOOL "" FORCE)
+endmacro()
+
+macro(iree_set_spirv_cross_cmake_options)
+ set(SPIRV_CROSS_ENABLE_MSL ON CACHE BOOL "" FORCE)
+ set(SPIRV_CROSS_ENABLE_GLSL ON CACHE BOOL "" FORCE) # Required to enable MSL
+
+ set(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS OFF CACHE BOOL "" FORCE)
+ set(SPIRV_CROSS_CLI OFF CACHE BOOL "" FORCE)
+ set(SPIRV_CROSS_ENABLE_TESTS OFF CACHE BOOL "" FORCE)
+ set(SPIRV_CROSS_SKIP_INSTALL ON CACHE BOOL "" FORCE)
+
+ set(SPIRV_CROSS_ENABLE_HLSL OFF CACHE BOOL "" FORCE)
+ set(SPIRV_CROSS_ENABLE_CPP OFF CACHE BOOL "" FORCE)
+ set(SPIRV_CROSS_ENABLE_REFLECT OFF CACHE BOOL "" FORCE)
+ set(SPIRV_CROSS_ENABLE_C_API OFF CACHE BOOL "" FORCE)
+ set(SPIRV_CROSS_ENABLE_UTIL OFF CACHE BOOL "" FORCE)
+endmacro()
diff --git a/build_tools/cmake/iree_third_party_cmake_options.cmake b/build_tools/cmake/iree_third_party_cmake_options.cmake
deleted file mode 100644
index c148839..0000000
--- a/build_tools/cmake/iree_third_party_cmake_options.cmake
+++ /dev/null
@@ -1,70 +0,0 @@
-# Copyright 2021 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-macro(iree_set_benchmark_cmake_options)
- set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
- set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
-endmacro()
-
-macro(iree_set_cpuinfo_cmake_options)
- set(CPUINFO_BUILD_TOOLS ON CACHE BOOL "" FORCE)
-
- set(CPUINFO_BUILD_BENCHMARKS OFF CACHE BOOL "" FORCE)
- set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE BOOL "" FORCE)
- set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE BOOL "" FORCE)
-endmacro()
-
-macro(iree_set_googletest_cmake_options)
- set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
- set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
-endmacro()
-
-macro(iree_set_llvm_cmake_options)
- set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "" FORCE)
- set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "" FORCE)
- set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "" FORCE)
- set(LLVM_APPEND_VC_REV OFF CACHE BOOL "" FORCE)
- set(LLVM_ENABLE_IDE ON CACHE BOOL "" FORCE)
-
- # TODO(ataei): Use optional build time targets selection for LLVMAOT.
- set(LLVM_TARGETS_TO_BUILD "WebAssembly;X86;ARM;AArch64;RISCV;NVPTX;AMDGPU"
- CACHE STRING "" FORCE)
-
- set(LLVM_ENABLE_PROJECTS "mlir;lld" CACHE STRING "" FORCE)
- set(LLVM_ENABLE_BINDINGS OFF CACHE BOOL "" FORCE)
-endmacro()
-
-macro(iree_add_llvm_external_project name identifier location)
- message(STATUS "Adding LLVM external project ${name} (${identifier}) -> ${location}")
- if(NOT EXISTS "${location}/CMakeLists.txt")
- message(FATAL_ERROR "External project location ${location} is not valid")
- endif()
- list(APPEND LLVM_EXTERNAL_PROJECTS ${name})
- list(REMOVE_DUPLICATES LLVM_EXTERNAL_PROJECTS)
- set(LLVM_EXTERNAL_${identifier}_SOURCE_DIR ${location} CACHE STRING "" FORCE)
- set(LLVM_EXTERNAL_PROJECTS ${LLVM_EXTERNAL_PROJECTS} CACHE STRING "" FORCE)
-endmacro()
-
-macro(iree_set_spirv_headers_cmake_options)
- set(SPIRV_HEADERS_SKIP_EXAMPLES ON CACHE BOOL "" FORCE)
- set(SPIRV_HEADERS_SKIP_INSTALL ON CACHE BOOL "" FORCE)
-endmacro()
-
-macro(iree_set_spirv_cross_cmake_options)
- set(SPIRV_CROSS_ENABLE_MSL ON CACHE BOOL "" FORCE)
- set(SPIRV_CROSS_ENABLE_GLSL ON CACHE BOOL "" FORCE) # Required to enable MSL
-
- set(SPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS OFF CACHE BOOL "" FORCE)
- set(SPIRV_CROSS_CLI OFF CACHE BOOL "" FORCE)
- set(SPIRV_CROSS_ENABLE_TESTS OFF CACHE BOOL "" FORCE)
- set(SPIRV_CROSS_SKIP_INSTALL ON CACHE BOOL "" FORCE)
-
- set(SPIRV_CROSS_ENABLE_HLSL OFF CACHE BOOL "" FORCE)
- set(SPIRV_CROSS_ENABLE_CPP OFF CACHE BOOL "" FORCE)
- set(SPIRV_CROSS_ENABLE_REFLECT OFF CACHE BOOL "" FORCE)
- set(SPIRV_CROSS_ENABLE_C_API OFF CACHE BOOL "" FORCE)
- set(SPIRV_CROSS_ENABLE_UTIL OFF CACHE BOOL "" FORCE)
-endmacro()
diff --git a/build_tools/cmake/iree_trace_runner_test.cmake b/build_tools/cmake/iree_trace_runner_test.cmake
index c0c732d..1160fa6 100644
--- a/build_tools/cmake/iree_trace_runner_test.cmake
+++ b/build_tools/cmake/iree_trace_runner_test.cmake
@@ -96,6 +96,8 @@
"${_RULE_TRACE_RUNNER}"
)
+ add_dependencies(iree-test-deps "${_NAME}")
+
iree_native_test(
NAME
"${_RULE_NAME}"
diff --git a/build_tools/cmake/rebuild.sh b/build_tools/cmake/rebuild.sh
index 0851c39..b7cf349 100755
--- a/build_tools/cmake/rebuild.sh
+++ b/build_tools/cmake/rebuild.sh
@@ -51,4 +51,10 @@
)
"$CMAKE_BIN" "${CMAKE_ARGS[@]?}" "$@" ..
+echo "Building all"
+echo "------------"
"$CMAKE_BIN" --build . -- -k 0
+
+echo "Building test deps"
+echo "------------------"
+"$CMAKE_BIN" --build . --target iree-test-deps -- -k 0
diff --git a/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader-asan/build.sh b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader-asan/build.sh
index fccc505..bba10b3 100755
--- a/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader-asan/build.sh
+++ b/build_tools/kokoro/gcp_ubuntu/cmake/linux/x86-swiftshader-asan/build.sh
@@ -41,9 +41,14 @@
echo "Configuring CMake"
"${CMAKE_BIN?}" "${CMAKE_ARGS[@]?}"
-echo "Building with CMake"
+echo "Building all"
+echo "------------"
"${CMAKE_BIN?}" --build "${CMAKE_BUILD_DIR?}" -- -k 0
+echo "Building test deps"
+echo "------------------"
+"${CMAKE_BIN?}" --build "${CMAKE_BUILD_DIR?}" --target iree-test-deps -- -k 0
+
# Respect the user setting, but default to as many jobs as we have cores.
export CTEST_PARALLEL_LEVEL=${CTEST_PARALLEL_LEVEL:-$(nproc)}
diff --git a/iree/compiler/Dialect/HAL/Target/LLVM/BUILD b/iree/compiler/Dialect/HAL/Target/LLVM/BUILD
index 7755e97..790fc66 100644
--- a/iree/compiler/Dialect/HAL/Target/LLVM/BUILD
+++ b/iree/compiler/Dialect/HAL/Target/LLVM/BUILD
@@ -57,6 +57,7 @@
"@llvm-project//llvm:WebAssemblyCodeGen",
"@llvm-project//llvm:X86AsmParser",
"@llvm-project//llvm:X86CodeGen",
+ "@llvm-project//llvm:config",
"@llvm-project//mlir:ArmNeon",
"@llvm-project//mlir:LLVMDialect",
"@llvm-project//mlir:LLVMToLLVMIRTranslation",
diff --git a/iree/compiler/Dialect/HAL/Target/LLVM/CMakeLists.txt b/iree/compiler/Dialect/HAL/Target/LLVM/CMakeLists.txt
index d73ca81..acd2759 100644
--- a/iree/compiler/Dialect/HAL/Target/LLVM/CMakeLists.txt
+++ b/iree/compiler/Dialect/HAL/Target/LLVM/CMakeLists.txt
@@ -28,21 +28,12 @@
::LLVMTargetOptions
::LinkerTool
::StaticLibraryGenerator
- LLVMAArch64AsmParser
- LLVMAArch64CodeGen
- LLVMARMAsmParser
- LLVMARMCodeGen
+ IREELLVMCPUTargetDeps
LLVMBitReader
LLVMBitWriter
LLVMCore
LLVMLinker
- LLVMRISCVAsmParser
- LLVMRISCVCodeGen
LLVMSupport
- LLVMWebAssemblyAsmParser
- LLVMWebAssemblyCodeGen
- LLVMX86AsmParser
- LLVMX86CodeGen
MLIRArmNeon
MLIRLLVMIR
MLIRLLVMToLLVMIRTranslation
@@ -131,3 +122,22 @@
)
### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###
+
+add_library(IREELLVMCPUTargetDeps INTERFACE)
+
+function(_add_optional_llvm_dep dep)
+ if(TARGET ${dep})
+ target_link_libraries(IREELLVMCPUTargetDeps INTERFACE ${dep})
+ endif()
+endfunction()
+
+_add_optional_llvm_dep(LLVMAArch64AsmParser)
+_add_optional_llvm_dep(LLVMAArch64CodeGen)
+_add_optional_llvm_dep(LLVMARMAsmParser)
+_add_optional_llvm_dep(LLVMARMCodeGen)
+_add_optional_llvm_dep(LLVMRISCVAsmParser)
+_add_optional_llvm_dep(LLVMRISCVCodeGen)
+_add_optional_llvm_dep(LLVMWebAssemblyAsmParser)
+_add_optional_llvm_dep(LLVMWebAssemblyCodeGen)
+_add_optional_llvm_dep(LLVMX86AsmParser)
+_add_optional_llvm_dep(LLVMX86CodeGen)
diff --git a/iree/compiler/Dialect/HAL/Target/LLVM/LLVMAOTTarget.cpp b/iree/compiler/Dialect/HAL/Target/LLVM/LLVMAOTTarget.cpp
index 0d927e2..685f9f3 100644
--- a/iree/compiler/Dialect/HAL/Target/LLVM/LLVMAOTTarget.cpp
+++ b/iree/compiler/Dialect/HAL/Target/LLVM/LLVMAOTTarget.cpp
@@ -728,19 +728,51 @@
std::function<LLVMTargetOptions()> queryOptions) {
getLLVMTargetOptionsFromFlags();
-#define INIT_LLVM_TARGET(TargetName) \
+// Dynamically do preprocessor dispatch to initialize only targets that we
+// care about if they are enabled. Unfortunately, the way the LLVM macros
+// for this are set up and the inability to do a conditional within a macro
+// means that we have to syntactically have a macro for every possible
+// target we care about. There are more robust ways to do this but they all
+// require build support, which is a pain to manage across platforms.
+//
+// See comments below.
+#define LLVM_INITIALIZE_GENERIC(TargetName) \
LLVMInitialize##TargetName##Target(); \
LLVMInitialize##TargetName##TargetMC(); \
LLVMInitialize##TargetName##TargetInfo(); \
LLVMInitialize##TargetName##AsmPrinter(); \
LLVMInitialize##TargetName##AsmParser();
+// CPU targets that we care about and have hard-linked against are here.
+// They delegate to the generic initialize above. These must all be added
+// to the build file or you will get undefined symbol errors at link time.
+#define LLVM_INITIALIZE_TARGET_AArch64() LLVM_INITIALIZE_GENERIC(AArch64)
+#define LLVM_INITIALIZE_TARGET_ARM() LLVM_INITIALIZE_GENERIC(ARM)
+#define LLVM_INITIALIZE_TARGET_RISCV() LLVM_INITIALIZE_GENERIC(RISCV)
+#define LLVM_INITIALIZE_TARGET_X86() LLVM_INITIALIZE_GENERIC(X86)
+#define LLVM_INITIALIZE_TARGET_WebAssembly() \
+ LLVM_INITIALIZE_GENERIC(WebAssembly)
+
+// We must no-op the name of each target we don't care about. This is annoying,
+// but targets aren't created every day and isn't the end of the world. The
+// error messages when missing are quite clear and you just add a line here.
+#define LLVM_INITIALIZE_TARGET_AMDGPU()
+#define LLVM_INITIALIZE_TARGET_AVR()
+#define LLVM_INITIALIZE_TARGET_BPF()
+#define LLVM_INITIALIZE_TARGET_Hexagon()
+#define LLVM_INITIALIZE_TARGET_Lanai()
+#define LLVM_INITIALIZE_TARGET_Mips()
+#define LLVM_INITIALIZE_TARGET_MSP430()
+#define LLVM_INITIALIZE_TARGET_NVPTX()
+#define LLVM_INITIALIZE_TARGET_PowerPC()
+#define LLVM_INITIALIZE_TARGET_Sparc()
+#define LLVM_INITIALIZE_TARGET_SystemZ()
+#define LLVM_INITIALIZE_TARGET_XCore()
+
+#define LLVM_TARGET(TargetName) LLVM_INITIALIZE_TARGET_##TargetName()
+#include "llvm/Config/Targets.def"
+
auto backendFactory = [=]() {
- INIT_LLVM_TARGET(X86)
- INIT_LLVM_TARGET(ARM)
- INIT_LLVM_TARGET(AArch64)
- INIT_LLVM_TARGET(RISCV)
- INIT_LLVM_TARGET(WebAssembly)
return std::make_shared<LLVMAOTTargetBackend>(queryOptions());
};
@@ -753,8 +785,6 @@
static TargetBackendRegistration registration2("dylib", backendFactory);
static TargetBackendRegistration registration3("dylib-llvm-aot",
backendFactory);
-
-#undef INIT_LLVM_TARGET
}
} // namespace HAL
diff --git a/iree/compiler/Dialect/HAL/Target/LLVM/test/CMakeLists.txt b/iree/compiler/Dialect/HAL/Target/LLVM/test/CMakeLists.txt
index 896553f..23b72bf 100644
--- a/iree/compiler/Dialect/HAL/Target/LLVM/test/CMakeLists.txt
+++ b/iree/compiler/Dialect/HAL/Target/LLVM/test/CMakeLists.txt
@@ -16,9 +16,9 @@
SRCS
"smoketest.mlir"
TOOLS
+ ${IREE_LLD_TARGET}
FileCheck
iree::tools::iree-opt
- lld
)
### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###
diff --git a/iree/test/e2e/models/CMakeLists.txt b/iree/test/e2e/models/CMakeLists.txt
index a15eb09..9856ced 100644
--- a/iree/test/e2e/models/CMakeLists.txt
+++ b/iree/test/e2e/models/CMakeLists.txt
@@ -22,9 +22,9 @@
"resnet50_fake_weights.mlir"
"unidirectional_lstm.mlir"
TOOLS
+ ${IREE_LLD_TARGET}
FileCheck
iree::tools::iree-run-mlir
- lld
LABELS
"hostonly"
"optonly"
diff --git a/iree/test/e2e/regression/CMakeLists.txt b/iree/test/e2e/regression/CMakeLists.txt
index 9ce4339..bdefe12 100644
--- a/iree/test/e2e/regression/CMakeLists.txt
+++ b/iree/test/e2e/regression/CMakeLists.txt
@@ -21,10 +21,10 @@
"trace_dispatch_tensors.mlir"
"unused_args.mlir"
TOOLS
+ ${IREE_LLD_TARGET}
FileCheck
iree::tools::iree-opt
iree::tools::iree-run-mlir
- lld
LABELS
"hostonly"
)
diff --git a/iree/tools/CMakeLists.txt b/iree/tools/CMakeLists.txt
index 2aa9a67..6e8defb 100644
--- a/iree/tools/CMakeLists.txt
+++ b/iree/tools/CMakeLists.txt
@@ -12,6 +12,17 @@
return()
endif()
+# Depending on which target backends are enabled, we may or may not have built
+# LLD.
+if(IREE_LLD_TARGET)
+ # lld install - required by the compiler to link codegen executables.
+ install(
+ TARGETS lld
+ COMPONENT Compiler
+ RUNTIME DESTINATION bin
+ )
+endif()
+
add_subdirectory(android)
add_subdirectory(test)
add_subdirectory(utils)
@@ -403,7 +414,7 @@
DEPS
::iree_translate_lib
DATA
- lld
+ ${IREE_LLD_TARGET}
HOSTONLY
)
@@ -413,7 +424,7 @@
DEPS
::iree_opt_main
DATA
- lld
+ ${IREE_LLD_TARGET}
HOSTONLY
)
@@ -461,7 +472,7 @@
iree::vm::bytecode_module
iree::vm::cc
DATA
- lld
+ ${IREE_LLD_TARGET}
HOSTONLY
)
@@ -471,13 +482,6 @@
# below, which we use for cross-platform testing.
set_target_properties(FileCheck PROPERTIES EXCLUDE_FROM_ALL OFF)
- # lld install - required by the compiler to link codegen executables.
- install(
- TARGETS lld
- COMPONENT Compiler
- RUNTIME DESTINATION bin
- )
-
# Bundle the FileCheck binary from LLVM into our tests/bin directory so
# installed FileCheck tests are hermetic.
install(
diff --git a/iree/tools/test/CMakeLists.txt b/iree/tools/test/CMakeLists.txt
index c37ec3f..57ef3b3 100644
--- a/iree/tools/test/CMakeLists.txt
+++ b/iree/tools/test/CMakeLists.txt
@@ -22,12 +22,12 @@
"repeated_return.mlir"
"scalars.mlir"
TOOLS
+ ${IREE_LLD_TARGET}
FileCheck
iree::tools::iree-benchmark-module
iree::tools::iree-run-mlir
iree::tools::iree-run-module
iree::tools::iree-translate
- lld
LABELS
"hostonly"
)
diff --git a/llvm-external-projects/iree-compiler-api/CMakeLists.txt b/llvm-external-projects/iree-compiler-api/CMakeLists.txt
index 749e4c7..3a37ec7 100644
--- a/llvm-external-projects/iree-compiler-api/CMakeLists.txt
+++ b/llvm-external-projects/iree-compiler-api/CMakeLists.txt
@@ -3,7 +3,7 @@
# that make up the IREE compiler input surface area. As a standalone
# project intended for direct distribution, it hard-codes a number of important
# CMake settings for producing optimal binaries and packages.
-cmake_minimum_required(VERSION 3.16.3)
+cmake_minimum_required(VERSION 3.17...3.22)
if(POLICY CMP0068)
cmake_policy(SET CMP0068 NEW)
@@ -66,10 +66,11 @@
set(MLIR_MAIN_BINARY_DIR "${LLVM_MAIN_BINARY_DIR}/tools/mlir")
# Configuration includes.
-include(${IREE_SOURCE_DIR}/build_tools/cmake/iree_third_party_cmake_options.cmake)
+include(${IREE_SOURCE_DIR}/build_tools/cmake/iree_cmake_options.cmake)
+include(${IREE_SOURCE_DIR}/build_tools/cmake/iree_external_cmake_options.cmake)
# CMake settings.
-set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
+set(BUILD_SHARED_LIBS OFF)
set(CMAKE_PLATFORM_NO_VERSIONED_SONAME ON)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
set(CMAKE_C_VISIBILITY_PRESET "hidden")
@@ -119,29 +120,19 @@
# Include IREE and LLVM if building standalone.
if(IREE_COMPILER_API_STANDALONE)
- # Required MLIR settings.
- # TODO: We require an ordering of mlir-dependent external projects to be
- # loaded after mlir. We take advantage of the lexical ordering here by
- # prefixing, which feels gross but is stable. Investigate a better mechanism
- # upstream.
+ iree_set_compiler_cmake_options()
iree_set_llvm_cmake_options()
iree_add_llvm_external_project(mlir-iree-dialects MLIR_IREE_DIALECTS ${LLVM_EXTERNAL_MLIR_IREE_DIALECTS_SOURCE_DIR})
iree_add_llvm_external_project(mlir-hlo MLIR_HLO ${LLVM_EXTERNAL_MLIR_HLO_SOURCE_DIR})
- set(MLIR_ENABLE_BINDINGS_PYTHON ON CACHE BOOL "" FORCE)
- set(MLIR_BINDINGS_PYTHON_LOCK_VERSION OFF CACHE BOOL "" FORCE)
- # TODO: Conflicting gtest.
- set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "" FORCE)
- # TODO: Conflicting benchmark.
- set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "" FORCE)
+ set(MLIR_ENABLE_BINDINGS_PYTHON ON)
# Required mlir-hlo settings.
# TODO: Consider removing this upstream and just using the main
# MLIR_ENABLE_BINDINGS_PYTHON option.
- set(MHLO_ENABLE_BINDINGS_PYTHON ON CACHE BOOL "" FORCE)
+ set(MHLO_ENABLE_BINDINGS_PYTHON ON)
# Required IREE settings.
- set(IREE_BUILD_PYTHON_BINDINGS ON CACHE BOOL "" FORCE)
- set(IREE_BUILD_OLD_PYTHON_COMPILER_API OFF CACHE BOOL "" FORCE)
+ set(IREE_BUILD_PYTHON_BINDINGS ON)
# Include LLVM.
message(STATUS "Configuring LLVM from (${LLVM_MAIN_SRC_DIR} into ${LLVM_MAIN_BINARY_DIR})...")
diff --git a/llvm-external-projects/iree-compiler-api/build_tools/build_intree.sh b/llvm-external-projects/iree-compiler-api/build_tools/build_intree.sh
deleted file mode 100755
index 362dde9..0000000
--- a/llvm-external-projects/iree-compiler-api/build_tools/build_intree.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash
-# Copyright 2021 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-# Simple script that does a CMake configure and build of the project.
-# This is meant for CI's and project maintainers.
-
-set -eu -o errtrace
-
-project_dir="$(cd $(dirname $0)/.. && pwd)"
-workspace_dir="$project_dir/../.."
-build_dir="$project_dir/build"
-
-# Write out a .env file to the workspace.
-echo "PYTHONPATH=$build_dir/python_package:$build_dir/iree/bindings/python" > $workspace_dir/.env
-
-cmake -GNinja -B"$build_dir" "$project_dir" \
- -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache \
- -DCMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld \
- -DCMAKE_SHARED_LINKER_FLAGS=-fuse-ld=lld \
- -DCMAKE_MODULE_LINKER_FLAGS=-fuse-ld=lld \
- -DLLVM_OPTIMIZED_TABLEGEN=ON \
- "$@"
-
-cd $build_dir
-ninja all iree/bindings/python/all
diff --git a/llvm-external-projects/iree-compiler-api/build_tools/build_python_wheels.sh b/llvm-external-projects/iree-compiler-api/build_tools/build_python_wheels.sh
index 4f10a01..65e76d7 100755
--- a/llvm-external-projects/iree-compiler-api/build_tools/build_python_wheels.sh
+++ b/llvm-external-projects/iree-compiler-api/build_tools/build_python_wheels.sh
@@ -28,7 +28,6 @@
export CMAKE_GENERATOR=Ninja
fi
$PYTHON -m pip wheel "${repo_root}" \
- --use-feature=in-tree-build \
-w "$wheelhouse" -v
echo "---- INSTALLING iree-compiler ----"
diff --git a/llvm-external-projects/iree-compiler-api/lib/CAPI/CMakeLists.txt b/llvm-external-projects/iree-compiler-api/lib/CAPI/CMakeLists.txt
index 6e5d29b..4226ead 100644
--- a/llvm-external-projects/iree-compiler-api/lib/CAPI/CMakeLists.txt
+++ b/llvm-external-projects/iree-compiler-api/lib/CAPI/CMakeLists.txt
@@ -1,7 +1,24 @@
+# LLD may not have been enabled at the global level (typically because we
+# are not building for a CPU backend). If not, don't add API support for it.
+set(_OPTIONAL_SOURCES)
+set(_OPTIONAL_LINK_LIBS)
+if(TARGET lld)
+ list(APPEND _OPTIONAL_SOURCES Lld.cpp)
+ list(APPEND _OPTIONAL_LINK_LIBS
+ lldCommon
+ lldCOFF
+ lldELF
+ lldMachO
+ lldMinGW
+ lldWasm
+ )
+endif()
+
add_mlir_public_c_api_library(IREECompilerAPICompilerCAPI
Compiler.cpp
- Lld.cpp
Tools.cpp
+ ${_OPTIONAL_SOURCES}
+ PARTIAL_SOURCES_INTENDED
# TODO: If installing, complains about IREEVM not being in any export set.
DISABLE_INSTALL
LINK_COMPONENTS
@@ -20,13 +37,7 @@
# Tools.
iree::tools::iree_translate_lib
- # LLD.
- lldCommon
- lldCOFF
- lldELF
- lldMachO
- lldMinGW
- lldWasm
+ ${_OPTIONAL_LINK_LIBS}
)
# TODO: Fix upstream so there is a way to know what the actual compile target
diff --git a/llvm-external-projects/iree-compiler-api/python/CMakeLists.txt b/llvm-external-projects/iree-compiler-api/python/CMakeLists.txt
index 4bec0be..c2f00d0 100644
--- a/llvm-external-projects/iree-compiler-api/python/CMakeLists.txt
+++ b/llvm-external-projects/iree-compiler-api/python/CMakeLists.txt
@@ -132,9 +132,11 @@
IREECTool.c
)
-add_iree_compiler_busybox_tool(
- IREECompilerLldTool
- OUTPUT_NAME iree-lld
- SRCS
- LldTool.c
-)
+if(TARGET lld)
+ add_iree_compiler_busybox_tool(
+ IREECompilerLldTool
+ OUTPUT_NAME iree-lld
+ SRCS
+ LldTool.c
+ )
+endif()