Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[shortfin][build] Improve dependency management for builds #132

Merged
merged 11 commits into from
Aug 22, 2024
117 changes: 102 additions & 15 deletions libshortfin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@ set(CMAKE_CXX_STANDARD 20)
# https://discourse.cmake.org/t/cmake-3-28-cmake-cxx-compiler-clang-scan-deps-notfound-not-found/9244/3
set(CMAKE_CXX_SCAN_FOR_MODULES 0)

# Problems with linking libfmt without PIC.
# Turn on PIC on non windows targets.
if(NOT WIN32)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

# build options
option(SHORTFIN_BUILD_PYTHON_BINDINGS "Builds Python Bindings" OFF)
option(SHORTFIN_BUILD_TESTS "Builds C++ tests" ON)
option(SHORTFIN_BUNDLE_DEPS "Download dependencies instead of using system libraries" OFF)
set(SHORTFIN_IREE_SOURCE_DIR "" CACHE FILEPATH "Path to IREE source")

if(SHORTFIN_BUILD_TESTS)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
include(GoogleTest)
enable_testing()
endif()
include(FetchContent)

# Includes.
list(APPEND CMAKE_MODULE_PATH
Expand All @@ -46,9 +44,98 @@ list(APPEND CMAKE_MODULE_PATH
include(shortfin_library)

# Dependencies.
find_package(spdlog)
find_package(xtensor)
find_package(IREERuntime)

if(SHORTFIN_BUNDLE_DEPS)
## fmt
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG e69e5f977d458f2650bb346dadf2ad30c5320281 # 10.2.1 (sync with spdlog)
)

## spdlog
# We build fmt from source instead, because we also use fmt.
set(SPDLOG_FMT_EXTERNAL ON)
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG 2d4acf8cc321d7783d8f2e22e17a794c6d0e9450 # v1.14.1
)

## xtl: required for xtensor
FetchContent_Declare(
xtl
GIT_REPOSITORY https://github.com/xtensor-stack/xtl.git
GIT_TAG a7c1c5444dfc57f76620391af4c94785ff82c8d6 # v0.7.7
)

## xtensor
FetchContent_Declare(
xtensor
GIT_REPOSITORY https://github.com/xtensor-stack/xtensor.git
GIT_TAG 3634f2ded19e0cf38208c8b86cea9e1d7c8e397d # v0.25.0
)

FetchContent_MakeAvailable(fmt spdlog xtl xtensor)
else()
find_package(spdlog)
find_package(xtensor)
endif()

## iree runtime

if (NOT SHORTFIN_IREE_SOURCE_DIR AND SHORTFIN_BUNDLE_DEPS)
FetchContent_Declare(
iree
GIT_REPOSITORY https://github.com/iree-org/iree.git
GIT_TAG candidate-20240821.992
# TODO: We shouldn't have to pull googletest when we are not building tests.
# This needs to be fixed with IREE.
GIT_SUBMODULES "third_party/benchmark third_party/cpuinfo third_party/flatcc third_party/hip-build-deps third_party/googletest"
Groverkss marked this conversation as resolved.
Show resolved Hide resolved
GIT_SHALLOW ON
marbre marked this conversation as resolved.
Show resolved Hide resolved
)
FetchContent_GetProperties(iree)
if(NOT iree_POPULATED)
FetchContent_Populate(iree)
Groverkss marked this conversation as resolved.
Show resolved Hide resolved
endif()
set(SHORTFIN_IREE_SOURCE_DIR ${iree_SOURCE_DIR})
endif()

if(SHORTFIN_IREE_SOURCE_DIR)
set(IREE_BUILD_COMPILER OFF)
set(IREE_BUILD_TESTS OFF)
set(IREE_BUILD_SAMPLES OFF)
# Disable missing submodules error because we are only building the runtime
Groverkss marked this conversation as resolved.
Show resolved Hide resolved
set(IREE_ERROR_ON_MISSING_SUBMODULES OFF)
# Only enable local_sync/local_task/hip drivers for now.
set(IREE_HAL_DRIVER_DEFAULTS OFF)
set(IREE_HAL_DRIVER_LOCAL_SYNC ON)
set(IREE_HAL_DRIVER_LOCAL_TASK ON)
set(IREE_HAL_DRIVER_HIP ON)
add_subdirectory(${SHORTFIN_IREE_SOURCE_DIR} shortfin_iree SYSTEM EXCLUDE_FROM_ALL)
marbre marked this conversation as resolved.
Show resolved Hide resolved
else()
# Try to find iree using find_package
find_package(IREERuntime)
endif()

# tests
Groverkss marked this conversation as resolved.
Show resolved Hide resolved

if(SHORTFIN_BUILD_TESTS)
if (NOT SHORTFIN_IREE_SOURCE_DIR)
# Due to the above mentioned bugged with IREE CMakeLists.txt, we reuse
# IREE's googletest.
Groverkss marked this conversation as resolved.
Show resolved Hide resolved
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
endif()
include(GoogleTest)
enable_testing()
Groverkss marked this conversation as resolved.
Show resolved Hide resolved
endif()


add_subdirectory(src)

Expand Down
Loading