Skip to content

Commit 51003ed

Browse files
committed
ci: enable ONNX runtime setup for embeddings builds
1 parent feffa7d commit 51003ed

3 files changed

Lines changed: 126 additions & 14 deletions

File tree

.github/workflows/embedding_build_template.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,32 @@ jobs:
234234
run: |
235235
# Set Docker image based on architecture
236236
# Download glibc2_17-compatible ORT static lib (avoids __isoc23_strtoll from pyke.io builds)
237-
ORT_VERSION="1.24.2"
237+
read_ort_metadata() {
238+
local key="$1"
239+
awk -v key="$key" '
240+
/^\[package.metadata.manticore.ort\]/ { in_section=1; next }
241+
/^\[/ { in_section=0 }
242+
in_section && $1 == key {
243+
gsub(/"/, "", $3)
244+
print $3
245+
exit
246+
}
247+
' embeddings/Cargo.toml
248+
}
249+
250+
ORT_VERSION="$(read_ort_metadata version)"
251+
ORT_GLIBC="$(read_ort_metadata linux-glibc)"
252+
if [[ -z "${ORT_VERSION}" || -z "${ORT_GLIBC}" ]]; then
253+
echo "Failed to read ORT metadata from embeddings/Cargo.toml" >&2
254+
exit 1
255+
fi
256+
238257
if [[ "${{ inputs.arch }}" == "aarch64" ]]; then
239258
docker_image="ghcr.io/manticoresoftware/rust-min-libc:aarch64-rust1.94.1-glibc2.27-openssl1.1.1k"
240-
ort_asset="onnxruntime-linux-aarch64-static_lib-${ORT_VERSION}-glibc2_17"
259+
ort_asset="onnxruntime-linux-aarch64-static_lib-${ORT_VERSION}-glibc${ORT_GLIBC}"
241260
else
242261
docker_image="ghcr.io/manticoresoftware/rust-min-libc:amd64-rust1.94.1-glibc2.27-openssl1.1.1k"
243-
ort_asset="onnxruntime-linux-x64-static_lib-${ORT_VERSION}-glibc2_17"
262+
ort_asset="onnxruntime-linux-x64-static_lib-${ORT_VERSION}-glibc${ORT_GLIBC}"
244263
fi
245264
246265
curl -sL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v${ORT_VERSION}/${ort_asset}.zip" -o /tmp/ort.zip

cmake/build_embeddings.cmake

Lines changed: 100 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,80 @@ if (__build_embeddings_included)
2020
endif ()
2121
set ( __build_embeddings_included YES )
2222

23+
set ( EMBEDDINGS_ORT_VERSION "" CACHE STRING "ONNX Runtime version used for local Linux embeddings builds; defaults to embeddings/Cargo.toml metadata" )
24+
set ( EMBEDDINGS_ORT_GLIBC "" CACHE STRING "ONNX Runtime glibc baseline used for local Linux embeddings builds; defaults to embeddings/Cargo.toml metadata" )
25+
26+
function(read_embeddings_ort_metadata OUT_ORT_VERSION OUT_ORT_GLIBC)
27+
set ( CARGO_TOML "${CMAKE_SOURCE_DIR}/embeddings/Cargo.toml" )
28+
if (NOT EXISTS "${CARGO_TOML}")
29+
message ( FATAL_ERROR "embeddings Cargo.toml was not found: ${CARGO_TOML}" )
30+
endif()
31+
32+
file ( READ "${CARGO_TOML}" CARGO_TOML_CONTENT )
33+
string ( REGEX MATCH "\\[package\\.metadata\\.manticore\\.ort\\][^\[]*" ORT_METADATA "${CARGO_TOML_CONTENT}" )
34+
if (NOT ORT_METADATA)
35+
message ( FATAL_ERROR "Missing [package.metadata.manticore.ort] version/linux-glibc in ${CARGO_TOML}" )
36+
endif()
37+
38+
if (NOT ORT_METADATA MATCHES "version[ \t]*=[ \t]*\"([^\"]+)\"")
39+
message ( FATAL_ERROR "Missing [package.metadata.manticore.ort] version in ${CARGO_TOML}" )
40+
endif()
41+
set ( ORT_VERSION "${CMAKE_MATCH_1}" )
42+
43+
if (NOT ORT_METADATA MATCHES "linux-glibc[ \t]*=[ \t]*\"([^\"]+)\"")
44+
message ( FATAL_ERROR "Missing [package.metadata.manticore.ort] linux-glibc in ${CARGO_TOML}" )
45+
endif()
46+
set ( ORT_GLIBC "${CMAKE_MATCH_1}" )
47+
48+
if (EMBEDDINGS_ORT_VERSION)
49+
set ( ORT_VERSION "${EMBEDDINGS_ORT_VERSION}" )
50+
endif()
51+
if (EMBEDDINGS_ORT_GLIBC)
52+
set ( ORT_GLIBC "${EMBEDDINGS_ORT_GLIBC}" )
53+
endif()
54+
55+
set ( ${OUT_ORT_VERSION} "${ORT_VERSION}" PARENT_SCOPE )
56+
set ( ${OUT_ORT_GLIBC} "${ORT_GLIBC}" PARENT_SCOPE )
57+
endfunction()
58+
59+
function(prepare_embeddings_ort)
60+
if (NOT UNIX OR APPLE)
61+
return()
62+
endif()
63+
64+
read_embeddings_ort_metadata ( ORT_VERSION ORT_GLIBC )
65+
66+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)$")
67+
set ( ORT_ARCH "aarch64" )
68+
else()
69+
set ( ORT_ARCH "x64" )
70+
endif()
71+
72+
set ( ORT_ASSET "onnxruntime-linux-${ORT_ARCH}-static_lib-${ORT_VERSION}-glibc${ORT_GLIBC}" )
73+
set ( ORT_URL "https://github.com/csukuangfj/onnxruntime-libs/releases/download/v${ORT_VERSION}/${ORT_ASSET}.zip" )
74+
set ( ORT_ROOT "${CMAKE_CURRENT_BINARY_DIR}/embeddings/ort/${ORT_ASSET}" )
75+
set ( ORT_ZIP "${CMAKE_CURRENT_BINARY_DIR}/embeddings/ort/${ORT_ASSET}.zip" )
76+
77+
if (NOT EXISTS "${ORT_ROOT}/lib")
78+
message ( STATUS "Downloading ONNX Runtime static library: ${ORT_ASSET}" )
79+
file ( MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/embeddings/ort" )
80+
file ( DOWNLOAD "${ORT_URL}" "${ORT_ZIP}" STATUS ORT_DOWNLOAD_STATUS SHOW_PROGRESS )
81+
list ( GET ORT_DOWNLOAD_STATUS 0 ORT_DOWNLOAD_CODE )
82+
if (NOT ORT_DOWNLOAD_CODE EQUAL 0)
83+
list ( GET ORT_DOWNLOAD_STATUS 1 ORT_DOWNLOAD_ERROR )
84+
message ( FATAL_ERROR "Failed to download ${ORT_URL}: ${ORT_DOWNLOAD_ERROR}" )
85+
endif()
86+
file ( ARCHIVE_EXTRACT INPUT "${ORT_ZIP}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/embeddings/ort" )
87+
endif()
88+
89+
if (NOT EXISTS "${ORT_ROOT}/lib")
90+
message ( FATAL_ERROR "ONNX Runtime lib directory was not found: ${ORT_ROOT}/lib" )
91+
endif()
92+
93+
set ( ENV{ORT_LIB_PATH} "${ORT_ROOT}/lib" )
94+
message ( STATUS "Using ONNX Runtime from ORT_LIB_PATH=$ENV{ORT_LIB_PATH}" )
95+
endfunction()
96+
2397
function(build_embeddings_lib)
2498
message ( STATUS "building embeddings locally..." )
2599

@@ -49,21 +123,37 @@ function(build_embeddings_lib)
49123
# This matches the format used by other Manticore libraries for consistent version display
50124
set(ENV{GIT_COMMIT_ID} "${GIT_COMMIT_ID}")
51125
set(ENV{GIT_TIMESTAMP_ID} "${GIT_TIMESTAMP_ID}")
126+
prepare_embeddings_ort()
52127

53-
# Enable platform-specific BLAS acceleration for candle when available
54-
set(EMBEDDINGS_CARGO_FEATURES "")
55-
if(APPLE)
56-
set(EMBEDDINGS_CARGO_FEATURES "--features" "accelerate")
57-
elseif(UNIX)
58-
# MKL provides multi-threaded BLAS on Linux; skip if not available
59-
execute_process(COMMAND pkg-config --exists mkl-dynamic-lp64-seq RESULT_VARIABLE MKL_FOUND OUTPUT_QUIET ERROR_QUIET)
60-
if(MKL_FOUND EQUAL 0)
61-
set(EMBEDDINGS_CARGO_FEATURES "--features" "mkl")
128+
# Enable platform-specific BLAS acceleration for candle when available.
129+
if (DEFINED EMBEDDINGS_CARGO_FEATURES)
130+
set(EMBEDDINGS_FEATURES_CSV "${EMBEDDINGS_CARGO_FEATURES}")
131+
else()
132+
set(EMBEDDINGS_FEATURE_LIST)
133+
if(APPLE)
134+
list(APPEND EMBEDDINGS_FEATURE_LIST accelerate)
135+
elseif(UNIX)
136+
# MKL provides multi-threaded BLAS on Linux; skip if not available
137+
execute_process(COMMAND pkg-config --exists mkl-dynamic-lp64-seq RESULT_VARIABLE MKL_FOUND OUTPUT_QUIET ERROR_QUIET)
138+
if(MKL_FOUND EQUAL 0)
139+
list(APPEND EMBEDDINGS_FEATURE_LIST mkl)
140+
endif()
62141
endif()
142+
list(JOIN EMBEDDINGS_FEATURE_LIST "," EMBEDDINGS_FEATURES_CSV)
143+
endif()
144+
145+
if (UNIX AND NOT APPLE AND DEFINED ENV{ORT_LIB_PATH} AND NOT "$ENV{ORT_LIB_PATH}" STREQUAL "" AND EMBEDDINGS_FEATURES_CSV)
146+
string(REPLACE "," ";" EMBEDDINGS_FEATURE_LIST "${EMBEDDINGS_FEATURES_CSV}")
147+
list(REMOVE_ITEM EMBEDDINGS_FEATURE_LIST download-ort)
148+
list(JOIN EMBEDDINGS_FEATURE_LIST "," EMBEDDINGS_FEATURES_CSV)
149+
endif()
150+
151+
if (EMBEDDINGS_FEATURES_CSV)
152+
set(EMBEDDINGS_CARGO_FEATURE_ARGS "--features" "${EMBEDDINGS_FEATURES_CSV}")
63153
endif()
64154

65155
execute_process (
66-
COMMAND cargo build --manifest-path ${CMAKE_SOURCE_DIR}/embeddings/Cargo.toml --lib --release ${EMBEDDINGS_CARGO_FEATURES} --target-dir ${CMAKE_CURRENT_BINARY_DIR}/embeddings
156+
COMMAND cargo build --manifest-path ${CMAKE_SOURCE_DIR}/embeddings/Cargo.toml --lib --release ${EMBEDDINGS_CARGO_FEATURE_ARGS} --target-dir ${CMAKE_CURRENT_BINARY_DIR}/embeddings
67157
RESULT_VARIABLE CMD_RESULT
68158
)
69159

@@ -86,4 +176,3 @@ function(build_embeddings_lib)
86176
file(RENAME "${CMAKE_CURRENT_BINARY_DIR}/embeddings/release/${EMBEDDINGS_LIB_NAME}.pdb" "${CMAKE_CURRENT_BINARY_DIR}/embeddings/release/lib_${EMBEDDINGS_LIB_NAME}.pdb")
87177
endif()
88178
endfunction ()
89-

embeddings/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name = "manticore-knn-embeddings"
33
version = "1.1.1"
44
edition = "2021"
55

6+
[package.metadata.manticore.ort]
7+
version = "1.24.2"
8+
linux-glibc = "2_17"
9+
610
# Candle: git dep so CI works without a local candle clone.
711
# For local dev with ../../candle, add a [patch] section to use path deps.
812
[dependencies]

0 commit comments

Comments
 (0)