diff --git a/src/lib.rs b/src/lib.rs index 9abcc4915..c56888d31 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1171,6 +1171,9 @@ impl Build { if !msvc || !is_asm || !is_arm { cmd.arg("-c"); } + if !msvc || compiler.family == (ToolFamily::Msvc { clang_cl: true }) { + cmd.arg("--"); // #513: For non-MSVC, separate flags/options from the input file. + } cmd.arg(&obj.src); run(&mut cmd, &name)?; diff --git a/tests/support/mod.rs b/tests/support/mod.rs index cde930e90..b56f7d7c3 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -151,6 +151,15 @@ impl Execution { }; self } + + pub fn must_end_with>(&self, p: &[P]) -> &Execution { + let expected = p.iter().map(|x| x.as_ref()).collect::>(); + if !self.args.iter().map(|x| OsStr::new(x)).collect::>().as_slice().ends_with(expected.as_slice()) { + panic!("did not end with {:?}", expected); + } else { + self + } + } } /// Hard link an executable or copy it if that fails. diff --git a/tests/test.rs b/tests/test.rs index 3c9b4dc49..e86e2130b 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -343,6 +343,14 @@ fn gnu_static() { test.cmd(0).must_have("-static").must_not_have("-shared"); } +#[test] +fn gnu_dash_dash() { + let test = Test::gnu(); + test.gcc().file("foo.c").compile("foo"); + + test.cmd(0).must_end_with(&["--", "foo.c"]); +} + #[test] fn msvc_smoke() { reset_env(); @@ -411,3 +419,11 @@ fn msvc_no_static_crt() { test.cmd(0).must_have("-MD"); } + +#[test] +fn msvc_no_dash_dash() { + let test = Test::msvc(); + test.gcc().file("foo.c").compile("foo"); + + test.cmd(0).must_not_have("--"); +}