rustrust-cargo

how to specify conditional rustflags in cargo config file


I need to add

"-C link-arg /STACK:4000000"

but only for windows builds. I could not follow the cargo book and could not find any sample config.toml files.


Solution

  • You can define some target-specific properties via [target.<TARGET>] sections. The Cargo configuration documentation shows what fields are possible there:

    [target.<triple>]
    linker = "…"              # linker to use
    runner = "…"              # wrapper to run executables
    rustflags = ["…", "…"]    # custom flags for `rustc`
    rustdocflags = ["…", "…"] # custom flags for `rustdoc`
    

    So you would want something like this in your ./.cargo/config.toml:

    [target.x86_64-pc-windows-msvc]
    rustflags = ["-C", "link-arg", "/STACK:4000000"]