Repository navigation
Replace CMake iree_get_executable_path() with IMPORTED targets. - #11764
Conversation
0647585 to
2102361
Compare
2102361 to
bd96907
Compare
GMNGeoffrey
left a comment
There was a problem hiding this comment.
I wonder if we should use find_program instead. It's very heuristic, but I think would cover cases like someone having pip installed the IREE tools. Maybe that's too magic though? It would also allow someone to set a standard CMake variable, like CMAKE_PROGRAM_PATH or CMAKE_PREFIX_PATH, although those say they are "intended to be set by the project", so maybe asking a user to set them isn't an appropriate usage.
| # executing that compiler. | ||
| if (NOT DEFINED IREE_HOST_BINARY_ROOT) | ||
| # executing `iree-compile --iree-hal-list-target-backends`. | ||
| if(NOT IREE_HOST_BINARY_ROOT) |
There was a problem hiding this comment.
I hope we can eventually kill this check also
There was a problem hiding this comment.
I was considering a configure step that would run iree-compile --iree-hal-list-target-backends, parse the output, then set the IREE_TARGET_BACKEND_* variables. Despite it being tricky to write that snippet of CMake code, I think the resulting behavior would fit pretty nicely into how we set up these rules.
| # TODO(scotttodd): Should this be checking IREE_BUILD_COMPILER? | ||
| # Maybe we should disallow setting both at the same time, since it's | ||
| # ambigious which should be used | ||
| if(IREE_HOST_BINARY_ROOT AND NOT IREE_BUILD_COMPILER) |
There was a problem hiding this comment.
Rather than putting this if condition in the CMakeLists.txt, can we put it in iree_cc_binary? That seems cleaner to me: any binary can be either installed/imported or built from source. That's a bit fiddly with the IREE_ENABLE_THREADING bit here though
There was a problem hiding this comment.
Could also be only added iff we mark a binary as "public", "exported", "import", or something like that. We could also use that to control installing and aliasing into a global namespace so that our test binaries don't do that
There was a problem hiding this comment.
That could simplify some of the CMake files further, but it feels a little too implicit to me.
- We still want to build runtime binaries like
iree-run-moduleusing the target configuration and I want that to be obvious from reading the files - I don't like the idea of having
iree::compiler::deps that aren't directly guarded byif(IREE_BUILD_COMPILER)
There was a problem hiding this comment.
Yeah I think the nice thing would be something like Bazel's configurations, where we say that we need iree-compile built in the host configuration. Anyway, that's too much for now
| iree_import_binary(NAME iree-tblgen) | ||
| iree_import_binary(NAME iree-compile) | ||
| iree_import_binary(NAME iree-opt) | ||
| iree_import_binary(NAME iree-run-mlir) |
There was a problem hiding this comment.
The IREE_ENABLE_THREADING check made the ordering in this file messier than I'd like, so this should not return. The runtime tools (like iree-benchmark-module) are defined right after the threading check.
| COMPONENT Tests | ||
| ) | ||
| endif(IREE_BUILD_COMPILER) | ||
| elseif(NOT IREE_HOST_BINARY_ROOT) |
There was a problem hiding this comment.
It seems a bit weird that this is here instead of being part of the same conditional block as checking IREE_HOST_BINARY_ROOT above
There was a problem hiding this comment.
You can also blame/thank IREE_ENABLE_THREADING for that.
Ordering is currently:
- Import compiler binaries if needed
- Return if threading is disabled
- Define runtime binaries
- Define compiler binaries
Also note that what we distribute through pip doesn't contain all of the tools (at least last I checked) that a source build needs. We'd need |
2e7bc17 to
9c42da2
Compare
9c42da2 to
868a03c
Compare
| # TODO(scotttodd): Should this be checking IREE_BUILD_COMPILER? | ||
| # Maybe we should disallow setting both at the same time, since it's | ||
| # ambigious which should be used | ||
| if(IREE_HOST_BINARY_ROOT AND NOT IREE_BUILD_COMPILER) |
There was a problem hiding this comment.
Yeah I think the nice thing would be something like Bazel's configurations, where we say that we need iree-compile built in the host configuration. Anyway, that's too much for now
…11812) The new variable is documented in the root CMakeLists.txt and is initialized from the (new deprecated) old variable. ``` iree-build/ # CMake build directory install/ # Set by -DCMAKE_INSTALL_PREFIX, IREE_HOST_BINARY_ROOT pointed here bin/ # IREE_HOST_BIN_DIR should point here lib/ src/ tests/ ``` Now we can also point to other binary distributions that don't have CMake's build/install structure. --- Closes #11441. Fixes #4662. This new variable approach was discussed on #11764 (comment). Co-authored-by: Geoffrey Martin-Noble <[email protected]>
…11764) This changes how to access host tools during CMake's configure step from using a custom `iree_get_executable_path()` function to using `IMPORTED` targets (https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html). A new helper `iree_import_binary` is added to keep `IREE_HOST_BINARY_ROOT` use centralized. ## Details Previously, each CMake file that wanted to use a tool that might be provided by either the current build or a "host install" would use the `iree_get_executable_path` function, e.g. ```cmake # tools/CMakeLists.txt if(IREE_BUILD_COMPILER) iree_cc_binary(NAME iree-compile ...) endif() # some other file iree_get_executable_path(_COMPILE_TOOL_EXECUTABLE "iree-compile") add_custom_command( OUTPUT ${_OUTPUT_FILES} COMMAND ${_COMPILE_TOOL_EXECUTABLE} ${_ARGS} DEPENDS ${_COMPILE_TOOL_EXECUTABLE} ${_SRC_PATH} ) ``` The `iree_get_executable_path` function attempted to find an executable with that name and would add an `IMPORTED` target if one did not already exist. We can simplify that to just defining `IMPORTED` targets directly, right where the targets are normally defined when `IREE_BUILD_COMPILER` is enabled (or `CMAKE_CROSSCOMPILING` is disabled). Importing targets where they are defined (rather than where they are used) will also let us more cleanly solve issues like #11331. Now this looks more like ```cmake # tools/CMakeLists.txt if(IREE_HOST_BINARY_ROOT AND NOT IREE_BUILD_COMPILER) iree_import_binary(NAME iree-compile) elseif(IREE_BUILD_COMPILER) iree_cc_binary(NAME iree-compile ...) else() # warn about not building or importing endif() # some other file - use the target without caring if it was imported or not add_custom_command( OUTPUT ${_OUTPUT_FILES} COMMAND iree-compile ${_ARGS} DEPENDS iree-compile ${_SRC_PATH} ) ``` ## Other context This is an alternate take on #11441 and was discussed a bit here: #11402 (comment). Future PRs may * Remove the implicit `bin/` suffix from `IREE_HOST_BINARY_ROOT` to decouple it from the CMake `install` process * Add `SHARED_LIBRARY_DEPS` to `iree_import_binary`, along with `iree_import_library`, for proper dependency modeling of IREECompiler.dll (assuming that `IMPORTED_RUNTIME_ARTIFACTS` doesn't already do what I want)
…11812) The new variable is documented in the root CMakeLists.txt and is initialized from the (new deprecated) old variable. ``` iree-build/ # CMake build directory install/ # Set by -DCMAKE_INSTALL_PREFIX, IREE_HOST_BINARY_ROOT pointed here bin/ # IREE_HOST_BIN_DIR should point here lib/ src/ tests/ ``` Now we can also point to other binary distributions that don't have CMake's build/install structure. --- Closes #11441. Fixes #4662. This new variable approach was discussed on #11764 (comment). Co-authored-by: Geoffrey Martin-Noble <[email protected]>
This changes how to access host tools during CMake's configure step from using a custom
iree_get_executable_path()function to usingIMPORTEDtargets (https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html). A new helperiree_import_binaryis added to keepIREE_HOST_BINARY_ROOTuse centralized.Details
Previously, each CMake file that wanted to use a tool that might be provided by either the current build or a "host install" would use the
iree_get_executable_pathfunction, e.g.The
iree_get_executable_pathfunction attempted to find an executable with that name and would add anIMPORTEDtarget if one did not already exist.We can simplify that to just defining
IMPORTEDtargets directly, right where the targets are normally defined whenIREE_BUILD_COMPILERis enabled (orCMAKE_CROSSCOMPILINGis disabled). Importing targets where they are defined (rather than where they are used) will also let us more cleanly solve issues like #11331.Now this looks more like
Other context
This is an alternate take on #11441 and was discussed a bit here: #11402 (comment).
Future PRs may
bin/suffix fromIREE_HOST_BINARY_ROOTto decouple it from the CMakeinstallprocessSHARED_LIBRARY_DEPStoiree_import_binary, along withiree_import_library, for proper dependency modeling of IREECompiler.dll (assuming thatIMPORTED_RUNTIME_ARTIFACTSdoesn't already do what I want)