bevy icon indicating copy to clipboard operation
bevy copied to clipboard

The `dynamic_linking` feature doesn't produce a Windows exe which can easily run outside Cargo

Open djeedai opened this issue 1 year ago • 4 comments

Bevy version

0.12.1

[Optional] Relevant system information

Win11

What you did

Try to run program.exe from either the target/debug or the target/debug/deps folder.

What went wrong

Program fails to start:

  • Missing bevy_dylib-34dfd29b56be4d40.dll if not in deps/.
  • Missing std-5a4aac4b2cd4ff41.dll in both cases, and I have no idea where it is (nowhere under my project hierarchy, I assume somewhere in some Cargo cache?).

Additional information

It's all too complicated and requires too much tribal knowledge to run a simple application outside of cargo run. One example is hooking RenderDoc, but otherwise just simply to run it without having to open a terminal.

  • The application depends on a couple of DLLs in unknown locations.
  • The application is present in at least 2 folders (see above).
  • The application also has requirements on the working directory to find the assets/ folder.

Trying to match all requirements at once is extremely difficult, because you're limited to a single working directory (which is the simplest way to fix most of those issues). I probably managed to do it in the past, but I already forgot how, if it didn't change in the meantime.

Additionally it looks like some bevy_dylib.dll was copied in target/debug, possibly as an attempt to fix that (?), however the executable produced depends on the version with the hash, not the stripped one, as objdump confirmed:

> objdump -x program.exe | findstr DLL
        DLL Name: bevy_dylib-34dfd29b56be4d40.dll
        DLL Name: std-5a4aac4b2cd4ff41.dll
        DLL Name: SHLWAPI.dll
        DLL Name: kernel32.dll
        DLL Name: user32.dll
        DLL Name: ole32.dll
        DLL Name: oleaut32.dll
        DLL Name: VCRUNTIME140.dll
        DLL Name: api-ms-win-crt-math-l1-1-0.dll
        DLL Name: api-ms-win-crt-runtime-l1-1-0.dll
        DLL Name: api-ms-win-crt-stdio-l1-1-0.dll
        DLL Name: api-ms-win-crt-locale-l1-1-0.dll
        DLL Name: api-ms-win-crt-heap-l1-1-0.dll

I couldn't find any relevant (enough) information in documentations. On docs.rs, there's no mention of dynamic_linking anywhere. On the Bevy website, there's the following note:

NOTE: Remember to revert this before releasing your game! Otherwise you will need to include libbevy_dylib alongside your game if you want it to run. If you remove the "dynamic" feature, your game executable can run standalone.

But it falls short of giving enough information for the user to actually fix the issue as 1) the location of the DLL is not explained, and 2) as shown above this is not enough, you also need std-xxx.dll.

djeedai avatar Dec 15 '23 13:12 djeedai

This is due to library search paths and affects all OS. I get around with via LD_LIBRARY_PATH on Linux. related https://github.com/rust-lang/cargo/issues/4895

AxiomaticSemantics avatar Dec 19 '23 02:12 AxiomaticSemantics

https://github.com/bevyengine/bevy/issues/6723 same root issue.

AxiomaticSemantics avatar Jan 05 '24 22:01 AxiomaticSemantics

The std DLL is part of your Rust toolchain installation. If you are using Rustup, you can find it under the path where rustup installs your toolchain.

inodentry avatar Feb 05 '24 12:02 inodentry

Something interesting I found out - using a path dependency makes bevy_dylib get linked as bevy_dylib.dll (no hash!). The std still has the hash but that should certainly be stable unless you switch Rust versions.

Edit: using a git or crates.io dependency still results in the hashed dll.

andriyDev avatar Feb 12 '24 01:02 andriyDev