Skip to content

Rename IREE_HOST_BINARY_ROOT to IREE_TOOLS_INSTALL. - #11441

Closed
ScottTodd wants to merge 3 commits into
iree-org:mainfrom
ScottTodd:host-binary-root
Closed

ScottTodd wants to merge 3 commits into
iree-org:mainfrom
ScottTodd:host-binary-root

Conversation

@ScottTodd

Copy link
Copy Markdown
Member

Progress on #4662, depends on #11439

The expected path is the root of the install directory:

iree-build/
    install/ <-- this directory
        bin/    <-- not this directory ("binaries")
        lib/    <-- not this directory ("libraries")
        ...
        tests/

This also adds some documentation on the new variable in the root CMakeLists file. I'm also considering importing all binaries and libraries from the provided install directory, as a way to replace the current iree_get_executable_path() and associated code for cross compilation in our test functions (see #11402 (review)).

@ScottTodd ScottTodd added infrastructure Relating to build systems, CI, or testing cleanup 🧹 labels Dec 6, 2022
@benvanik

benvanik commented Dec 6, 2022

Copy link
Copy Markdown
Collaborator

Maybe we still want to have HOST in this name? (IREE_HOST_TOOLS_INSTALL or something)
Making it explicit that this is intended to be the host tools install instead of target tools install would help avoid confusion and match common naming of this kind of thing.

@ScottTodd

Copy link
Copy Markdown
Member Author

Maybe we still want to have HOST in this name? (IREE_HOST_TOOLS_INSTALL or something) Making it explicit that this is intended to be the host tools install instead of target tools install would help avoid confusion and match common naming of this kind of thing.

Note that you can use this even when not cross compiling, so there doesn't need to be a "host" vs "target" distinction in the build. This setting should be a mechanism to use some tools from an existing build rather than building them from source. The real distinction we're making is compiler + other host tools (iree-compile, iree-tblgen, c_embed_data) vs runtime tools (iree-run-module, iree-benchmark-module). The directory points to the full "host" install, including iree-run-module and other runtime tools, but CMake should not use those runtime tools from the install.

Naming ideas:

  • IREE_TOOLS_INSTALL
  • IREE_HOST_TOOLS_INSTALL
  • IREE_COMPILER_TOOLS_INSTALL

@benvanik

benvanik commented Dec 6, 2022

Copy link
Copy Markdown
Collaborator

The use of this is for the build host binaries, so that iree-run-module exists in an install is orthogonal as iree-run-module should not be used by the build host.

I think INSTALL may be the wrong word as it's kind of tying this to a cmake install of something. If it's really just a directory of the tools required by the host to build then "IREE_HOST_TOOLS_PATH" or something seems appropriate. A user shouldn't need to build iree-run-module/etc for this and instead just the tools a build host needs to complete an IREE target build. That a cmake install produces a superset of the requirements feels incidental - a user may want to build/ship just what's required for their bot to cross-compile.

Maybe the root problem being addressed could be satisfied with a cmake helper for verifying that a path has all the required host tools (iree-opt, iree-compile, etc) - that may let us give the right error messages and such without enforcing the workflow ("you pointed us at foo/ but that doesn't have tool X" etc).

(just riffing, not sure exactly what's trying to be solved with the changes - I just worried it may be changing one misnamed thing to another :)

@ScottTodd

Copy link
Copy Markdown
Member Author

The impetus for this bit of work was #11331 and how cross compilation is complicating that. We don't just have a folder of binaries now - we have bin/ and lib/.

Linux:

lib/
    libIREEcompiler.so
bin/
    iree-compile
    iree-opt

Windows:

lib/
    IREEcompiler.lib
bin/
    IREEcompiler.dll
    iree-compile.exe
    iree-opt.exe

I'm trying to unwind some of the complexity that has grown in our CMake files while also cleanly supporting the new dynamic linking modes for our tools.

@benvanik

benvanik commented Dec 6, 2022

Copy link
Copy Markdown
Collaborator

I'm a bit scared by that - the bin/lib split is arbitrary and we really don't want to be requiring that - we should only require the executables to exist and not anything about the directory structure containing them. Nearly always these kind of executable path flags just point at bin dirs such that you can interchangeably use them with PATH. Is there a reason we need to know the lib dir exists at all?

@benvanik

benvanik commented Dec 6, 2022

Copy link
Copy Markdown
Collaborator

(restating what you're trying to do may be useful - I'm still unclear - having a helper cmake var that given an install path sets up other more fundamental vars seems ok; it's letting the install concept proliferate around the codebase that's sketching me out)

@ScottTodd

Copy link
Copy Markdown
Member Author

restating what you're trying to do may be useful

A bunch of things, each orthogonal but useful together:

@benvanik

benvanik commented Dec 6, 2022

Copy link
Copy Markdown
Collaborator

yeah as you say those things should be orthogonal to this var and if they are intersecting then there's probably some undesirable conflation happening that we should fix instead of just renaming :)

The place where we point to find the executables used for the build host tools shouldn't require a cmake install to have ever been performed (or cmake to have been used at all for the tools build), shouldn't be platform dependent, shouldn't have anything to do with cmake deps, and shouldn't relate to how the tool executables are linked (statically or dynamically). If anything differs based on any of those aspects we've got the var wrong and not just the naming.

Whatever we do with the var should be something compatible with what we will do with vcpkg, pip, custom user directory mixins (bring your own compiler build), bazel builds/etc, and what we'll want to do with find_program/find_package. cmake installs and such may feed into those but we don't want to couple our cross-compiling builds with any one particular host tool acquisition mechanism.

If we can decouple every other thing you're doing from this var renaming maybe we can think of a better name as I'm not sure what's being done here is it - maybe defer this until after all the other changes/fixes land and we can re-evaluate? I think we're doing tomato/tomatoe tradeoffs when really this is a burrito :)

