Hi,
I've been spending a few hours investigating this issue. This is what I
have up to now:
The issue happens when rustdoc tries to run the tests that are embedded
in the docs. For example, this is one of the many failing tests:
/// Rounds each lane in the style specified.
///
/// ```
/// # use safe_arch::*;
/// let a = m128::from_array([-0.1, 1.6, 3.3, 4.5]);
/// //
/// assert_eq!(round_m128::<{ round_op!(Nearest) }>(a).to_array(), [0.0,
2.0, 3.0, 4.0]);
/// //
/// assert_eq!(round_m128::<{ round_op!(NegInf) }>(a).to_array(), [-1.0,
1.0, 3.0, 4.0]);
/// //
/// assert_eq!(round_m128::<{ round_op!(PosInf) }>(a).to_array(), [0.0,
2.0, 4.0, 5.0]);
/// //
/// assert_eq!(round_m128::<{ round_op!(Zero) }>(a).to_array(), [0.0,
1.0, 3.0, 4.0]);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docsrs, doc(cfg(target_feature = "sse4.1")))]
pub fn round_m128<const MODE: i32>(a: m128) -> m128 {
m128(unsafe { _mm_round_ps(a.0, MODE) })
}
It fails because the function is not defined, and the function is not
defined because the code is compiled depending on the features of the
architecture. The machine I'm using for this test doesn't support sse4.1
and thus this code (and the other failing ones) is not compiled in my
machine.
Looking at the heading there, it seems to be trying to only run these
tests if the target feature is enabled, but for some reason that part is
not working.
These files are included in src/lib.rs with stanzas like this one:
#[cfg(target_feature = "sse4.1")]
submodule!(pub sse4_1);
In my laptop, if I comment out the inclusion of sse4_1, avx2 and fma in
that file, the build works successfully. Why don't I need to comment out
sse4.2? Because that one doesn't include tests. i.e. not all the files
include tests, but for the files that do, if the package is compiled for
a CPU that doesn't support that feature, the tests fail.
I found this piece of documentation:
https://doc.rust-lang.org/rustdoc/advanced-features.html
Basically it says that using #[cfg(doc)] will cause the documentation to
be generated even if the feature is not enabled, but this is not passed
to doctests.
And then I found this other piece:
https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html
Which seems to do exactly what would be desired: document the feature as
only available on a condition, while not running the tests when the
condition is not enabled. Unfortunately, that feature is "unstable".
This is work in progress and I guess the interface might change.
The build that worked until mid-2024 was using a previous version of
Rust (1.79 was the last success in July 2024 vs 1.84 the first failure
in December), and also a different configuration for doc generation, as
this commit was included after the new upstream release:
https://github.com/Lokathor/safe_arch/pull/115/commits/d81e8bbd9fd7b41497c3b0bd8a27285e8840d4d5
I also found this issue which seems to explain the reason for the above
mentioned commit that changed the configuration:
https://github.com/rust-lang/cargo/issues/13875
i.e. rustdoc now always passes --cfg docsrs, without it needing to be
specified. Looking at the failing invocation (seen in the output pasted
by Santiago in #1092391), we see that it's passing: --check-cfg
'cfg(docsrs)'
At this point, I'm stuck. It seems like the package is following the
standards and it should work, but it doesn't. Anyway, I'll keep
investigating, but sending this now in case anybody else is looking at
this and has any ideas.
--
Regards,
Marga