diff --git a/dev/vcpkg/env.sh b/dev/vcpkg/env.sh index 91aaa6a7d267..009e9faba2ac 100755 --- a/dev/vcpkg/env.sh +++ b/dev/vcpkg/env.sh @@ -7,25 +7,34 @@ if [ -z "${BASH_SOURCE[0]}" ] || [ "$0" == "${BASH_SOURCE[0]}" ]; then fi SCRIPT_ROOT="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" -init_vcpkg_env=$("${SCRIPT_ROOT}/init.sh" $@) -eval "$init_vcpkg_env" export VCPKG_ROOT="$SCRIPT_ROOT/.vcpkg" export VCPKG="$SCRIPT_ROOT/.vcpkg/vcpkg" export VCPKG_TRIPLET=x64-linux-avx export VCPKG_TRIPLET_INSTALL_DIR=${SCRIPT_ROOT}/vcpkg_installed/${VCPKG_TRIPLET} -export EXPORT_TOOLS_PATH="${VCPKG_TRIPLET_INSTALL_DIR}/tools/protobuf" -if [ "\${GLUTEN_VCPKG_ENABLED:-}" != "${VCPKG_ROOT}" ]; then +${SCRIPT_ROOT}/init.sh "$@" + +if [ "${GLUTEN_VCPKG_ENABLED:-}" != "${VCPKG_ROOT}" ]; then + EXPORT_TOOLS_PATH="${VCPKG_TRIPLET_INSTALL_DIR}/tools/protobuf" + # The scripts depends on environment $CMAKE_TOOLCHAIN_FILE, which requires + # cmake >= 3.21. If system cmake < 3.25, vcpkg will download latest cmake. We + # can use vcpkg's internal cmake if we find it. + VCPKG_CMAKE_BIN_DIR=$(echo "${VCPKG_ROOT}"/downloads/tools/cmake-*/cmake-*/bin) + if [ -f "$VCPKG_CMAKE_BIN_DIR/cmake" ]; then + EXPORT_TOOLS_PATH="${VCPKG_CMAKE_BIN_DIR}:${EXPORT_TOOLS_PATH}" + fi + EXPORT_TOOLS_PATH=${EXPORT_TOOLS_PATH/%:/} + export VCPKG_ROOT=${VCPKG_ROOT} export VCPKG_MANIFEST_DIR=${SCRIPT_ROOT} export VCPKG_TRIPLET=${VCPKG_TRIPLET} export CMAKE_TOOLCHAIN_FILE=${SCRIPT_ROOT}/toolchain.cmake - export PKG_CONFIG_PATH=${VCPKG_TRIPLET_INSTALL_DIR}/lib/pkgconfig:${VCPKG_TRIPLET_INSTALL_DIR}/share/pkgconfig:\${PKG_CONFIG_PATH:-} + export PKG_CONFIG_PATH=${VCPKG_TRIPLET_INSTALL_DIR}/lib/pkgconfig:${VCPKG_TRIPLET_INSTALL_DIR}/share/pkgconfig:${PKG_CONFIG_PATH:-} export PATH="${EXPORT_TOOLS_PATH}:$PATH" export GLUTEN_VCPKG_ENABLED=${VCPKG_ROOT} else - echo "Gluten's vcpkg environment is enabled" >&2 + echo "Gluten's vcpkg environment is already enabled" >&2 fi diff --git a/dev/vcpkg/init.sh b/dev/vcpkg/init.sh index 9beaa19526fe..bae1a8ad32eb 100755 --- a/dev/vcpkg/init.sh +++ b/dev/vcpkg/init.sh @@ -2,8 +2,6 @@ set -e -exec 3>&1 >&2 - BUILD_TESTS=OFF ENABLE_S3=OFF ENABLE_GCS=OFF @@ -39,11 +37,19 @@ for arg in "$@"; do esac done -export SCRIPT_ROOT="$(realpath "$(dirname "$0")")" -export VCPKG_ROOT="$SCRIPT_ROOT/.vcpkg" -export VCPKG="$SCRIPT_ROOT/.vcpkg/vcpkg" -VCPKG_TRIPLET=x64-linux-avx +require_set() { + if [ -z "${!1}" ]; then + echo "Required variable $1 not found!" + exit 1 + fi +} + +require_set "VCPKG_ROOT" +require_set "VCPKG" +require_set "VCPKG_TRIPLET" +require_set "VCPKG_TRIPLET_INSTALL_DIR" +SCRIPT_ROOT="$(realpath "$(dirname "$0")")" cd "$SCRIPT_ROOT" if [ ! -d "$VCPKG_ROOT" ] || [ -z "$(ls "$VCPKG_ROOT")" ]; then @@ -75,19 +81,6 @@ fi $VCPKG install --no-print-usage \ --triplet="${VCPKG_TRIPLET}" --host-triplet="${VCPKG_TRIPLET}" ${EXTRA_FEATURES} -export VCPKG_TRIPLET_INSTALL_DIR=${SCRIPT_ROOT}/vcpkg_installed/${VCPKG_TRIPLET} -EXPORT_TOOLS_PATH="${VCPKG_TRIPLET_INSTALL_DIR}/tools/protobuf" - -# This scripts depends on environment $CMAKE_TOOLCHAIN_FILE, which requires -# cmake >= 3.21. If system cmake < 3.25, vcpkg will download latest cmake. We -# can use vcpkg's internal cmake if we find it. -VCPKG_CMAKE_BIN_DIR=$(echo "${VCPKG_ROOT}"/downloads/tools/cmake-*/cmake-*/bin) -if [ -f "$VCPKG_CMAKE_BIN_DIR/cmake" ]; then - EXPORT_TOOLS_PATH="${VCPKG_CMAKE_BIN_DIR}:${EXPORT_TOOLS_PATH}" -fi - -export EXPORT_TOOLS_PATH=${EXPORT_TOOLS_PATH/%:/} - # For fixing a build error like below when gluten's build type is Debug: # No rule to make target '/root/gluten/dev/vcpkg/vcpkg_installed/x64-linux-avx/debug/lib/libz.a', # needed by 'releases/libvelox.so' diff --git a/dev/vcpkg/toolchain.cmake b/dev/vcpkg/toolchain.cmake index 21ff9090fb9e..10d156c1b040 100644 --- a/dev/vcpkg/toolchain.cmake +++ b/dev/vcpkg/toolchain.cmake @@ -3,11 +3,15 @@ set(ENABLE_GLUTEN_VCPKG ON) -# If this arg is set, `vcpkg install` will be executed according -# to the manifest file exists in this given path, i.e., vcpkg.json, -# which will not respect our setting for extra features through -# `--x-feature`. -#set(VCPKG_MANIFEST_DIR $ENV{VCPKG_MANIFEST_DIR}) +# Force the use of VCPKG classic mode to avoid reinstalling vcpkg features during +# different CMake sub-projects. Which means, the features installed by `vcpkg install` +# in script `init.sh` will be used across all CMake sub-projects. +# +# Reference: https://learn.microsoft.com/en-us/vcpkg/users/buildsystems/cmake-integration +# +# Note: "CACHE BOOL" is required to make this successfully override the option defined in +# vcpkg.cmake. +set(VCPKG_MANIFEST_MODE OFF CACHE BOOL "Use manifest mode, as opposed to classic mode." FORCE) set(VCPKG_TARGET_TRIPLET $ENV{VCPKG_TRIPLET}) set(VCPKG_HOST_TRIPLET $ENV{VCPKG_TRIPLET})