@benvanik

benvanik commented Dec 6, 2022

Copy link
Copy Markdown
Collaborator

(to be clear I think fixing this var is really important, just not sure that renaming is helping and may just be cementing the current badness - I'm fine if the churn is deemed worth it to others in the short term but would like to fix it so we don't have to think about it again instead)

@ScottTodd

Copy link
Copy Markdown
Member Author

Maybe we should rename to

  • IREE_HOST_TOOLS
  • IREE_HOST_BINARIES
  • IREE_HOST_BINARY_INSTALL

or keep the IREE_HOST_BINARY_ROOT name, then change it to mean the bin/ directory.

I can stop searching the lib/ path on Linux for libIREECompiler.so, as long as changes to IREE compiler code affect iree-compile (they don't on Windows, where changes are only reflected in IREECompiler.dll). The important thing there is to set up a dependency relationship between the installed tools (including their shared libraries) and generated targets. I thought about ways to inspect the executables/binaries and list their runtime deps (e.g. dumpbin on Windows), but I don't see a way to make that portable across platforms / shell environments / etc.

@benvanik

benvanik commented Dec 7, 2022

Copy link
Copy Markdown
Collaborator

I think you're still circling around workarounds to an issue that shouldn't exist - we really should not be requiring anything of the executables like this - if you're needing to in cmake specify lib dirs and stuff things have already gone off the rails.

@benvanik

benvanik commented Dec 7, 2022

Copy link
Copy Markdown
Collaborator

(that is to say if a user can't launch an executable from the bin dir with an arbitrary cwd without doing anything extra then our build/install is wrong, and we shouldn't work around that in cmake consuming those same executables in a way a user would)

@ScottTodd

Copy link
Copy Markdown
Member Author

I'm not working around something broken in just launching/running executables. What I've been debugging on #11331 and proposing fixes for in #11402 is how on Windows with shared libraries, changes to compiler code do not trigger rebuilding generated targets. That's because iree-comple.exe does not change whenever compiler code changes - only IREECompiler.dll changes. We don't have that problem on Linux - code changes do update iree-compile (and libIREECompiler.so).

I have a fix for that (add a DEPENDS on an imported library that references install/bin/IREECompiler.dll), but I want to simplify it, which requires also simplifying how we import prebuilt binaries. That simplification will be easier if we first clarify how we want this CMake variable to behave.

@benvanik

benvanik commented Dec 7, 2022

Copy link
Copy Markdown
Collaborator

I think we're going in circles (which is probably my fault - sorry!) - let's chat in the morning :)

@ScottTodd

Copy link
Copy Markdown
Member Author

Whatever we do with the var should be something compatible with what we will do with vcpkg, pip, custom user directory mixins (bring your own compiler build), bazel builds/etc, and what we'll want to do with find_program/find_package. cmake installs and such may feed into those but we don't want to couple our cross-compiling builds with any one particular host tool acquisition mechanism.

BTW yes, completely agree with this :)

ScottTodd added a commit that referenced this pull request Jan 12, 2023
…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)
@ScottTodd ScottTodd closed this in de426de Jan 13, 2023
@ScottTodd
ScottTodd deleted the host-binary-root branch January 13, 2023 22:22
jpienaar pushed a commit that referenced this pull request May 1, 2023
…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)
jpienaar pushed a commit that referenced this pull request May 1, 2023
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup 🧹 infrastructure Relating to build systems, CI, or testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants