lucifer1004 opened a new pull request, #590:
URL: https://github.com/apache/tvm-ffi/pull/590
## Summary
Three small bugs in the Rust ergonomics that prevented the macros from
being usable from downstream cdylibs:
1. **`ensure!` macro** expanded to `crate::bail!`, which resolves to
the *caller* crate at expansion site rather than `tvm_ffi`. Switched
to `$crate::bail!` so the path resolves correctly in any crate.
2. **`tvm_ffi_dll_export_typed_func!`** referenced
`tvm_ffi_sys::TVMFFIAny` without a `$crate::` prefix, forcing every
downstream crate to add `tvm-ffi-sys` to its own `[dependencies]`.
Switched to `$crate::tvm_ffi_sys::TVMFFIAny`; downstream crates now
only need to depend on `tvm-ffi`.
3. **Missing `#[no_mangle]`**: the generated
`pub unsafe extern "C" fn __tvm_ffi_<name>` had no `#[no_mangle]`,
so the linker stripped the symbol from cdylibs and
`Module::GetFunction` could not find it. Added
`#[unsafe(no_mangle)]` (supported in 2021 + 2024 editions on
rustc ≥ 1.82).
## Reproduction (before)
Building a downstream cdylib that uses `tvm_ffi_dll_export_typed_func!`:
\`\`\`text
error[E0433]: cannot find module or crate \`tvm_ffi_sys\` in this scope
= note: this error originates in the macro
\`tvm_ffi_dll_export_typed_func\`
\`\`\`
After adding \`tvm-ffi-sys\` as a direct dep:
\`\`\`text
error[E0433]: cannot find \`bail\` in the crate root
= note: this error originates in the macro \`tvm_ffi::ensure\`
\`\`\`
After working around \`ensure!\`, the cdylib builds — but
\`nm -D libfoo.so | grep tvm_ffi\` returns nothing because
\`#[no_mangle]\` is missing.
## Test plan
- [x] Built a downstream cdylib that only depends on \`tvm-ffi\` (no
\`tvm-ffi-sys\` direct dep).
- [x] Loaded via \`tvm_ffi.load_module(...)\` from Python.
- [x] Called three typed functions: scalar (\`sum_i32\`), 1-D tensor
(\`add_one_inplace\`), 2-tensor (\`dot_f32\`). All round-trip.
- [x] \`nm -D libfoo.so | grep __tvm_ffi\` shows the exported symbols.
This is the first of two stacked PRs from the same Rust-side work.
The second adds \`Module::LoadFromBytes\`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]