Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(build): sync ov cli version with openviking (#869)

Jiahui Zhou1e26203429f2
diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml
index 89a69ef49..1f574d690 100644
--- a/.github/workflows/_build.yml
+++ b/.github/workflows/_build.yml
@@ -220,6 +220,15 @@ jobs:
- name: Install build dependencies
run: uv pip install setuptools setuptools_scm pybind11 cmake wheel build
+ - name: Resolve OpenViking version for Rust CLI (Linux)
+ shell: bash
+ run: |
+ OPENVIKING_VERSION=$(
+ uv run --frozen python -c "from build_support.versioning import resolve_openviking_version; print(resolve_openviking_version())"
+ )
+ echo "OPENVIKING_VERSION=$OPENVIKING_VERSION" >> "$GITHUB_ENV"
+ echo "Resolved OpenViking version: $OPENVIKING_VERSION"
+
- name: Build Rust CLI (Linux)
run: cargo build --release --target ${{ matrix.arch == 'aarch64' && 'aarch64-unknown-linux-gnu' || 'x86_64-unknown-linux-gnu' }} -p ov_cli
@@ -368,6 +377,15 @@ jobs:
- name: Install build dependencies
run: uv pip install setuptools setuptools_scm pybind11 cmake wheel build
+ - name: Resolve OpenViking version for Rust CLI (macOS/Windows)
+ shell: bash
+ run: |
+ OPENVIKING_VERSION=$(
+ uv run --frozen python -c "from build_support.versioning import resolve_openviking_version; print(resolve_openviking_version())"
+ )
+ echo "OPENVIKING_VERSION=$OPENVIKING_VERSION" >> "$GITHUB_ENV"
+ echo "Resolved OpenViking version: $OPENVIKING_VERSION"
+
- name: Build Rust CLI (macOS/Windows)
shell: bash
run: |
diff --git a/build_support/versioning.py b/build_support/versioning.py
new file mode 100644
index 000000000..b41991aa5
--- /dev/null
+++ b/build_support/versioning.py
@@ -0,0 +1,34 @@
+from __future__ import annotations
+
+import os
+from pathlib import Path
+from typing import Mapping
+
+SCM_TAG_REGEX = r"^(?:v)?(?:[a-zA-Z0-9_]+@)?(?P<version>[0-9]+(?:\.[0-9]+)*)$"
+PROJECT_ROOT = Path(__file__).resolve().parent.parent
+
+
+def _get_scm_version(project_root: Path) -> str:
+ from setuptools_scm import get_version
+
+ return get_version(
+ root=str(project_root),
+ relative_to=__file__,
+ local_scheme="no-local-version",
+ tag_regex=SCM_TAG_REGEX,
+ )
+
+
+def resolve_openviking_version(
+ env: Mapping[str, str] | None = None, project_root: Path | None = None
+) -> str:
+ """Resolve the version shared by the Python package and bundled ov binary."""
+ env = env or os.environ
+ project_root = project_root or PROJECT_ROOT
+
+ for key in ("OPENVIKING_VERSION", "SETUPTOOLS_SCM_PRETEND_VERSION_FOR_OPENVIKING"):
+ value = env.get(key, "").strip()
+ if value:
+ return value
+
+ return _get_scm_version(project_root)
diff --git a/crates/ov_cli/build.rs b/crates/ov_cli/build.rs
new file mode 100644
index 000000000..0b3dbdf6f
--- /dev/null
+++ b/crates/ov_cli/build.rs
@@ -0,0 +1,18 @@
+use std::env;
+
+fn main() {
+ println!("cargo:rerun-if-env-changed=OPENVIKING_VERSION");
+ println!("cargo:rerun-if-env-changed=SETUPTOOLS_SCM_PRETEND_VERSION_FOR_OPENVIKING");
+
+ let version = env::var("OPENVIKING_VERSION")
+ .ok()
+ .filter(|value| !value.trim().is_empty())
+ .or_else(|| {
+ env::var("SETUPTOOLS_SCM_PRETEND_VERSION_FOR_OPENVIKING")
+ .ok()
+ .filter(|value| !value.trim().is_empty())
+ })
+ .unwrap_or_else(|| env::var("CARGO_PKG_VERSION").expect("CARGO_PKG_VERSION must be set"));
+
+ println!("cargo:rustc-env=OPENVIKING_CLI_VERSION={version}");
+}
diff --git a/crates/ov_cli/src/main.rs b/crates/ov_cli/src/main.rs
index 7a1b8cdea..5e49d0319 100644
--- a/crates/ov_cli/src/main.rs
+++ b/crates/ov_cli/src/main.rs
@@ -42,7 +42,7 @@ impl CliContext {
#[derive(Parser)]
#[command(name = "openviking")]
#[command(about = "OpenViking - An Agent-native context database")]
-#[command(version = env!("CARGO_PKG_VERSION"))]
+#[command(version = env!("OPENVIKING_CLI_VERSION"))]
#[command(arg_required_else_help = true)]
struct Cli {
/// Output format
@@ -635,7 +635,7 @@ async fn main() {
}
Commands::Config { action } => handle_config(action, ctx).await,
Commands::Version => {
- println!("{}", env!("CARGO_PKG_VERSION"));
+ println!("{}", env!("OPENVIKING_CLI_VERSION"));
Ok(())
}
Commands::Read { uri } => handle_read(uri, ctx).await,
diff --git a/setup.py b/setup.py
index 87cc38807..31977fb2e 100644
--- a/setup.py
+++ b/setup.py
@@ -19,6 +19,9 @@ if str(SETUP_DIR) not in sys.path:
get_host_engine_build_config = importlib.import_module(
"build_support.x86_profiles"
).get_host_engine_build_config
+resolve_openviking_version = importlib.import_module(
+ "build_support.versioning"
+).resolve_openviking_version
CMAKE_PATH = shutil.which("cmake") or "cmake"
C_COMPILER_PATH = shutil.which("gcc") or "gcc"
@@ -280,6 +283,9 @@ class OpenVikingBuildExt(build_ext):
print("Building ov CLI from source...")
try:
env = os.environ.copy()
+ env["OPENVIKING_VERSION"] = resolve_openviking_version(
+ env=env, project_root=SETUP_DIR
+ )
build_args = ["cargo", "build", "--release"]
target = env.get("CARGO_BUILD_TARGET")
if target: