Repository navigation
Description
Background
#4584 removed our custom CMake cross compilation code, which was implicitly compiling host tools (iree-translate, generate_cc_embed_data, iree-tblgen, etc.) used for the target build. Now a host build must be performed explicitly, or a binary distribution must be used.
One unfortunate consequence of this is that runtime-only builds for the Java bindings (and likely TFLite bindings too) still require at least the flatcc cli tool for compiling our schema flatbuffer files using the flatbuffer_c_library build helpers.
In general, trying to build all required tools and artifacts for a given user application in a single build step seems like a fool's errand, particularly when the application requires cross compilation. On the other end of the spectrum, requiring users to precisely build different parts of a project using different build systems (CMake host -> CMake target -> Gradle) will just lead to difficulty integrating.
flatcc
While we can build the CLI program for the target by adjusting these settings:
https://github.com/google/iree/blob/a66ff82b03006a4fdd646075eaceb4240eaf909c/build_tools/third_party/flatcc/CMakeLists.txt#L58-L62
https://github.com/google/iree/blob/a66ff82b03006a4fdd646075eaceb4240eaf909c/build_tools/cmake/iree_copts.cmake#L379-L383
https://github.com/google/iree/blob/a66ff82b03006a4fdd646075eaceb4240eaf909c/build_tools/cmake/flatbuffer_c_library.cmake#L98
we can't (at least as far as I'm aware) invoke the target program (e.g. an Android/Linux binary) on the host (e.g. a Windows machine) during a build step.
Solutions
I think for third party tools we could use FIND_PROGRAM() (if installed) and/or vcpkg to help with finding host tools and not building them ourselves. For in-tree tools like generate_cc_embed_data I think our only options are:
- Our own binary distributions
- An explicit host build (CMake invocation + path setup)
- An implicit host build (the magic we had before)
- Check in generated files where possible (like with this tablegen'd file)
Hopefully this mostly affects IREE developers only, since in the case of Android we can publish AAR files and users can skip all this CMake stuff :P. Maybe that's the answer to this? We could write a script to invoke CMake twice and generate an AAR using https://docs.gradle.org/current/userguide/command_line_interface.html then use that in any of our Android samples.
cc @KoolJBlack , @not-jenni
Activity
stellaraccident commentedon Jan 27, 2021
Also breaking the releases: https://github.com/google/iree/runs/1772766160?check_suite_focus=true
stellaraccident commentedon Jan 27, 2021
I'm reworking that now and will just enable building the compiler for the runtime package, but it's pretty non-ideal.
benvanik commentedon Jan 27, 2021
I think it's fine to require two build invocations - one for host and one for target - when building the runtime. The invocation that builds flatcc should take literally seconds at most and be done once, and as you say is something we can automate with vcpkg to hide it from most users. For a majority of people cross-compiling this is the kind of thing they need to do already (especially if they are using protobuf/flatbuffers/etc from source like we are, or pngcrush, or crunch, etc etc).
Falling back to PATH copies is a bit risky as there's no guarantee it'll match versions and won't work for something we build ourselves (like the embed data stuff), but flatcc isn't changing much so it's probably fine so long as it is a shared path with the vcpkg (not a big conditional cmake block that is only exercised in that one case).
benvanik commentedon Jan 27, 2021
(the alternative is that we check in binaries, which is the extreme of non-ideal - needing to invoke your compiler for each platform is something that comes with the territory of cross-compiling)
benvanik commentedon Jan 27, 2021
To clarify, the "flatbuffer compiler" not the "iree compiler" correct? We should literally only be issuing a cmake build for the
--target flatcc_cli.stellaraccident commentedon Jan 27, 2021
No - I think it is more broken than that. See the log: https://pipelines.actions.githubusercontent.com/SaXEyjchYvnWH9Rq3qeZEPLXtO1Hv1A8b0nd0VWR5igNiKNAhf/_apis/pipelines/1/runs/42323/signedlogcontent/9?urlExpires=2021-01-27T00%3A13%3A25.9225710Z&urlSigningMethod=HMACV1&urlSignature=wko37FpEfWFKj6bkDFYUGzckVMJC4bkXi%2BiQrh5Nd1A%3D
Some stuff getting hauled in and failing CMake configure:
With these options:
ScottTodd commentedon Jan 27, 2021
This is what we settled on as a workaround for right now in building the Java bindings
https://github.com/not-jenni/iree/blob/937ad5a9601becbd9dac3b6c0a7c6d3b2798feaf/experimental/bindings/java/build.gradle#L26-L42 (on #4608)
That's messy for developers and basically a non-starter for users :p
benvanik commentedon Jan 27, 2021
ok, sounds like there are a bunch of issues - but the end goal should be that if a user is building the runtime from source the only host targets they need to build are flatcc_cli and the embed data binary (and maybe iree-dump-module & co, which are runtime data tools). We can have an install target for that so there's just one cmake build to do, and we can have vcpkg do that automatically when installing iree[runtime-tools] or whatnot.
stellaraccident commentedon Jan 27, 2021
I "fixed" my problem by building with
-DIREE_BUILD_TESTS=OFF. Which then exposed another problem in that we have non-test depends on benchmark. Required a small patch to the top-level to configure benchmark regardless.benvanik commentedon Jan 27, 2021
It may be useful cleanup to split out IREE_BUILD_COMPILER_TESTS and IREE_BUILD_RUNTIME_TESTS - lit tests in the former, iree-check-module/etc in the former.
stellaraccident commentedon Jan 27, 2021
Yeah, next on my list.
Move release build steps to python (from yaml).
Move release build steps to python (from yaml).
Move release build steps to python (from yaml).
Move release build steps to python (from yaml). (#4618)
ScottTodd commentedon Jan 27, 2021
I think two things got conflated here.
IREE's runtime (including tests), when built for any platform, should not require compiler tools like
iree-translate. #4627 should fix that.IREE's runtime, when built for any platform, may still require host tools like flatcc's CLI and
generate_cc_embed_data.Skip check tests on host builds when IREE_BUILD_COMPILER is OFF. (#4627)
Add Gradle tasks to configure and make host tools with CMake before c…
ScottTodd commentedon Apr 27, 2022
I think this issue is stale/obsolete now. Host tools like
flatccandgenerate_c_embed_datacan still be required for runtime builds, and we have a reasonable separation between compiler and runtime tools/builds now. We also have a few functional examples of building for weirder platforms that are relatively stable (Android, RISC-V/bare-metal, Web/Emscripten).