Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
330 changes: 330 additions & 0 deletions .github/workflows/try-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
name: Try Build

run-name: Try build on ${{ inputs.runner }}${{ inputs.compiler != 'runner-native' && format(' ({0})', inputs.compiler) || '' }}

# Manually triggered workflow to test knowhere on runner/compiler
# environments that are not covered by the regular UT matrix.
on:
workflow_dispatch:
inputs:
runner:
description: 'GitHub-hosted runner to use'
required: true
type: choice
options:
- ubuntu-22.04
- ubuntu-24.04
- macos-15
- macos-26
default: ubuntu-24.04
compiler:
description: 'compiler toolchain (runner-native = runner default compiler)'
required: true
type: choice
options:
- runner-native
- gcc-11
- gcc-12
- gcc-13
- gcc-14
- gcc-15
- gcc-16
- clang-15
- clang-16
- clang-17
- clang-19
- clang-21
- clang-22
- clang-23
default: runner-native
extra_options:
description: 'extra conan options appended to the generated profile [options] section (e.g. -o \&:with_asan=True)'
required: false
default: ''

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
try-build:
name: Try build (${{ github.event.inputs.runner }})
runs-on: ${{ github.event.inputs.runner }}
timeout-minutes: 300
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: none

- name: Install Dependency
run: |
if [ "$RUNNER_OS" = "Linux" ]; then
sudo apt update && sudo apt install -y cmake libaio-dev python3 python3-pip \
&& pip3 install conan==2.33.0
else
python3 -m venv "$RUNNER_TEMP/conan-venv"
"$RUNNER_TEMP/conan-venv/bin/python" -m pip install conan==2.33.0 "cmake<4"
echo "$RUNNER_TEMP/conan-venv/bin" >> "$GITHUB_PATH"
# knowhere requires OpenMP (find_package(OpenMP REQUIRED)); Apple
# Clang's -fopenmp is a -Xpreprocessor flag that needs libomp's
# headers and runtime, which scripts/install_deps.sh also installs.
brew install libomp
fi

- name: Install toolchain
if: github.event.inputs.compiler != 'runner-native'
env:
INPUT_COMPILER: ${{ github.event.inputs.compiler }}
run: |
set -euo pipefail
COMPILER_TYPE=${INPUT_COMPILER%%-*} # gcc or clang
COMPILER_VERSION=${INPUT_COMPILER##*-} # e.g. 12, 16, 23
BIN_DIR="$RUNNER_TEMP/toolchain-bin"
mkdir -p "$BIN_DIR"
case "$RUNNER_OS/$COMPILER_TYPE" in
macOS/clang)
brew install "llvm@$COMPILER_VERSION"
BREW_LLVM="$(brew --prefix "llvm@$COMPILER_VERSION")"
CC="$BREW_LLVM/bin/clang"
CXX="$BREW_LLVM/bin/clang++"
ln -sf "$CC" "$BIN_DIR/clang"
ln -sf "$CXX" "$BIN_DIR/clang++"
ln -sf "$CC" "$BIN_DIR/cc"
ln -sf "$CXX" "$BIN_DIR/c++"
echo "$BIN_DIR" >> "$GITHUB_PATH"
echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> "$GITHUB_ENV"
;;
macOS/gcc)
brew install "gcc@$COMPILER_VERSION"
BREW_GCC="$(brew --prefix "gcc@$COMPILER_VERSION")"
CC="$BREW_GCC/bin/gcc-$COMPILER_VERSION"
CXX="$BREW_GCC/bin/g++-$COMPILER_VERSION"
ln -sf "$CC" "$BIN_DIR/gcc"
ln -sf "$CXX" "$BIN_DIR/g++"
ln -sf "$CC" "$BIN_DIR/cc"
ln -sf "$CXX" "$BIN_DIR/c++"
echo "$BIN_DIR" >> "$GITHUB_PATH"
echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> "$GITHUB_ENV"
;;
Linux/clang)
wget -qO /tmp/llvm.sh https://apt.llvm.org/llvm.sh
chmod +x /tmp/llvm.sh
sudo /tmp/llvm.sh "$COMPILER_VERSION"
CC="/usr/bin/clang-$COMPILER_VERSION"
CXX="/usr/bin/clang++-$COMPILER_VERSION"
ln -sf "$CC" "$BIN_DIR/clang"
ln -sf "$CXX" "$BIN_DIR/clang++"
ln -sf "$CC" "$BIN_DIR/cc"
ln -sf "$CXX" "$BIN_DIR/c++"
echo "$BIN_DIR" >> "$GITHUB_PATH"
;;
Linux/gcc)
sudo apt-get update
GCC_BIN=""
if sudo apt-get install -y --no-install-recommends "gcc-$COMPILER_VERSION" "g++-$COMPILER_VERSION"; then
GCC_BIN="/usr/bin"
elif sudo apt-get install -y --no-install-recommends software-properties-common \
&& sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test \
&& sudo apt-get update \
&& sudo apt-get install -y --no-install-recommends "gcc-$COMPILER_VERSION" "g++-$COMPILER_VERSION"; then
GCC_BIN="/usr/bin"
else
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew install "gcc@$COMPILER_VERSION"
GCC_BIN="$(brew --prefix "gcc@$COMPILER_VERSION")/bin"
echo "$(brew --prefix binutils)/bin" >> "$GITHUB_PATH"
fi
CC="$GCC_BIN/gcc-$COMPILER_VERSION"
CXX="$GCC_BIN/g++-$COMPILER_VERSION"
ln -sf "$CC" "$BIN_DIR/gcc"
ln -sf "$CXX" "$BIN_DIR/g++"
ln -sf "$CC" "$BIN_DIR/cc"
ln -sf "$CXX" "$BIN_DIR/c++"
echo "$BIN_DIR" >> "$GITHUB_PATH"
;;
*)
echo "Unsupported OS/compiler combination: $RUNNER_OS/$INPUT_COMPILER" >&2
exit 1
;;
esac
echo "CC=$CC" >> "$GITHUB_ENV"
echo "CXX=$CXX" >> "$GITHUB_ENV"

