Skip to content

Using dynamic_linking on Windows breaks cargo test --doc #14129

Closed
@janhohenheim

Description

@janhohenheim

originally discovered in #13553

Bevy version

0.14.0

Relevant system information

  • Rust version: 1.80.0
  • OS: Windows 11
`AdapterInfo { name: "NVIDIA GeForce GTX 1080 Ti", vendor: 4318, device: 6918, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "555.99", backend: Vulkan }`

What you did

Cargo.toml
[package]
name = "minimal_doctest_fail"
version = "0.1.0"
edition = "2021"

[dependencies]
# remove the `dynamic_linking` feature to fix the issue.
bevy = { version = "0.14.0", features = ["dynamic_linking"] }

# Enable a small amount of optimization in debug mode
[profile.dev]
opt-level = 1

# Enable high optimizations for dependencies (incl. Bevy), but not for our code:
[profile.dev.package."*"]
opt-level = 3
lib.rs
/// ```
/// use bevy::prelude::*;
/// ```
pub struct Foo;

What went wrong

Running cargo test --doc results in a failure:

Test executable failed (exit code: 0xc0000135)

That exit code means that a dynamic library was not found. Indeed, removing the dynamic_linking feature fixes this.

Additional information

Quoting @SkiFire13 here:

@janhohenheim I can confirm that this results in the Test executable failed (exit code: 0xc0000135) error for me as well (tested with an empty .cargo/config.toml and no RUSTFLAGS or RUSTDOCFLAGS set).

I've also managed to further minimize the issue to remove the dependency on Bevy. You only need a crate depending on a dylib crate, and a doctest that uses any item from the dylib crate. SkiFire13/minimal_dylib_doctest_fail

I've also found this rust issue which seems to fit the problem rust-lang/rust#39487. It has been closed in favour of rust-lang/rustup#893, where it's mentioned that the issue is with the stdilb dll not being added to the path when running the test. Indeed if I either add %RUSTUP_HOME%\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\ to the PATH or copy the std-****.dll file in that directory to the directory where I'm running cargo test --doc then it works. However I wonder why this issue doesn't appear on Linux (I've tested on WSL and the same minimalized reproduction works fine without the workaround).

Since this breaks doctests for Windows users following Bevy's recommended settings, we should probably make readers aware of this. I opened bevyengine/bevy-website#1522 to add a little mention to the dynamic-on-Windows disclaimer we have anyways.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-Build-SystemRelated to build systems or continuous integrationC-BugAn unexpected or incorrect behaviorC-DocsAn addition or correction to our documentationC-TestingA change that impacts how we test Bevy or how users test their appsO-WindowsSpecific to the Windows desktop operating systemP-CrashA sudden unexpected crash

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions