First, there is a big difference between development and release. Your development configuration should be focused on low build times, and your release configuration should be focused on portability.
Bevy
recommends using the "dynamic"
feature for low build times. If you want to compile for release, though, you should remove that flag. This is most likely where most of your problems come from.
Another problem that arises is that by default, Rust on Windows depends on the MSVC Runtime. You might want to enable static runtime linking to compile the runtime into the executable. This increases its size a little, but that should be fine.
The best way to enable static runtime linking on windows is to create the file .cargo/config.toml
in your project directory, and then paste into it:
[target.x86_64-pc-windows-msvc]
rustflags = ["-Ctarget-feature=+crt-static"]
So to sum up:
- Remove the
"dynamic"
flag from bevy
- Build with the
crt-static
flag
Then, you should be able to copy-paste your binary to arbitrary windows systems.
Note, however, that further dependencies of your project could introduce new runtime dependencies. You might have to deliver the respective .dll
files with your executable, then; this is common practice for games.
Further remarks
You can check for runtime dependencies with the ldd
tool in git-bash
.
Using it on my executable without +crt-static
shows:
> ldd target/release/<my cratename>.exe
ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffc8c410000)
KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ffc8afc0000)
KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ffc89d80000)
bcrypt.dll => /c/WINDOWS/System32/bcrypt.dll (0x7ffc89d00000)
ucrtbase.dll => /c/WINDOWS/System32/ucrtbase.dll (0x7ffc8a370000)
VCRUNTIME140.dll => /c/WINDOWS/SYSTEM32/VCRUNTIME140.dll (0x7ffc6cba0000)
After linking with +crt-static
, it shows:
> ldd target/release/<my cratename>.exe
ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffc8c410000)
KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ffc8afc0000)
KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ffc89d80000)
bcrypt.dll => /c/WINDOWS/System32/bcrypt.dll (0x7ffc89d00000)