Cargo test when invoking rustdoc (for the documentation tests) ignores the rustc-link-lib set from the build script

When linking a library statically (stdc++) with a library crate, we need to add this:

println!("cargo:rustc-link-lib=static=stdc++");

However, if specified like this, the unit tests work fine, but the doc-tests fail due to being unable to locate many-many symbols from the stdc++ within the crate library.

It can be fixed by linking the whole archive:

println!("cargo:rustc-link-lib=static:-bundle,+whole-archive=stdc++");

But this seems to be a little redundant.

The question is if this is intended. If not, I wonder how one is assumed to be correctly linking then to avoid the problem for the doc-tests?