lucifer1004 opened a new pull request, #825:
URL: https://github.com/apache/tvm-ffi/pull/825
## Why
`tvm-ffi-sys/build.rs` decides whether it is building documentation with
`env::var("RUSTDOC").is_ok()`. Cargo sets `RUSTDOC` for every build script
([Cargo: environment variables set for build
scripts](https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts)),
so the check is always true. It was meant for the Rust docs build in
`docs/conf.py` (#160).
As a result, a normal `cargo build` without a working `tvm-ffi-config`
doesn't fail. It prints "tvm-ffi-config not available, skipping for
documentation build" and emits no `rustc-link-*` directives. The first sign of
trouble is a link error in a dependent crate:
```
rust-lld: error: undefined symbol: TVMFFIEnvGetStream
```
Cargo also caches the empty build-script output. The build script declares
no `rerun-if-*`, so it reruns only when the package's own files change, and the
build keeps failing after tvm-ffi is installed until `cargo clean -p
tvm-ffi-sys`.
## What
- **Documentation builds:** detected by `DOCS_RS`, which docs.rs sets.
`docs/conf.py` now sets it too for its `cargo doc`, so docs still build without
tvm-ffi installed. In that case the build script emits a `cargo:warning` naming
the reason and doesn't link.
- **Every other build:** fails in the build script, with the reason and the
fix, when `tvm-ffi-config` cannot be run, exits non-zero (its stderr is
included), or prints no library directory:
```
could not run `tvm-ffi-config`: No such file or directory (os error 2).
tvm-ffi-sys links libtvm_ffi from the directory that `tvm-ffi-config --libdir`
prints: install tvm-ffi (e.g. `pip install apache-tvm-ffi`) and put
tvm-ffi-config on PATH. To build documentation only, set DOCS_RS=1.
```
- **Rerunning:** the build script declares its inputs with
`cargo:rerun-if-env-changed` (`DOCS_RS`, `PATH`, and the library-path variable
it reads) plus `rerun-if-changed=build.rs`, so output from one environment
isn't reused in another.
## Tests
A scratch crate that depends on `tvm-ffi-sys` and calls `TVMFFIEnvGetStream`:
- **On `main`, without `tvm-ffi-config`:** the build script runs with
`RUSTDOC=…/rustdoc` in its environment (`cargo build -vv`), its output has no
link directives, and the link fails with the undefined symbol above.
- **With this change:**
- Without `tvm-ffi-config`, the build fails in the build script with the
message above.
- `DOCS_RS=1 cargo doc` without `tvm-ffi-config` still builds, with the
warning.
- With `tvm-ffi-config`, the crate builds and runs, including right after
that `DOCS_RS=1` build: the build script reruns and links.
- `cargo test` in `rust/` passes (25 suites).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]