Skip to content

Commit 44b67a8

Browse files
jackylee-chclaude
andcommitted
[VL] Unify native-build component isolation via a single resolver (macOS + Linux)
Native-build path policy was duplicated across three shell entry points (builddeps-veloxbe.sh, build-helper-functions.sh, build-velox.sh), each independently hardcoding `-DCMAKE_IGNORE_PREFIX_PATH=/usr/local` on macOS only. This left Linux without first-class isolation and, importantly, left Velox's own dependency builds (folly, bundled Arrow, ...) unprotected from /usr/local. Introduce dev/build-isolation.sh as a single source of truth. It normalizes all path inputs, decides isolation on/off, and emits a CMake toolchain fragment + path-policy.env + machine-readable resolved_{trusted,ignored,runtime_ignored}_roots under the already-gitignored ep/_ep working dir. Every build layer consumes them. Default behavior (user-facing contract): * macOS and Linux both default-on (GLUTEN_BUILD_ISOLATION=auto -> on); vcpkg forces off; explicit on+vcpkg fails fast (only one toolchain slot). * macOS default: local prefix ${VELOX_HOME}/deps-install; /usr/local ignored. * Linux default: setup still installs to system dirs (trusted-managed, Docker/CI behavior and artifact locations unchanged); only ambient residue (stray Conda, user CMake registry) is filtered -- effectively a no-op unless you opt into a separate install. * Either platform + explicit INSTALL_PREFIX (separate install): /usr/local and /usr flip to ignored, with GLUTEN_ALLOW_IGNORED_ROOTS / GLUTEN_TRUST_PREFIX escape hatches. GLUTEN_BUILD_ISOLATION=off is a full kill-switch. Two-level isolation: * CMake find policy: ignore roots + NO_SYSTEM_FROM_IMPORTED + package-registry off, propagated to every nested cmake (incl. Velox's own dependency setup) via the exported CMAKE_TOOLCHAIN_FILE. The toolchain carries only the ignore policy -- it does NOT prepend trusted prefixes globally, which would wrongly redirect Velox's/Arrow's self-contained bundled builds to deps-install. * Compiler include search: CMAKE_IGNORE_* doesn't govern the compiler, and on macOS clang searches /usr/local/include ahead of -isystem, so a stale header there (e.g. an old gtest/fmt) shadows the bundled copy. The resolver exports CFLAGS/CXXFLAGS with `-idirafter <ignored>/include` to demote those roots below every -I/-isystem dir; child cmake processes inherit it. build-arrow.sh: guard the destructive download-dir removal (never wipe a user-provided ARROW_PREFIX) and resolve a sane default install prefix for standalone runs instead of silently targeting /usr/local. Verified end-to-end by a complete native macOS build (arm64): valid libgluten.dylib + libvelox.dylib with zero /usr/local linkage (otool -L). The resolver supports GLUTEN_ISOLATION_DRYRUN=1 to emit the policy without building. Linux is a no-op by default, preserving existing Docker/CI behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 473a5d2 commit 44b67a8

5 files changed

Lines changed: 570 additions & 29 deletions

File tree

dev/build-arrow.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,30 @@ SUDO="${SUDO:-""}"
2222
source ${CURRENT_DIR}/build-helper-functions.sh
2323
VELOX_ARROW_BUILD_VERSION=15.0.0
2424
ARROW_PREFIX=$CURRENT_DIR/../ep/_ep/arrow_ep
25+
ARROW_MANAGED_PREFIX="$CURRENT_DIR/../ep/_ep/arrow_ep"
2526
BUILD_TYPE=Release
27+
# When invoked via builddeps-veloxbe.sh, INSTALL_PREFIX is already resolved and
28+
# exported (isolated local prefix on macOS, system on Linux) and is respected
29+
# here. For a standalone run, consult the isolation resolver so we do not
30+
# silently target /usr/local on an isolated platform.
31+
if [ -z "${INSTALL_PREFIX:-}" ] && [ -f "${CURRENT_DIR}/build-isolation.sh" ]; then
32+
source "${CURRENT_DIR}/build-isolation.sh"
33+
# Fatal on resolver rejection (e.g. isolation=on with vcpkg, or an invalid
34+
# mode): falling through would silently target /usr/local and mask the
35+
# misconfiguration. Consistent with the other native build entrypoints.
36+
resolve_build_isolation || exit 1
37+
fi
2638
INSTALL_PREFIX=${INSTALL_PREFIX:-"/usr/local"}
2739

2840
function prepare_arrow_build() {
29-
mkdir -p ${ARROW_PREFIX}/../ && pushd ${ARROW_PREFIX}/../ && ${SUDO} rm -rf arrow_ep/
41+
mkdir -p ${ARROW_PREFIX}/../ && pushd ${ARROW_PREFIX}/../
42+
# Only auto-remove Gluten's managed download dir; never wipe a user-provided
43+
# Arrow source tree pointed to by an overridden ARROW_PREFIX.
44+
if [ "${ARROW_PREFIX}" = "${ARROW_MANAGED_PREFIX}" ]; then
45+
${SUDO} rm -rf arrow_ep/
46+
else
47+
echo "INFO: ARROW_PREFIX=${ARROW_PREFIX} is user-provided; not auto-removing it." >&2
48+
fi
3049
wget_and_untar https://github.com/apache/arrow/archive/refs/tags/apache-arrow-${VELOX_ARROW_BUILD_VERSION}.tar.gz arrow_ep
3150
#wget_and_untar https://archive.apache.org/dist/arrow/arrow-${VELOX_ARROW_BUILD_VERSION}/apache-arrow-${VELOX_ARROW_BUILD_VERSION}.tar.gz arrow_ep
3251
cd arrow_ep

dev/build-helper-functions.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,18 @@ function cmake_install {
176176
CPU_TARGET="${CPU_TARGET:-unknown}"
177177
COMPILER_FLAGS=$(get_cxx_flags $CPU_TARGET)
178178

179-
local MACOS_ISOLATION_FLAGS=""
180-
if [[ "$(uname)" == "Darwin" ]]; then
181-
if [[ "${INSTALL_PREFIX:-}" == "/usr/local" || "${INSTALL_PREFIX:-}" == /usr/local/* ]]; then
182-
echo "INFO: INSTALL_PREFIX=${INSTALL_PREFIX} is under /usr/local; keeping /usr/local visible to CMake." >&2
183-
else
184-
MACOS_ISOLATION_FLAGS="-DCMAKE_NO_SYSTEM_FROM_IMPORTED=ON \
185-
-DCMAKE_IGNORE_PREFIX_PATH=/usr/local \
186-
-DCMAKE_IGNORE_PATH=/usr/local;/usr/local/include;/usr/local/lib;/usr/local/lib/cmake \
187-
-DCMAKE_SYSTEM_IGNORE_PATH=/usr/local;/usr/local/include;/usr/local/lib;/usr/local/lib/cmake"
188-
fi
179+
# Component isolation: a single resolver computes the ignore/prefix policy for
180+
# both macOS and Linux (dev/build-isolation.sh). macOS default reproduces the
181+
# previous /usr/local ignore flags; Linux default is a no-op; vcpkg disables it.
182+
local _gi="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/build-isolation.sh"
183+
local ISOLATION_FLAGS=""
184+
if [ -f "$_gi" ]; then
185+
source "$_gi"
186+
resolve_build_isolation || exit 1
187+
ISOLATION_FLAGS="${GLUTEN_ISOLATION_CMAKE_FLAGS:-}"
188+
# Demote ignored roots' /include below -I/-isystem so a stale /usr/local
189+
# header can't shadow bundled/deps-install headers (compiler isolation).
190+
COMPILER_FLAGS="$COMPILER_FLAGS ${GLUTEN_ISOLATION_CXXFLAGS:-}"
189191
fi
190192

191193
# CMAKE_POSITION_INDEPENDENT_CODE is required so that Velox can be built into dynamic libraries \
@@ -197,7 +199,7 @@ function cmake_install {
197199
"${INSTALL_PREFIX+-DCMAKE_INSTALL_PREFIX=}${INSTALL_PREFIX-}" \
198200
-DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" \
199201
-DBUILD_TESTING=OFF \
200-
$MACOS_ISOLATION_FLAGS \
202+
$ISOLATION_FLAGS \
201203
"$@"
202204

203205
cmake --build "${BINARY_DIR}"

0 commit comments

Comments
 (0)