Skip to content

Commit e72d792

Browse files
committed
Guard find_library(tensorflow_c_api ...) by checking for TENSORFLOW_C_LIB_PATH to be set by the user
Also have CMake fails if the user provides a TENSORFLOW_C_LIB_PATH but we can't find TensorFlow at this path. At the moment the CMake script tries to figure if TensorFlow is available on the system and enables support for it. This is in general not desirable to customize build features this way and instead it is preferable to let the user opt-in explicitly into the features they want to enable. This is in line with other optional external dependencies like Z3. There are a few reasons to this but amongst others: - reproducibility: making features "magically" enabled based on whether we find a package on the system or not makes it harder to handle bug reports from users. - user control: they can't have TensorFlow on the system and build LLVM without TensorFlow right now. They also would suddenly distribute LLVM with a different set of features unknowingly just because their build machine environment would change subtly. Right now this is motivated by a user reporting build failures on their system: .../mesa-git/llvm-git/src/llvm-project/llvm/lib/Analysis/TFUtils.cpp:23:10: fatal error: tensorflow/c/c_api.h: No such file or directory 23 | #include "tensorflow/c/c_api.h" | ^~~~~~ It looks like we detected TensorFlow at configure time but couldn't set all the paths correctly. Differential Revision: https://reviews.llvm.org/D88371
1 parent e46d74b commit e72d792

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

llvm/CMakeLists.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,11 @@ configure_file(
829829
${LLVM_INCLUDE_DIR}/llvm/Config/Targets.def
830830
)
831831

832+
# They are not referenced. See set_output_directory().
833+
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
834+
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
835+
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
836+
832837
# For up-to-date instructions for installing the Tensorflow dependency, refer to
833838
# the bot setup script: https://github.com/google/ml-compiler-opt/blob/master/buildbot/buildbot_init.sh
834839
# In this case, the latest C API library is available for download from
@@ -837,18 +842,12 @@ configure_file(
837842
# LLVM_HAVE_TF_API, through llvm-config.h, so that a user of the LLVM library may
838843
# also leverage the dependency.
839844
set(TENSORFLOW_C_LIB_PATH "" CACHE PATH "Path to TensorFlow C library install")
840-
find_library(tensorflow_c_api tensorflow PATHS ${TENSORFLOW_C_LIB_PATH}/lib)
841-
842-
if (tensorflow_c_api)
845+
if (TENSORFLOW_C_LIB_PATH)
846+
find_library(tensorflow_c_api tensorflow PATHS ${TENSORFLOW_C_LIB_PATH}/lib NO_DEFAULT_PATH REQUIRED)
843847
set(LLVM_HAVE_TF_API "ON" CACHE BOOL "Full Tensorflow API available")
844848
include_directories(${TENSORFLOW_C_LIB_PATH}/include)
845849
endif()
846850

847-
# They are not referenced. See set_output_directory().
848-
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/bin )
849-
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
850-
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX} )
851-
852851
# For up-to-date instructions for installing the Tensorflow dependency, refer to
853852
# the bot setup script: https://github.com/google/ml-compiler-opt/blob/master/buildbot/buildbot_init.sh
854853
# Specifically, assuming python3 is installed:

0 commit comments

Comments
 (0)