- name: Verify toolchain matches the requested compiler
if: github.event.inputs.compiler != 'runner-native'
env:
INPUT_COMPILER: ${{ github.event.inputs.compiler }}
run: |
set -euo pipefail
COMPILER_VERSION=${INPUT_COMPILER##*-}
for TOOL in "$CC" "$CXX"; do
if [ ! -x "$TOOL" ]; then
echo "::error::$INPUT_COMPILER: resolved compiler '$TOOL' is not executable" >&2
exit 1
fi
done
check_major_version() {
local tool="$1" name="$2" line ver major
line="$("$tool" --version 2>&1 | head -n 1)"
echo "::notice::$name=$tool ($line)"
ver="$(grep -oE '[0-9]+(\.[0-9]+)+' <<<"$line" | tail -n 1)"
major="${ver%%.*}"
if [ "$major" != "$COMPILER_VERSION" ]; then
echo "::error::$name='$tool' reported '$line' but compiler '$INPUT_COMPILER' requires major version $COMPILER_VERSION" >&2
exit 1
fi
}
check_major_version "$CC" "CC"
check_major_version "$CXX" "CXX"

- name: Compute Conan compiler settings
if: github.event.inputs.compiler != 'runner-native'
id: toolchain
env:
INPUT_COMPILER: ${{ github.event.inputs.compiler }}
run: |
set -euo pipefail
COMPILER_TYPE=${INPUT_COMPILER%%-*}
COMPILER_VERSION=${INPUT_COMPILER##*-}
case "$COMPILER_TYPE" in
gcc)
COMPILER=gcc
;;
clang)
COMPILER=clang
;;
*)
echo "Unsupported compiler: $INPUT_COMPILER" >&2
exit 1
;;
esac
echo "Using compiler=$COMPILER/$COMPILER_VERSION"
echo "compiler=$COMPILER" >> "$GITHUB_OUTPUT"
echo "compiler_version=$COMPILER_VERSION" >> "$GITHUB_OUTPUT"

- name: Setup Conan
run: |
conan profile detect --force \
&& conan remote add default-conan-local2 https://milvus01.jfrog.io/artifactory/api/conan/default-conan-local2 --force

