You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Compiler tool dynamic linking may not be setting CMake dependencies completely #11331
I'm noticing that when I make changes to compiler code and rebuild iree-test-deps, the .vmfb test files are not regenerated. I think we're missing a dependency link between IREECompiler.dll (.so on Linux) and iree-compile.exe. The iree_check_test targets depend on the compiler tool here:
# DANGER: iree_cc_library links its deps with PUBLIC scope, which causes
# usage requirements to propagate from dependents to users of the shared
# library. The shared library is intended to be used as an isolated boundary
# for C consumers. Therefore, we depend on the backing static library with
# PRIVATE scope explicitly here vs using a DEPS above. This kind of "boundary
# shared library" seems to be the only place this happens, so we special
# case vs generalizing.
target_link_libraries(
iree_compiler_API2_SharedImpl
PRIVATE
iree_compiler_API2_StaticImpl
)
I don't quite follow that comment (and why a "boundary shared library" is useful within the build system). @stellaraccident ?
I can restore the expected behavior (changing the compiler rebuilds iree-test-deps) by either flipping that to PUBLIC or by inserting a dep on iree::compiler::API2::StaticImpl here (though other places may similarly be "broken"):
The goal of the library is to have one dynamic library that all consumers dynamically link against. If you add the static library as PUBLIC then all consumers will also statically link against everything. If you look in your build dir you should see either 50KB for iree-compile/iree-opt/etc + the 400MB (debug) compiler binary if dynamically linking or iree-compile/iree-opt/etc all at 400MB if statically linking.
There should be a straight-line dep here: code -> static library -> shared library -> tools -> test artifacts. The thing to investigate is where that breaks down as code changes should propagate all the way through: code changes, static library picks up those code changes, shared library picks up the static library changes, tools pick up the shared library changes, etc.
Maybe there's something special to get a shared library to invalidate dependent targets? Seems like something we could try to reproduce standalone to see if we're holding cmake right.
(By "inserting a dep on iree::compiler::API2::StaticImpl" I mean to DEPENDS in add_custom_command, which is just for computing when to rebuild - not actually adding any new linking)
Libraries and targets following PUBLIC are linked to, and are made part of the link interface. Libraries and targets following PRIVATE are linked to, but are not made part of the link interface
# DANGER: iree_cc_library links its deps with PUBLIC scope, which causes
# usage requirements to propagate from dependents to users of the shared
# library. The shared library is intended to be used as an isolated boundary
# for C consumers. Therefore, we depend on the backing static library with
# PRIVATE scope explicitly here vs using a DEPS above. This kind of "boundary
# shared library" seems to be the only place this happens, so we special
# case vs generalizing.
target_link_libraries(
iree_compiler_API2_SharedImpl
PRIVATE
iree_compiler_API2_StaticImpl
)
I don't quite follow that comment (and why a "boundary shared library" is useful within the build system). @stellaraccident ?
I can restore the expected behavior (changing the compiler rebuilds iree-test-deps) by either flipping that to PUBLIC or by inserting a dep on iree::compiler::API2::StaticImpl here (though other places may similarly be "broken"):
# Changes to either the compiler tool or the input sources should rebuild.
DEPENDS
${_COMPILE_TOOL_EXECUTABLE}
${_LINKER_TOOL_EXECUTABLE}
${_RULE_SRC}
${_RULE_DEPENDS}
If you link as public, then the compile options get inherited, which is not what you want for such a C API. I discovered it because the flags to disable exceptions were being added to all dependents when linked public.
I didn't notice the vmfb deps not rebuilding (I could have sworn they were for me). Adding it as a depends should be fine.
Activity
ScottTodd commentedon Nov 29, 2022
I think the
PRIVATElinkage here is the problem:iree/compiler/src/iree/compiler/API2/CMakeLists.txt
Lines 76 to 87 in e36ce11
I don't quite follow that comment (and why a "boundary shared library" is useful within the build system). @stellaraccident ?
I can restore the expected behavior (changing the compiler rebuilds
iree-test-deps) by either flipping that toPUBLICor by inserting a dep oniree::compiler::API2::StaticImplhere (though other places may similarly be "broken"):iree/build_tools/cmake/iree_bytecode_module.cmake
Lines 131 to 136 in e36ce11
benvanik commentedon Nov 29, 2022
The goal of the library is to have one dynamic library that all consumers dynamically link against. If you add the static library as PUBLIC then all consumers will also statically link against everything. If you look in your build dir you should see either 50KB for iree-compile/iree-opt/etc + the 400MB (debug) compiler binary if dynamically linking or iree-compile/iree-opt/etc all at 400MB if statically linking.
There should be a straight-line dep here: code -> static library -> shared library -> tools -> test artifacts. The thing to investigate is where that breaks down as code changes should propagate all the way through: code changes, static library picks up those code changes, shared library picks up the static library changes, tools pick up the shared library changes, etc.
Maybe there's something special to get a shared library to invalidate dependent targets? Seems like something we could try to reproduce standalone to see if we're holding cmake right.
ScottTodd commentedon Nov 29, 2022
(By "inserting a dep on
iree::compiler::API2::StaticImpl" I mean toDEPENDSinadd_custom_command, which is just for computing when to rebuild - not actually adding any new linking)RE:
PUBLICvsPRIVATE, https://cmake.org/cmake/help/latest/command/target_link_libraries.html:stellaraccident commentedon Nov 30, 2022
If you link as public, then the compile options get inherited, which is not what you want for such a C API. I discovered it because the flags to disable exceptions were being added to all dependents when linked public.
I didn't notice the vmfb deps not rebuilding (I could have sworn they were for me). Adding it as a depends should be fine.
This was a bit of a head scratcher...
ScottTodd commentedon Nov 30, 2022
Just tested on Linux, and I do see them rebuilding correctly with no changes. This might be Windows specific...
ScottTodd commentedon Nov 30, 2022
I'm not on my Windows machine right now to test, but maybe we could flip this
PRIVATEtoPUBLIC(looking for what's different on Windows vs Linux):iree/build_tools/cmake/iree_cc_library.cmake
Lines 110 to 115 in da5b7f7
Replace CMake `iree_get_executable_path()` with `IMPORTED` targets. (#…
Replace CMake `iree_get_executable_path()` with `IMPORTED` targets. (#…