From 3b94f44ec4c97c8ad27e3f8bff8fd67ea6275c34 Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Thu, 28 Jun 2018 18:34:12 -0700 Subject: [PATCH 1/2] Revert "`cargo install` will ignore the target triple specified in a project directory" This reverts commit 1bad99180aa71f9e0db1dd1629e53beb58ca65b3. --- src/bin/cargo/commands/install.rs | 3 --- tests/testsuite/install.rs | 32 ------------------------------- 2 files changed, 35 deletions(-) diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index f5af6435618..f0c65515d2f 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -74,9 +74,6 @@ continuous integration systems.", pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { let mut compile_opts = args.compile_options(config, CompileMode::Build)?; compile_opts.build_config.release = !args.is_present("debug"); - // We override target architecture to host architecture since it may be - // set to some other architecture in .cargo/config. - compile_opts.build_config.requested_target = None; let krates = args.values_of("crate") .unwrap_or_default() diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 78df8638c50..0559c570440 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -1606,35 +1606,3 @@ fn git_repo_replace() { .contains(&format!("{}", new_rev)) ); } - -#[test] -fn install_with_non_existent_target() { - pkg("bar", "0.0.1"); - - let p = project("foo") - .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(); - - assert_that( - cargo_process("install").arg("bar").cwd(p.root()), - execs().with_status(0), - ); - assert_that(cargo_home(), has_installed_exe("bar")); -} - From 0774e97da3894f07ed5b6f7db175027a9bc4718b Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Thu, 28 Jun 2018 18:57:24 -0700 Subject: [PATCH 2/2] Support cross-compile install --- src/bin/cargo/commands/install.rs | 1 + tests/testsuite/install.rs | 35 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index f0c65515d2f..efac1a940c7 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -32,6 +32,7 @@ pub fn cli() -> App { "Install only the specified example", "Install all examples", ) + .arg_target_triple("Build for the target triple") .arg(opt("root", "Directory to install packages into").value_name("DIR")) .after_help( "\ diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 0559c570440..25ee7f1e16f 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -4,6 +4,7 @@ use std::io::prelude::*; use cargo::util::ProcessBuilder; use cargotest::install::{cargo_home, has_installed_exe}; +use cargotest::support::cross_compile; use cargotest::support::git; use cargotest::support::paths; use cargotest::support::registry::Package; @@ -1334,6 +1335,40 @@ fn dev_dependencies_lock_file_untouched() { assert!(lock == lock2, "different lockfiles"); } +#[test] +fn install_target_native() { + pkg("foo", "0.1.0"); + + assert_that( + cargo_process("install") + .arg("foo") + .arg("--target") + .arg(cargotest::rustc_host()), + execs() + .with_status(0), + ); + assert_that(cargo_home(), has_installed_exe("foo")); +} + +#[test] +fn install_target_foreign() { + if cross_compile::disabled() { + return; + } + + pkg("foo", "0.1.0"); + + assert_that( + cargo_process("install") + .arg("foo") + .arg("--target") + .arg(cross_compile::alternate()), + execs() + .with_status(0), + ); + assert_that(cargo_home(), has_installed_exe("foo")); +} + #[test] fn vers_precise() { pkg("foo", "0.1.1");