From dd554dff11e0d36b3012e531d3ebb1c9edd5eee4 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Thu, 20 Aug 2020 13:51:53 +0200 Subject: [PATCH] Allow to unset a default target by setting `build.target` to the empty string --- src/cargo/core/compiler/compile_kind.rs | 6 ++++- tests/testsuite/cross_compile.rs | 31 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/compile_kind.rs b/src/cargo/core/compiler/compile_kind.rs index 4c123601f8e..f099db8ec8f 100644 --- a/src/cargo/core/compiler/compile_kind.rs +++ b/src/cargo/core/compiler/compile_kind.rs @@ -72,7 +72,11 @@ impl CompileKind { } else { val.raw_value().to_string() }; - CompileKind::Target(CompileTarget::new(&value)?) + if value == "" { + CompileKind::Host + } else { + CompileKind::Target(CompileTarget::new(&value)?) + } } None => CompileKind::Host, }; diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index fe573a88270..a854cec91fa 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -117,6 +117,37 @@ fn simple_cross_config() { } } +#[cargo_test] +fn unset_default_target() { + let p = project() + .file( + ".cargo/config", + r#" + [build] + target = "" + "#, + ) + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.0" + authors = [] + "#, + ) + .file( + "src/main.rs", + r#" + fn main() {{}} + "#, + ) + .build(); + + p.cargo("build -v").run(); + assert!(p.bin("foo").is_file()); +} + #[cargo_test] fn simple_deps() { if cross_compile::disabled() {