onnxruntime icon indicating copy to clipboard operation
onnxruntime copied to clipboard

[Build] `re2` not compiled when statically building with `onnxruntime_BUILD_UNIT_TESTS=OFF`

Open cyanic-selkie opened this issue 1 year ago • 3 comments

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

cyanic-selkie avatar Oct 19 '24 19:10 cyanic-selkie

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.

snnn avatar Oct 21 '24 01:10 snnn

Do you have more logs? Can you set FETCHCONTENT_TRY_FIND_PACKAGE_MODE to NEVER?

snnn avatar Oct 21 '24 01:10 snnn

@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.

notests_build.log

Here is the entire build log of the original command I posted without disabling tests.

tests_build.log

Looking at the explicit dependencies, re2 is only an explicit dependency for test related packages, not onnxruntime directly.

Can you reproduce the issue?

cyanic-selkie avatar Oct 21 '24 06:10 cyanic-selkie

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.

snnn avatar Oct 22 '24 02:10 snnn

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.

snnn avatar Oct 22 '24 02:10 snnn