#msvc #windows-msvc #windows #vcruntime

no-std build static_vcruntime

Statically link the VCRuntime when using the MSVC toolchain

10 stable releases

2.0.0 Apr 20, 2022
1.5.1 Apr 23, 2021
1.1.0 Mar 30, 2021

#189 in Build Utils

Download history 1898/week @ 2024-08-14 1736/week @ 2024-08-21 1703/week @ 2024-08-28 2019/week @ 2024-09-04 2069/week @ 2024-09-11 2024/week @ 2024-09-18 2220/week @ 2024-09-25 2110/week @ 2024-10-02 1862/week @ 2024-10-09 2426/week @ 2024-10-16 1962/week @ 2024-10-23 1505/week @ 2024-10-30 1668/week @ 2024-11-06 1958/week @ 2024-11-13 2457/week @ 2024-11-20 1939/week @ 2024-11-27

8,384 downloads per month
Used in 10 crates

MIT OR Apache-2.0 OR Zlib

8KB

Statically link the VCRuntime when using the MSVC toolchain.

By default, Rust requires programs to deploy vcruntime140.dll (or equivalent) when redistributing binaries. This crate statically links the library instead.

Usage

Add this to your Cargo.toml:

[build-dependencies]
static_vcruntime = "2.0"

And in your build script:

fn main() {
    static_vcruntime::metabuild();
}

That is all. Then when you build a release binary, the runtime will be statically linked:

cargo build --release

Issues

If you have problems then you may need to clean the build directory before rebuilding:

cargo clean

If all else fails then, in the same directory as your Cargo.toml, create a folder called .cargo. In that folder create the file config.toml and add the following:

[target.'cfg(all(windows, target_env = "msvc"))']
rustflags = ["-C", "target-feature=+crt-static"]

This makes it easier to override the defaults.

No runtime deps