cargo::core::compiler::build_context::target_info

Function extra_args

source
fn extra_args(
    gctx: &GlobalContext,
    requested_kinds: &[CompileKind],
    host_triple: &str,
    target_cfg: Option<&[Cfg]>,
    kind: CompileKind,
    flags: Flags,
) -> CargoResult<Vec<String>>
Expand description

Acquire extra flags to pass to the compiler from various locations.

The locations are:

  • the CARGO_ENCODED_RUSTFLAGS environment variable
  • the RUSTFLAGS environment variable

then if none of those were found

  • target.*.rustflags from the config (.cargo/config)
  • target.cfg(..).rustflags from the config
  • host.*.rustflags from the config if compiling a host artifact or without --target (requires -Zhost-config)

then if none of those were found

  • build.rustflags from the config

The behavior differs slightly when cross-compiling (or, specifically, when --target is provided) for artifacts that are always built for the host (plugins, build scripts, …). For those artifacts, only host.*.rustflags is respected, and no other configuration sources, regardless of the value of target-applies-to-host. This is counterintuitive, but necessary to retain backwards compatibility with older versions of Cargo.

Rules above also applies to rustdoc. Just the key would be rustdocflags/RUSTDOCFLAGS.