cargo test --doc
fails to link a test and I don't understand why. Versions 1.80.1, 1.81.0, +beta all fail.
I have a project with a package. The package has a build.rs
that downloads libone.a
and libtwo.a
. libone.a
depends on libtwo.a
. The package has a module with wrapper functions for the functions in libone.a
.
The rust unittests exercising the C API run fine:
$ cargo test -r -p packageA moduleA::test::filter_ --lib
I add a doctest which simply calls one of the wrapper functions and it can't be linked:
$ cargo test -r -p packageA --doc
...
/usr/bin/ld: /home/me/project/target/release/build/packageA-xxxx/out/libone.a(entrypoint.cc.o): in function `functionA':
/home/me/full-original-path-to/entrypoint.cc:178: undefined reference to `some::namespace::SomeClass::someFunction()'
Strangely, the objects from libone.a
are found, but not the ones from libtwo.a
even though the cc
linking command is instructed to use both: -lone -ltwo "-L" "/home/me/project/target/release/build/packageA-xxxx/out"
.
I'm trying to debug the cc command but when I run it manually, I get this error:
/usr/bin/ld: cannot open output file /tmp/rustdoctesttpJF2c/rust_out: No such file or directory
How exactly can I run cargo test -r -p packageA --doc
such that it does not remove the directory it creates in /tmp? I've seen some mentions of -Csave-temps
but I can't figure out how to use it. Where do I put it?
Any idea why this might fail?
If I use cargo +nightly
as opposed to cargo 1.80.1
, the same doctest can be linked and passes! I tried cargo clean
but I still get the same broken behavior with 1.80.1
. cargo +beta
also fails.
Using Build Scripts - The Cargo Book in build.rs or linking like this makes no difference:
#[link(name = "one")]
#[link(name = "two")]
extern "C" { ... }