Skip to content

Doctests fail with cross compilation, causing test_in_svsm builds to fail to compile with rust nightly toolchain 2025-05-17 and later #705

@AdamCDunlap

Description

@AdamCDunlap

Prior to nightly-2025-05-17, rust would not compile doctests as part of cargo test when cross compiling. In this toolchain version, that was fixed so doctests are part of it: rust-lang/cargo#15462. When building the "test_in_svsm" binaries (e.g. make bin/test-kernel.elf), cargo test is invoked to cross compile the unit tests. With the nightly-2025-05-17 toolchain, this therefore tries to build the doctests for the x86_64-unknown-none target. However, these tests fail to compile on that target. This is partly due to them not specifying no_std, but even if that is given there are other errors.

These are a few options for resolving:

  1. Use the environment variable RUSTDOC=true for cargo test, which makes cargo think there are no doctests at all. This basically replicates what the toolchain was doing anyway prior to this version.
  2. Edit the problematic doctests (which may be all of them?) to have per-target ignores to say they shouldn't be cross-compiled.
  3. Set up our unit test runner to work with doctests as well. I don't know why unit tests and doctest are treated differently, but hopefully a lot of the same infrastructure can be shared. I spent a bit of time trying to do this, but it was nontrivial for me. I also found this comment indicating that doctest integration with custom test runners is not supported, so this might just not be possible at the moment.

I'm inclined to send in a PR for option 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions