[Build] `re2` not compiled when statically building with `onnxruntime_BUILD_UNIT_TESTS=OFF`
Describe the issue
I have compiled onnxruntime with the following command (on linux):
./build.sh --cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF --config Release --parallel --compile_no_warning_as_error --skip_submodule_sync --update --build --build_dir build/linux
When linking this to a rust library (via ort), there seems to be an issue where, if the flag --cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF is given, re2 isn't compiled (only when building a static library, apparently, it gets built when building the shared library).
Urgency
No response
Target platform
Linux x86_64
Build script
./build.sh --cmake_extra_defines=onnxruntime_BUILD_UNIT_TESTS=OFF --config Release --parallel --compile_no_warning_as_error --skip_submodule_sync --update --build --build_dir build/linux
Error / output
There is no error at build time, linking downstream fails as described above.
Visual Studio Version
No response
GCC / Compiler Version
No response
I just checked https://github.com/microsoft/onnxruntime/blob/main/cmake/external/onnxruntime_external_deps.cmake, re2 doesn't seem to be optional. It should always get built. Sorry I have no idea how it would happen.
Do you have more logs? Can you set FETCHCONTENT_TRY_FIND_PACKAGE_MODE to NEVER?
@snnn Setting FETCHCONTENT_TRY_FIND_PACKAGE_MODE to NEVER seemingly didn't change anything. I also double checked that libre2.a simply doesn't exist when I disable tests. In fact, the entire re2-build directory is missing.
Here is the entire build log of the original command I posted.
Here is the entire build log of the original command I posted without disabling tests.
Looking at the explicit dependencies, re2 is only an explicit dependency for test related packages, not onnxruntime directly.
Can you reproduce the issue?
I tried the command on Linux(sorry I don't have a Mac machine). It did not have any problem. I noticed that you didn't generate a dynamic onnxruntime lib. So, your application needs to link to all onnxruntime's internal libraries and their dependencies(including re2). That's a lot. And since you disabled all executable binaries and all *.dylib targets, there is no link stage. Nothing needs be linked. Therefore re2 even won't get built. This is expected.
Could you consider using vcpkg? https://github.com/microsoft/onnxruntime/pull/21348. If vcpkg works, then it can help build all the dependencies and ensure ORT and your app using the dependency versions.