Repository navigation
Conversation
This should work when cross compiling too now.
b5fc699 to
1193d4a
Compare
|
Ehhhh, this got sort of messy. It would be easier if changes to |
8ee0d3a to
6366215
Compare
ScottTodd
left a comment
There was a problem hiding this comment.
Tweaked a bit after a discussion with @stellaraccident:
I think rather than plumbing that through all of the macros and such, I'd rather arrange to just have an API2::RuntimeImpl target that was rigged correctly. And then add that as a dep to any tool which is sensitive to the implementation changing.
Each .cmake file still needs to include the dep - I can't just add it to the iree_cc_binary... unless I also make the change I'm thinking of in my other comment. We'd import each executable and at the same time set up their dependencies, then those functions would only need to depend on the imported targets.
| # Import the RuntimeImpl target when cross compiling. | ||
| # TODO(scotttodd): Refactor to import_shared_library/import_executable funcs? | ||
| set(_RUNTIME_IMPL_NAME "iree_compiler_API2_RuntimeImpl") | ||
| set(_RUNTIME_IMPL_ALIAS "iree::compiler::API2::RuntimeImpl") | ||
| if(TARGET "${_RUNTIME_IMPL_NAME}") | ||
| # Already defined, nothing to do. | ||
| elseif(DEFINED IREE_HOST_BINARY_ROOT) | ||
| # Import. | ||
| set(_FULL_LIBRARY_NAME "${CMAKE_SHARED_LIBRARY_PREFIX}IREECompiler${CMAKE_SHARED_LIBRARY_SUFFIX}") | ||
| set(_LIBRARY_BIN_PATH "${IREE_HOST_BINARY_ROOT}/bin/${_FULL_LIBRARY_NAME}") | ||
| set(_LIBRARY_LIB_PATH "${IREE_HOST_BINARY_ROOT}/lib/${_FULL_LIBRARY_NAME}") | ||
| if(EXISTS ${_LIBRARY_BIN_PATH}) | ||
| add_library("${_RUNTIME_IMPL_NAME}" SHARED IMPORTED GLOBAL) | ||
| set_property(TARGET "${_RUNTIME_IMPL_NAME}" PROPERTY IMPORTED_LOCATION "${_LIBRARY_BIN_PATH}") | ||
| add_library("${_RUNTIME_IMPL_ALIAS}" ALIAS "${_RUNTIME_IMPL_NAME}") |
There was a problem hiding this comment.
We could consider replacing the iree_get_executable_path implementation with this as well.
If IREE_HOST_BINARY_ROOT (I can rename this to IREE_HOST_INSTALL_ROOT) is set, we'd import iree-compile and the other binary targets. We could then have a single place that imports all targets (shared libraries and executables) from that install path.
There was a problem hiding this comment.
What if we move the logic for building from source vs using prebuilt from all the targets using installable artifacts to the producers of them instead. So anything that uses iree-compile can depend on the target and trust that everything Just Works:tm:. I think all the logic can be in iree_cc_binary (we currently install all binaries, though I think we should probably stop doing that, since some are just random tests). To support the shared libraries, the binary would need to inspect its dependencies to see if they're shared, and if so add a dep on the appropriate file. Ah or rather than that (which sounds like a lot of introspection) it can just keep deps if they're a shared library and iree_cc_library can do similar logic to look up its prebuilt version if it's shared. WDYT? I think something like that would work pretty well.
There was a problem hiding this comment.
Yeah, I have something like this in mind, but my brain is fried from all this CMake work - I might pick it up later.
if(IREE_BUILD_COMPILER)
iree_cc_binary(iree-compile ...)
iree_cc_binary(iree-opt ...)
elseif(IREE_HOST_BINARY_ROOT)
# add IMPORTED libraries/binaries
iree_import_binary(iree-compile
SHARED_LIBRARY_DEPS
IREECompiler
)
iree_import_binary(iree-opt
SHARED_LIBRARY_DEPS
IREECompiler
)
else()
# skip defining iree-compile and other targets
endif()
# elsewhere just use the iree-compile target, ask it for TARGET_FILE using generator expressions, etc.There was a problem hiding this comment.
(SHARED_LIBRARY_DEPS IREECompiler there could then also be imported with iree_import_shared_library to the iree::compiler::API2::Impl name, or something similar enough)
| DEPS | ||
| ::SharedImpl | ||
| ) | ||
| add_library("iree_compiler_API2_RuntimeImpl" ALIAS "iree_compiler_API2_SharedImpl") |
There was a problem hiding this comment.
I don't understand why this needs two names
…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)
…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)
Fixes #11331 (not sure if there's a more natural fix, but this works...). See also #11285.
When I change compiler code on Windows and build
iree-test-deps, I just seeIREECompiler.dlllinking:On Linux, I see both
libIREECompiler.so.0andtools/iree-compilelinking, which then rebuilds generated files:This adds an explicit dependency on
iree::compiler::API2::SharedImpl(or an imported target when cross compiling) to theadd_custom_command()iniree_bytecode_module()(and related functions), so compiler changes correctly trigger rebuilding generated files on Windows.