Skip to content

Commit

Permalink
[VL] Minor follow-ups for #7052 (#7315)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhztheplayer authored Sep 24, 2024
1 parent 9a6aa2c commit f00e453
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
21 changes: 15 additions & 6 deletions dev/vcpkg/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 12 additions & 19 deletions dev/vcpkg/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

set -e

exec 3>&1 >&2

BUILD_TESTS=OFF
ENABLE_S3=OFF
ENABLE_GCS=OFF
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
14 changes: 9 additions & 5 deletions dev/vcpkg/toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit f00e453

Please sign in to comment.