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-ffi.git
The following commit(s) were added to refs/heads/main by this push:
new 35c99d0 [FIX][RUST] use `$crate::` in tvm_ffi_dll_export_typed_func!
and ensure! (#590)
35c99d0 is described below
commit 35c99d0ac4cb784862115d0089f60c603acec8f9
Author: Gabriel Wu <[email protected]>
AuthorDate: Fri May 15 22:59:45 2026 +0800
[FIX][RUST] use `$crate::` in tvm_ffi_dll_export_typed_func! and ensure!
(#590)
---
rust/tvm-ffi/src/macros.rs | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/rust/tvm-ffi/src/macros.rs b/rust/tvm-ffi/src/macros.rs
index 95c2b5b..7c2cad7 100644
--- a/rust/tvm-ffi/src/macros.rs
+++ b/rust/tvm-ffi/src/macros.rs
@@ -102,7 +102,7 @@ macro_rules! bail {
macro_rules! ensure {
($cond:expr, $error_kind:expr, $fmt:expr $(, $args:expr)* $(,)?) => {{
if !$cond {
- crate::bail!($error_kind, $fmt $(, $args)*);
+ $crate::bail!($error_kind, $fmt $(, $args)*);
}
}};
}
@@ -260,11 +260,27 @@ macro_rules! impl_arg_into_ref {
macro_rules! tvm_ffi_dll_export_typed_func {
($name:ident, $func:expr) => {
$crate::macros::paste::paste! {
+ // `#[no_mangle]` is required so the symbol is preserved in a
+ // `cdylib` and matches the `__tvm_ffi_<name>` naming convention
+ // that `ffi.Module.load_from_file.<format>` looks up via
+ // `GetSymbolWithSymbolPrefix`. Without it, the linker strips the
+ // function from the output `.so`.
+ //
+ // Using plain `#[no_mangle]` (rather than `#[unsafe(no_mangle)]`,
+ // which would require rustc >= 1.82) keeps the crate buildable
+ // on older toolchains. Edition-2024 callers will see a
+ // deprecation warning, which is harmless.
+ //
+ // The path-qualified `$crate::tvm_ffi_sys::…` reference (rather
+ // than a bare `tvm_ffi_sys::…`) lets downstream crates use the
+ // macro without having to add `tvm-ffi-sys` to their own
+ // `[dependencies]`.
+ #[no_mangle]
pub unsafe extern "C" fn [<__tvm_ffi_ $name>](
_handle: *mut std::ffi::c_void,
- args: *const tvm_ffi_sys::TVMFFIAny,
+ args: *const $crate::tvm_ffi_sys::TVMFFIAny,
num_args: i32,
- result: *mut tvm_ffi_sys::TVMFFIAny,
+ result: *mut $crate::tvm_ffi_sys::TVMFFIAny,
) -> i32 {
let packed_args =
std::slice::from_raw_parts(args as *const
$crate::any::AnyView, num_args as usize);