rustrust-cargo

Why don't I have a standard config.toml


So I wanted to set the number of jobs that the Rust compiler uses, and I heard it should go in config.toml. Furthermore config.toml should be in:

$CARGO_HOME/config.toml which defaults to:

Windows: %USERPROFILE%\.cargo\config.toml
Unix: $HOME/.cargo/config.toml

The closest things I have are three files names like this:

/home/myname/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cfg-expr-0.15.8/.cargo/config.toml

That's not the one right? My understanding is that Cargo looks for a config.toml in the current directory and then recursively up one folder until it reaches root. I don't even know what it's using as I don't see a file named config.toml, and anyway the system-wide search only showed what I pasted above. Where is this config.toml file? Two of the config.toml files are really small that set a couple of flags, and then the one under cfg-expr-0.15.8/.cargo looks like:

[target.'cfg(all())']
rustflags = [
    # BEGIN - Embark standard lints v6 for Rust 1.55+
    # do not change or add/remove here, but one can add exceptions after this section
    # for more info see: <https://github.com/EmbarkStudios/rust-ecosystem/issues/59>
    "-Dunsafe_code",
    "-Wclippy::all",
    "-Wclippy::await_holding_lock",
    "-Wclippy::char_lit_as_u8",
    "-Wclippy::checked_conversions",
    "-Wclippy::dbg_macro",
    "-Wclippy::debug_assert_with_mut_call",
    "-Wclippy::doc_markdown",
    "-Wclippy::empty_enum",
    "-Wclippy::enum_glob_use",
    "-Wclippy::exit",
    "-Wclippy::expl_impl_clone_on_copy",
    "-Wclippy::explicit_deref_methods",
    "-Wclippy::explicit_into_iter_loop",
    "-Wclippy::fallible_impl_from",
    "-Wclippy::filter_map_next",
    "-Wclippy::flat_map_option",
    "-Wclippy::float_cmp_const",
    "-Wclippy::fn_params_excessive_bools",
    "-Wclippy::from_iter_instead_of_collect",
    "-Wclippy::if_let_mutex",
    "-Wclippy::implicit_clone",
    "-Wclippy::imprecise_flops",
    "-Wclippy::inefficient_to_string",
    "-Wclippy::invalid_upcast_comparisons",
    "-Wclippy::large_digit_groups",
    "-Wclippy::large_stack_arrays",
    "-Wclippy::large_types_passed_by_value",
    "-Wclippy::let_unit_value",
    "-Wclippy::linkedlist",
    "-Wclippy::lossy_float_literal",
    "-Wclippy::macro_use_imports",
    "-Wclippy::manual_ok_or",
    "-Wclippy::map_err_ignore",
    "-Wclippy::map_flatten",
    "-Wclippy::map_unwrap_or",
    "-Wclippy::match_on_vec_items",
    "-Wclippy::match_same_arms",
    "-Wclippy::match_wild_err_arm",
    "-Wclippy::match_wildcard_for_single_variants",
    "-Wclippy::mem_forget",
    "-Wclippy::mismatched_target_os",
    "-Wclippy::missing_enforced_import_renames",
    "-Wclippy::mut_mut",
    "-Wclippy::mutex_integer",
    "-Wclippy::needless_borrow",
    "-Wclippy::needless_continue",
    "-Wclippy::needless_for_each",
    "-Wclippy::option_option",
    "-Wclippy::path_buf_push_overwrite",
    "-Wclippy::ptr_as_ptr",
    "-Wclippy::rc_mutex",
    "-Wclippy::ref_option_ref",
    "-Wclippy::rest_pat_in_fully_bound_structs",
    "-Wclippy::same_functions_in_if_condition",
    "-Wclippy::semicolon_if_nothing_returned",
    "-Wclippy::single_match_else",
    "-Wclippy::string_add_assign",
    "-Wclippy::string_add",
    "-Wclippy::string_lit_as_bytes",
    "-Wclippy::string_to_string",
    "-Wclippy::todo",
    "-Wclippy::trait_duplication_in_bounds",
    "-Wclippy::unimplemented",
    "-Wclippy::unnested_or_patterns",
    "-Wclippy::unused_self",
    "-Wclippy::useless_transmute",
    "-Wclippy::verbose_file_reads",
    "-Wclippy::zero_sized_map_values",
    "-Wfuture_incompatible",
    "-Wnonstandard_style",
    "-Wrust_2018_idioms",
    # END - Embark standard lints v6 for Rust 1.55+

Edit: OK, I've discovered that Cargo also looks for files just named "config" without the ".toml", well in my cargo home there's no config file, only a bunch of "config.yml" and "config.rs", along with the three "config.toml" that I mentioned, but isn't in the cargo home folder, it's in some long-winded path down.


Solution

  • The "config.toml" file in your home path (plus ".cargo") is optional.

    If you don't have one and you want to set some option, you simply create one.