This is an automated email from the ASF dual-hosted git repository.
tqchen 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 47ceb5d3f [DOCS][RUST] Use the published tvm-tirx crate in the
extension example (#130)
47ceb5d3f is described below
commit 47ceb5d3fa7ede221ee6eac2cbffa6bb73b7fc12
Author: Linzhang Li <[email protected]>
AuthorDate: Fri Oct 30 09:14:13 2026 -0400
[DOCS][RUST] Use the published tvm-tirx crate in the extension example
(#130)
## Summary
`tvm-tirx` 0.1.0-alpha.5 is now on crates.io, so the extension example
depends on the published
crate instead of `rust/` by path. Building the example no longer needs a
source build of TIRx:
`pip install ./examples/extension` installs `apache-tvm-tirx` from PyPI,
which provides the native
libraries the crate links, and builds the extension against it.
---
docs/advanced/extending_ir_in_rust.rst | 23 ++++++++---------------
docs/advanced/using_ir_extensions.rst | 2 +-
docs/reference/rust/index.rst | 11 ++++++-----
examples/extension/Cargo.toml | 6 +-----
examples/extension/README.md | 12 +++++-------
examples/extension/rustfmt.toml | 4 +---
tests/python/ir/test_op_rust.py | 9 +++++++--
7 files changed, 29 insertions(+), 38 deletions(-)
diff --git a/docs/advanced/extending_ir_in_rust.rst
b/docs/advanced/extending_ir_in_rust.rst
index b637140e3..ce8c3ac03 100644
--- a/docs/advanced/extending_ir_in_rust.rst
+++ b/docs/advanced/extending_ir_in_rust.rst
@@ -67,30 +67,23 @@ it is installed and imported like any other package. The
example package,
├── python/my_ext/ # loads the library and registers a compilation
pipeline
└── run_example.py # compiles and runs a function that uses the extension
-The Rust library is an ordinary crate that builds a shared library:
+The Rust library is an ordinary crate that builds a shared library. Its only
+dependency is the `tvm-tirx <https://crates.io/crates/tvm-tirx>`_ crate, which
+re-exports TVM FFI as ``tvm_tirx::tvm_ffi``:
.. literalinclude:: ../../examples/extension/Cargo.toml
:language: toml
:start-at: [lib]
- :end-before: # Standalone crate
-``tvm-tirx`` re-exports TVM FFI as ``tvm_tirx::tvm_ffi``, so it is the only
-dependency.
-
-To build and install the package, follow :doc:`../dev/source_build` to install
-TIRx with LLVM enabled, and use Rust 1.84 or newer; the build looks for cargo
-in ``~/.cargo/bin``, where rustup installs it, and then on ``PATH``. Then, from
-the TIRx repository root:
+With Rust 1.84 or newer, build and install the package from the TIRx
+repository root:
.. code-block:: bash
- uv pip install scikit-build-core
- uv pip install --no-build-isolation examples/extension
+ pip install ./examples/extension
-``--no-build-isolation`` builds the package against the TIRx in the project
-environment: the cargo build runs its ``tvm-tirx-config`` and
-``tvm-ffi-config`` tools to find the native libraries, so the extension links
-the TIRx it runs with.
+The package depends on ``apache-tvm-tirx``, and the build links the library
+against the TIRx native libraries that this package provides.
Case Study: Complex Numbers
---------------------------
diff --git a/docs/advanced/using_ir_extensions.rst
b/docs/advanced/using_ir_extensions.rst
index 95b0454c3..29d3ba284 100644
--- a/docs/advanced/using_ir_extensions.rst
+++ b/docs/advanced/using_ir_extensions.rst
@@ -89,7 +89,7 @@ With the package installed as in :doc:`extending_ir_in_rust`,
run the script:
.. code-block:: bash
- uv run --no-sync python examples/extension/run_example.py
+ python examples/extension/run_example.py
A successful run prints:
diff --git a/docs/reference/rust/index.rst b/docs/reference/rust/index.rst
index 1ca675b7a..4905526cc 100644
--- a/docs/reference/rust/index.rst
+++ b/docs/reference/rust/index.rst
@@ -18,11 +18,12 @@
Rust API
========
-The ``tvm-tirx`` crate in ``rust/`` binds the TIRx compiler objects over TVM
FFI.
-Its modules follow the Python package: ``tvm_tirx::ir`` is :doc:`tvm_tirx.ir
-<../python/ir>`, ``tvm_tirx::tirx`` is :doc:`tvm_tirx.tirx <../python/tirx>`,
and so
-on. Operators and types can also be defined from Rust in
``tvm_ffi::static_init_block!``
-blocks, which run when :doc:`tvm_tirx.backend.rust <../python/backend.rust>`
loads the
+The `tvm-tirx <https://crates.io/crates/tvm-tirx>`__ crate binds the TIRx
compiler
+objects over TVM FFI. Its modules follow the Python package: ``tvm_tirx::ir``
is
+:doc:`tvm_tirx.ir <../python/ir>`, ``tvm_tirx::tirx`` is :doc:`tvm_tirx.tirx
+<../python/tirx>`, and so on. Operators and types can also be defined from
Rust in
+``tvm_ffi::static_init_block!`` blocks, which run when their library loads; the
+:doc:`Rust extension tutorial <../../advanced/extending_ir_in_rust>` builds
such a
library.
The crate is built on the ``tvm-ffi`` crate, which provides the objects,
functions,
diff --git a/examples/extension/Cargo.toml b/examples/extension/Cargo.toml
index aa004ed92..809a036b8 100644
--- a/examples/extension/Cargo.toml
+++ b/examples/extension/Cargo.toml
@@ -26,8 +26,4 @@ publish = false
crate-type = ["cdylib"]
[dependencies]
-# The tvm-tirx crate is not published yet, so the extension depends on it by
path.
-tvm-tirx = { path = "../../rust" }
-
-# Standalone crate: not a member of any enclosing workspace.
-[workspace]
+tvm-tirx = "0.1.0-alpha.5"
diff --git a/examples/extension/README.md b/examples/extension/README.md
index df9a945d6..25dcb9c0e 100644
--- a/examples/extension/README.md
+++ b/examples/extension/README.md
@@ -30,14 +30,12 @@ pipeline. The tutorial in `docs/advanced/` walks through
the code.
## Install and Run
-Install TIRx from source with LLVM enabled, and Rust 1.84 or newer. From the
-repository root:
+With Rust 1.84 or newer, from the repository root:
```bash
-uv pip install scikit-build-core
-uv pip install --no-build-isolation examples/extension
-uv run --no-sync python examples/extension/run_example.py
+pip install ./examples/extension
+python examples/extension/run_example.py
```
-`--no-build-isolation` builds against the TIRx in the project environment,
-whose `tvm-tirx-config` and `tvm-ffi-config` the cargo build runs.
+The build compiles the library against the published `tvm-tirx` crate and the
+`apache-tvm-tirx` package, which the extension also depends on at run time.
diff --git a/examples/extension/rustfmt.toml b/examples/extension/rustfmt.toml
index 59604833f..f5a5255a8 100644
--- a/examples/extension/rustfmt.toml
+++ b/examples/extension/rustfmt.toml
@@ -15,7 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-# Match the layout `tvm-ffi-stubgen --target rust` emits, so `cargo fmt` leaves
-# the generated blocks byte-identical and `tvm-ffi-stubgen --check` stays
clean.
+# Keep calls and method chains on one line up to the 100-column limit.
use_small_heuristics = "Max"
-reorder_imports = false
diff --git a/tests/python/ir/test_op_rust.py b/tests/python/ir/test_op_rust.py
index a3e5a1725..ee3436bd8 100644
--- a/tests/python/ir/test_op_rust.py
+++ b/tests/python/ir/test_op_rust.py
@@ -23,6 +23,7 @@ with them. A copy of the library is a second library with the
same blocks, as li
the same crate have.
"""
+import json
import os
import re
import shutil
@@ -91,8 +92,12 @@ def define_ir_library():
@pytest.fixture(scope="module")
def extension_package(tmp_path_factory):
- """The my_ext package of examples/extension, laid out as its wheel
installs it."""
- debug_dir = cargo_build(EXTENSION_DIR / "Cargo.toml")
+ """The my_ext package of examples/extension, laid out as its wheel
installs it, built against
+ rust/ in place of the published tvm-tirx crate."""
+ rust_dir = json.dumps(str(RUST_DIR)) # a TOML string, as `--config` takes
+ debug_dir = cargo_build(
+ EXTENSION_DIR / "Cargo.toml", "--config",
f"patch.crates-io.tvm-tirx.path={rust_dir}"
+ )
root = tmp_path_factory.mktemp("extension")
package = shutil.copytree(EXTENSION_DIR / "python" / "my_ext", root /
"my_ext")
shutil.copy(debug_dir / library_name("my_ext"), package)