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 bbe5ea7b [FIX][Rust] Link tvm_ffi_testing only for tests (#817)
bbe5ea7b is described below
commit bbe5ea7bbaf3e274a03878be05e71b4a4a9a4a27
Author: Gabriel Wu <[email protected]>
AuthorDate: Sat Sep 26 23:56:48 2026 +0800
[FIX][Rust] Link tvm_ffi_testing only for tests (#817)
## Why
`tvm-ffi-sys/build.rs` links `tvm_ffi_testing` unconditionally, so every
crate that depends on tvm-ffi asks the linker for the testing library.
Only the tvm-ffi tests use it, for the `testing.*` global functions it
registers. With `--as-needed` the library usually drops out of the final
binary, but a downstream build still needs it present at link time, and
the link line doesn't reflect what the crate uses.
## What
- `tvm-ffi-sys` gets a `testing` feature, off by default. Its build
script links `tvm_ffi_testing` only when the feature is enabled.
- `tvm-ffi` enables the feature through a dev-dependency on
`tvm-ffi-sys`, so its tests, which run with resolver 2, still link the
testing library.
---
rust/tvm-ffi-sys/Cargo.toml | 4 ++++
rust/tvm-ffi-sys/build.rs | 7 ++++++-
rust/tvm-ffi/Cargo.toml | 4 ++++
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/rust/tvm-ffi-sys/Cargo.toml b/rust/tvm-ffi-sys/Cargo.toml
index ef87038d..5ae2d954 100644
--- a/rust/tvm-ffi-sys/Cargo.toml
+++ b/rust/tvm-ffi-sys/Cargo.toml
@@ -27,3 +27,7 @@ license = "Apache-2.0"
[lib]
name = "tvm_ffi_sys"
crate-type = ["lib"]
+
+[features]
+# Link libtvm_ffi_testing, which registers the `testing.*` global functions.
+testing = []
diff --git a/rust/tvm-ffi-sys/build.rs b/rust/tvm-ffi-sys/build.rs
index 1f2e64a5..fe787589 100644
--- a/rust/tvm-ffi-sys/build.rs
+++ b/rust/tvm-ffi-sys/build.rs
@@ -83,7 +83,12 @@ fn main() {
println!("cargo:rustc-link-search=native={}", lib_dir);
// link the library
println!("cargo:rustc-link-lib=dylib=tvm_ffi");
- println!("cargo:rustc-link-lib=dylib=tvm_ffi_testing");
+ // The testing library registers the `testing.*` global functions that
+ // tests call; link it only when asked, so that users of the crate do not
+ // depend on it at run time.
+ if env::var_os("CARGO_FEATURE_TESTING").is_some() {
+ println!("cargo:rustc-link-lib=dylib=tvm_ffi_testing");
+ }
// update the LD_LIBRARY_PATH environment variable
update_ld_library_path(&lib_dir);
}
diff --git a/rust/tvm-ffi/Cargo.toml b/rust/tvm-ffi/Cargo.toml
index b27c8c84..3df4eaf9 100644
--- a/rust/tvm-ffi/Cargo.toml
+++ b/rust/tvm-ffi/Cargo.toml
@@ -33,6 +33,10 @@ paste = "1.0"
tvm-ffi-sys = { version = "0.1.0-alpha.0", path = "../tvm-ffi-sys" }
tvm-ffi-macros = { version = "0.1.0-alpha.0", path = "../tvm-ffi-macros" }
+[dev-dependencies]
+# The tests call the `testing.*` global functions.
+tvm-ffi-sys = { version = "0.1.0-alpha.0", path = "../tvm-ffi-sys", features =
["testing"] }
+
# only needed for example building
[features]
example = []