#windows-msvc #link #msvc #compile-time #build-script #windows

no-std build link_args

Allows setting linker arugments at compile time without a build script. Currently only supports Windows MSVC toolchains.

5 unstable releases

0.6.0 Mar 29, 2021
0.5.1 Mar 27, 2021
0.5.0 Mar 27, 2021
0.4.1 Mar 24, 2021
0.4.0 Mar 24, 2021

#556 in Build Utils

Download history 43/week @ 2024-11-15 50/week @ 2024-11-22 170/week @ 2024-11-29 125/week @ 2024-12-06 403/week @ 2024-12-13 109/week @ 2024-12-20 30/week @ 2024-12-27 125/week @ 2025-01-03 208/week @ 2025-01-10 237/week @ 2025-01-17 161/week @ 2025-01-24 297/week @ 2025-01-31 396/week @ 2025-02-07 497/week @ 2025-02-14 525/week @ 2025-02-21 255/week @ 2025-02-28

1,763 downloads per month
Used in 3 crates

MIT OR Apache-2.0 OR Zlib

22KB
331 lines

Allows setting linker arugments at compile time without a build script. Currently only supports Windows MSVC toolchains.

Minimum Rust version: 1.51

Usage

Add this to your Cargo.toml:

[dependencies]
link_args = "0.6"

Examples

Set the stack size

// Reserve 8 MiB for the stack.
link_args::windows_msvc::stack_size!(0x800000);

Add a library

link_args::windows_msvc::default_lib!("kernel32.lib");

lib.rs:

Allows setting linker arugments at compile time without a build script. Currently only supports Windows MSVC toolchains.

Usage

Add this to your Cargo.toml:

[dependencies]
link_args = "0.6"

Examples

Put these examples at the root of your main.rs or lib.rs.

Set the size of the stack

Reserve 8 MiB (8,388,608 bytes) of virtual memory for the stack. This should only be set for crates that produce a .exe or .dll binary.

link_args::windows::stack_size!(0x800000);

Add a default library

Add "kernel32.lib" to the libraries that are serached for symbols.

link_args::windows::default_lib!("kernel32.lib");

Use the windows! macro

The windows! macro lets you set multiple arguments at once.

link_args::windows! {
    stack_size(0x800000);
    default_lib("kernel32.lib");
}

If you use unsafe linker arguments the you must mark the whole block as unsafe.

// Only set these in release mode.
#[cfg(not(debug_assertions))]
link_args::windows! {
    // Some of these linker args are unsafe so we have to use
    // an `unsafe` block.
    unsafe {
        // Link the ucrt dynamically and vcruntime statically.
        default_lib("ucrt", "libvcruntime", "libcmt");
        // Disable the other C runtime libraries.
        no_default_lib(
            "libvcruntimed.lib", "vcruntime.lib", "vcruntimed.lib",
            "libcmtd.lib", "msvcrt.lib", "msvcrtd.lib",
            "libucrt.lib", "libucrtd.lib", "ucrtd.lib",
        );
    }
}
<style>#macros + table > tbody > tr:not(:first-child) { display: none !important; }</style>

No runtime deps