diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 94f9f8c5791..6f6fd627648 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -75,6 +75,11 @@ continuous integration systems.", pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { let mut compile_opts = args.compile_options(config, CompileMode::Build)?; + + // for `cargo-install` we want to use what the user specified via `--target` and ignore what's + // in `.cargo/config` and what the environment says + compile_opts.build_config.requested_target = args.target(); + compile_opts.build_config.release = !args.is_present("debug"); let krates = args.values_of("crate") diff --git a/src/doc/src/reference/config.md b/src/doc/src/reference/config.md index 1eaf4511e09..3bb4c68b3ff 100644 --- a/src/doc/src/reference/config.md +++ b/src/doc/src/reference/config.md @@ -100,7 +100,7 @@ check-revoke = true # Indicates whether SSL certs are checked for revocation jobs = 1 # number of parallel jobs, defaults to # of CPUs rustc = "rustc" # the rust compiler tool rustdoc = "rustdoc" # the doc generator tool -target = "triple" # build for the target triple +target = "triple" # build for the target triple (ignored by `cargo install`) target-dir = "target" # path of where to place all generated artifacts rustflags = ["..", ".."] # custom flags to pass to all compiler invocations incremental = true # whether or not to enable incremental compilation diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 0c5cb3f076f..1c3bed5a5c3 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -1237,3 +1237,31 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina ", ).run(); } + +#[test] +fn install_ignores_cargo_config() { + pkg("bar", "0.0.1"); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + authors = [] + "#, + ) + .file( + ".cargo/config", + r#" + [build] + target = "non-existing-target" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + cargo_process("install bar").cwd(p.root()).with_status(0).run(); + assert_has_installed_exe(cargo_home(), "bar"); +}