Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cross-compile install #5614

Merged
merged 2 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"\
Expand Down Expand Up @@ -74,9 +75,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()
Expand Down
67 changes: 35 additions & 32 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -1606,35 +1641,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"));
}