This is an automated email from the ASF dual-hosted git repository.
spectrometerHBH pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-tirx.git
The following commit(s) were added to refs/heads/main by this push:
new 3ad801cb8 [BUILD][Rust] Use TVM FFI sources and pin registry
dependencies at release (#158)
3ad801cb8 is described below
commit 3ad801cb8e489b9d5b32c2ce6085ba2f296eb2b8
Author: Tianqi Chen <[email protected]>
AuthorDate: Sun Nov 1 22:12:33 2026 -0500
[BUILD][Rust] Use TVM FFI sources and pin registry dependencies at release
(#158)
Rust development builds use TVM FFI directly from the initialized
submodule, allowing unreleased source changes to be tested together.
Release preparation resolves the submodule commit to an exact Apache TVM
FFI release tag and rewrites the dependency to a registry-only exact
version before Cargo packaging and publishing. A check-only composite
action exposes the detected version; locally runnable Python commands
under ci/wheel perform detection and rewriting while the workflow
retains shared metadata preparation. Missing or ambiguous release tags
fail validation. Source-build guidance describes the submodule
dependency.
---
.github/actions/detect-tvm-ffi-version/action.yml | 30 ++++++
.github/workflows/publish_crate.yml | 48 +++------
AGENTS.md | 6 +-
ci/wheel/detect_tvm_ffi_version.py | 114 ++++++++++++++++++++++
cmake/modules/Rust.cmake | 7 +-
docs/dev/source_build.rst | 2 +-
rust/Cargo.toml | 6 +-
7 files changed, 170 insertions(+), 43 deletions(-)
diff --git a/.github/actions/detect-tvm-ffi-version/action.yml
b/.github/actions/detect-tvm-ffi-version/action.yml
new file mode 100644
index 000000000..3867f82cc
--- /dev/null
+++ b/.github/actions/detect-tvm-ffi-version/action.yml
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name: Detect TVM FFI Version
+description: Resolve the committed TVM FFI submodule to exactly one Apache
release tag.
+runs:
+ using: composite
+ steps:
+ - name: Detect the TVM FFI release version
+ id: detect
+ shell: bash
+ run: python ci/wheel/detect_tvm_ffi_version.py detect
+outputs:
+ version:
+ description: The release version without the v prefix.
+ value: ${{ steps.detect.outputs.version }}
diff --git a/.github/workflows/publish_crate.yml
b/.github/workflows/publish_crate.yml
index f30368049..d1c9421f4 100644
--- a/.github/workflows/publish_crate.yml
+++ b/.github/workflows/publish_crate.yml
@@ -58,6 +58,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
sha: ${{ steps.source.outputs.sha }}
+ tvm_ffi_version: ${{ steps.ffi.outputs.version }}
steps:
- name: Checkout source
uses: actions/[email protected]
@@ -77,44 +78,19 @@ jobs:
shell: bash
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
+ # Resolve the registry version from the source gitlink, not the
placeholder in its crate.
+ - id: ffi
+ name: Check the tvm-ffi release
+ uses: ./.github/actions/detect-tvm-ffi-version
+
- name: Prepare matching release metadata
shell: bash
+ env:
+ TVM_FFI_VERSION: ${{ steps.ffi.outputs.version }}
run: &prepare_release_metadata |
uv pip install tomlkit setuptools-scm
python ci/wheel/prepare_release_metadata.py
- python - <<'PY'
- import os
- import tomllib
- from pathlib import Path
-
- main =
tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))
- crate =
tomllib.loads(Path("rust/Cargo.toml").read_text(encoding="utf-8"))
- tvm_ffi = crate["dependencies"]["tvm-ffi"]
- tvm_ffi = tvm_ffi["version"] if isinstance(tvm_ffi, dict) else
tvm_ffi
- # A caret requirement on a tvm-ffi release such as 0.1.15-post2, a
SemVer pre-release,
- # would select an older release such as 0.1.15.
- if not tvm_ffi.startswith("="):
- raise SystemExit(f"rust/Cargo.toml must pin tvm-ffi exactly, not
to {tvm_ffi!r}")
- with open(os.environ["GITHUB_ENV"], "a", encoding="utf-8",
newline="\n") as env:
- env.write(f"RELEASE_VERSION={main['project']['version']}\n")
- env.write(f"CRATE_VERSION={crate['package']['version']}\n")
- env.write(f"TVM_FFI_VERSION={tvm_ffi[1:]}\n")
- PY
-
- # The crate depends on the crates.io release of the tvm-ffi the wheels
are built with.
- - name: Check the tvm-ffi release
- shell: bash
- run: |
- tag="v${TVM_FFI_VERSION}"
- submodule=$(git ls-tree HEAD 3rdparty/tvm-ffi | awk '{print $3}')
- # An annotated tag lists the commit it points to as "<tag>^{}",
after the tag itself.
- release=$(git ls-remote https://github.com/apache/tvm-ffi
"refs/tags/${tag}" "refs/tags/${tag}^{}" |
- sort -k2 | tail -n 1 | cut -f1)
- if [[ "${submodule}" != "${release}" ]]; then
- echo "::error::3rdparty/tvm-ffi is at ${submodule}, but the crate
depends on tvm-ffi ${TVM_FFI_VERSION}, whose tag ${tag} is at ${release:-no
commit}"
- exit 1
- fi
- echo "Crate tvm-tirx ${CRATE_VERSION} for wheel ${RELEASE_VERSION},
with tvm-ffi ${TVM_FFI_VERSION} at ${release}"
+ python ci/wheel/detect_tvm_ffi_version.py rewrite --version
"$TVM_FFI_VERSION"
build_crate:
name: ${{ matrix.name }}
@@ -160,6 +136,8 @@ jobs:
- name: Prepare matching release metadata
shell: bash
+ env:
+ TVM_FFI_VERSION: ${{ needs.check_release.outputs.tvm_ffi_version }}
run: *prepare_release_metadata
- name: Download TIRx wheel
@@ -201,7 +179,7 @@ jobs:
working-directory: rust
run: cargo +stable test --release
- # Packages and verifies the crate; only the release metadata edits above
are uncommitted.
+ # Packages and verifies the crate with the release metadata and registry
dependency edits.
- name: Dry-run crate publication
working-directory: rust
run: cargo +stable publish --dry-run --registry crates-io --allow-dirty
@@ -241,6 +219,8 @@ jobs:
- name: Prepare matching release metadata
shell: bash
+ env:
+ TVM_FFI_VERSION: ${{ needs.check_release.outputs.tvm_ffi_version }}
run: *prepare_release_metadata
- name: Set up Rust
diff --git a/AGENTS.md b/AGENTS.md
index 22b28b3be..7e2523ebe 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -124,8 +124,10 @@ describe missing coverage; they do not demonstrate that a
backend works.
### Rust crate
-`rust/` is a standalone crate (`tvm-tirx`) over the crates.io release of
-`3rdparty/tvm-ffi/rust`, pinned with an exact version requirement. Its IR
+`rust/` is a standalone crate (`tvm-tirx`) over the initialized
+`3rdparty/tvm-ffi/rust` submodule sources. Release CI requires the submodule
+on an exact TVM FFI release tag and rewrites the dependency to that exact
+crates.io version before packaging or publishing. Its IR
bindings are generated by `tvm-ffi-stubgen` between `tvm-ffi-stubgen(begin)`
and
`(end)` markers. The crate links `libtvm_tirx_compiler` from the directory
`tvm-tirx-config --libdir` prints, so build TIRx first. Its build script needs
diff --git a/ci/wheel/detect_tvm_ffi_version.py
b/ci/wheel/detect_tvm_ffi_version.py
new file mode 100644
index 000000000..de3daa8be
--- /dev/null
+++ b/ci/wheel/detect_tvm_ffi_version.py
@@ -0,0 +1,114 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Detect the source TVM FFI release or prepare the crate's registry
dependency.
+
+Run ``python ci/wheel/detect_tvm_ffi_version.py detect`` to print the release
version
+without changing the checkout. After preparing wheel metadata, run
+``python ci/wheel/detect_tvm_ffi_version.py rewrite --version VERSION`` to
replace the
+crate's source dependency with the exact registry version. GitHub output/env
+files are written when their environment variables are set.
+"""
+
+import argparse
+import os
+import re
+import subprocess
+from pathlib import Path
+
+VERSION_PATTERN =
r"[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?"
+
+
+def detect_version(root):
+ """Resolve the committed submodule to exactly one upstream release tag."""
+ submodule = subprocess.check_output(
+ ["git", "rev-parse", "HEAD:3rdparty/tvm-ffi"], cwd=root, text=True
+ ).strip()
+ refs = {}
+ for line in subprocess.check_output(
+ ["git", "ls-remote", "https://github.com/apache/tvm-ffi",
"refs/tags/v*"],
+ cwd=root,
+ text=True,
+ ).splitlines():
+ sha, ref = line.split()
+ refs[ref] = sha
+ # Prefer the peeled commit for annotated tags; lightweight tags point at
it directly.
+ versions = sorted(
+ ref.removeprefix("refs/tags/v")
+ for ref, sha in refs.items()
+ if re.fullmatch("refs/tags/v" + VERSION_PATTERN, ref)
+ and refs.get(ref + "^{}", sha) == submodule
+ )
+ if len(versions) != 1:
+ raise SystemExit(
+ f"3rdparty/tvm-ffi at {submodule} must match exactly one
apache/tvm-ffi "
+ f"release tag; found {versions}"
+ )
+ return versions[0]
+
+
+def write_github_values(variable, values):
+ """Export values in Actions while keeping local invocations independent of
it."""
+ if path := os.environ.get(variable):
+ with open(path, "a", encoding="utf-8", newline="\n") as output:
+ for name, value in values.items():
+ output.write(f"{name}={value}\n")
+
+
+def rewrite_dependency(root, version):
+ """Replace the source dependency with the verified exact registry
version."""
+ import tomlkit
+
+ if not re.fullmatch(VERSION_PATTERN, version):
+ raise SystemExit("version must come from the verified submodule
release tag")
+ main = tomlkit.parse((root / "pyproject.toml").read_text(encoding="utf-8"))
+ crate_path = root / "rust/Cargo.toml"
+ crate = tomlkit.parse(crate_path.read_text(encoding="utf-8"))
+ # Remove the source path entirely. An exact requirement preserves
prerelease versions
+ # such as 0.1.15-post2, which a caret requirement could replace with the
older 0.1.15.
+ crate["dependencies"]["tvm-ffi"] = f"={version}"
+ crate_path.write_text(tomlkit.dumps(crate), encoding="utf-8")
+ write_github_values(
+ "GITHUB_ENV",
+ {
+ "RELEASE_VERSION": main["project"]["version"],
+ "CRATE_VERSION": crate["package"]["version"],
+ "TVM_FFI_VERSION": version,
+ },
+ )
+ print(f"Crate tvm-tirx {crate['package']['version']} with crates.io
tvm-ffi {version}")
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument("--root", type=Path,
default=Path(__file__).resolve().parents[2])
+ commands = parser.add_subparsers(dest="command", required=True)
+ commands.add_parser("detect", help="print the release version without
modifying sources")
+ rewrite = commands.add_parser("rewrite", help="prepare the crate's exact
registry dependency")
+ rewrite.add_argument("--version", required=True, help="version returned by
detect")
+ args = parser.parse_args()
+ root = args.root.resolve()
+ if args.command == "detect":
+ version = detect_version(root)
+ write_github_values("GITHUB_OUTPUT", {"version": version})
+ print(version)
+ else:
+ rewrite_dependency(root, args.version)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/cmake/modules/Rust.cmake b/cmake/modules/Rust.cmake
index b1a5424a9..94c90c274 100644
--- a/cmake/modules/Rust.cmake
+++ b/cmake/modules/Rust.cmake
@@ -22,9 +22,10 @@
#
# TVM_TIRX_USE_RUST is ON, OFF or AUTO. AUTO builds the library when it can:
with the crate's
# sources (a source distribution has none), with a cargo at least as new as
the crate's
-# rust-version, and with the crate's dependencies, which `cargo fetch` gets
from crates.io or finds
-# in cargo's cache. rustup's cargo ($CARGO_HOME/bin or ~/.cargo/bin) is
preferred over one on PATH,
-# which may be an older system cargo; set TVM_TIRX_CARGO to choose another.
+# rust-version, with the initialized tvm-ffi submodule, and with registry
dependencies available
+# through `cargo fetch` or cargo's cache. rustup's cargo ($CARGO_HOME/bin or
~/.cargo/bin) is
+# preferred over one on PATH, which may be an older system cargo; set
TVM_TIRX_CARGO to choose
+# another.
#
# A build without the library removes the one an earlier build left, which
`import tvm_tirx` would
# load otherwise.
diff --git a/docs/dev/source_build.rst b/docs/dev/source_build.rst
index 0c8994b59..80f9f8efd 100644
--- a/docs/dev/source_build.rst
+++ b/docs/dev/source_build.rst
@@ -74,7 +74,7 @@ Available CMake options (see `CMakeLists.txt
- ``TVM_TIRX_USE_Z3`` -- Enable the Z3 solver (default: ``AUTO``).
- ``TVM_TIRX_USE_RUST`` -- Build the operators written in Rust (``rust/``)
with cargo
(default: ``AUTO``, which needs a cargo as new as the crate's
``rust-version`` and the crate's
- dependencies, from crates.io or cargo's cache).
+ initialized TVM FFI submodule, with other dependencies from crates.io or
cargo's cache).
- ``TVM_TIRX_BUILD_TESTS`` -- Build C++ tests (default: ``OFF``).
Verify the installation:
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index 7bdbc5a02..42702a814 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -37,9 +37,9 @@ name = "tvm_tirx"
crate-type = ["rlib", "cdylib"]
[dependencies]
-# The release of 3rdparty/tvm-ffi. An exact requirement, since 0.1.15-post2 is
a pre-release of
-# 0.1.15 for semver, and a caret requirement would select the older 0.1.15.
-tvm-ffi = "=0.1.15-post2"
+# Develop against the submodule sources, including changes between tvm-ffi
releases.
+# Release CI replaces this with an exact crates.io version from the submodule
release tag.
+tvm-ffi = { path = "../3rdparty/tvm-ffi/rust/tvm-ffi" }
# A library of operators and a type defined in Rust, which
`tests/python/ir/test_op_rust.py` loads.
[[example]]