- name: Generate Conan profile
env:
INPUT_COMPILER: ${{ github.event.inputs.compiler }}
INPUT_EXTRA_OPTIONS: ${{ github.event.inputs.extra_options }}
COMPILER: ${{ steps.toolchain.outputs.compiler }}
COMPILER_VERSION: ${{ steps.toolchain.outputs.compiler_version }}
run: |
set -euo pipefail
BASE_PROFILE="$(conan profile path default)"
PROFILE_PATH="$RUNNER_TEMP/try-build-profile"
if [ "$INPUT_COMPILER" = "runner-native" ]; then
cp "$BASE_PROFILE" "$PROFILE_PATH"
else
OS="$(sed -n 's/^os=//p' "$BASE_PROFILE")"
ARCH="$(sed -n 's/^arch=//p' "$BASE_PROFILE")"
# Keep libcxx/cppstd from the detected profile: Conan gcc/clang
# recipes commonly read compiler.libcxx (some via direct access
# that raises when the setting is undefined), so dropping them
# would only work until a future recipe bump touches them.
LIBCXX="$(sed -n 's/^compiler.libcxx=//p' "$BASE_PROFILE")"
CPPSTD="$(sed -n 's/^compiler.cppstd=//p' "$BASE_PROFILE")"
{
echo '[settings]'
echo "os=$OS"
echo "arch=$ARCH"
echo "compiler=$COMPILER"
echo "compiler.version=$COMPILER_VERSION"
if [ -n "$LIBCXX" ]; then
echo "compiler.libcxx=$LIBCXX"
fi
if [ -n "$CPPSTD" ]; then
echo "compiler.cppstd=$CPPSTD"
fi
echo
echo '[conf]'
echo "tools.build:compiler_executables={\"c\":\"$CC\",\"cpp\":\"$CXX\"}"
} > "$PROFILE_PATH"
fi
if [ -n "$INPUT_EXTRA_OPTIONS" ]; then
# Accept the documented " -o \&:name=value" form, stripping only a
# leading "-o " per token; reject multi-line values so a stray
# newline cannot inject extra [settings]/[conf] sections.
if [ "$(printf '%s' "$INPUT_EXTRA_OPTIONS" | tr -cd '\n' | wc -c)" -gt 0 ]; then
echo "::error::extra_options must be a single line of space-separated -o \&:name=value entries" >&2
exit 1
fi
# shellcheck disable=SC2206
TOKENS=($INPUT_EXTRA_OPTIONS)
OPTIONS=()
while [ "${#TOKENS[@]}" -gt 0 ]; do
T="${TOKENS[0]}"
TOKENS=("${TOKENS[@]:1}")
if [ "$T" = "-o" ] || [ "$T" = "-o " ]; then
if [ "${#TOKENS[@]}" -eq 0 ]; then
echo "::error::extra_options ends with a dangling '-o'" >&2
exit 1
fi
T="${TOKENS[0]}"
TOKENS=("${TOKENS[@]:1}")
fi
# Normalize a single leading "\&:" / "\&" (the documented input
# form, where the backslash just quotes '&' against the shell)
# to the profile's "&:" form.
case "$T" in
'\&:'*) T="&:${T#'\&:'}" ;;
'\&'*) T="&:${T#'\&'}" ;;
esac
case "$T" in
'&:'*)
OPTIONS+=("$T")
;;
*)
echo "::error::invalid extra_options entry '$T' (expected -o \\&:name=value)" >&2
exit 1
;;
esac
done
{
printf '\n[options]\n'
printf '%s\n' "${OPTIONS[@]}"
} >> "$PROFILE_PATH"
fi
# Fail fast if the assembled profile is not parseable.
conan profile show -pr "$PROFILE_PATH" >/dev/null
echo "Generated Conan profile at $PROFILE_PATH:"
cat "$PROFILE_PATH"
echo "CONAN_PROFILE=$PROFILE_PATH" >> "$GITHUB_ENV"

- name: Try build
env:
INPUT_COMPILER: ${{ github.event.inputs.compiler }}
run: |
set -euo pipefail
MAKE_FLAGS=()
if [ "$RUNNER_OS" = "macOS" ]; then
# Cardinal is not part of the macOS build matrix.
MAKE_FLAGS+=(WITH_CARDINAL=False)
fi
if [ "$INPUT_COMPILER" != "runner-native" ]; then
MAKE_FLAGS+=(CONAN_PROFILE="$CONAN_PROFILE")
fi
make "${MAKE_FLAGS[@]}"

- name: Report build environment
run: |
set -euo pipefail
echo "Runner : ${{ github.event.inputs.runner }}"
echo "OS : $(uname -srm)"
if [ -n "${CC:-}" ]; then
echo "Compiler : $($CC --version | head -n 1)"
else
echo "Compiler : $(cc --version | head -n 1)"
fi
if [ -n "${CONAN_PROFILE:-}" ]; then
echo "CXX standard : $(sed -n 's/^compiler.cppstd=//p' "$CONAN_PROFILE")"
echo "Build type : $(sed -n 's/^build_type=//p' "$CONAN_PROFILE")"
echo "Profile :"
cat "$CONAN_PROFILE"
fi
Loading
Loading