From 6148dfebc0896086c7328114af336d42756e26c9 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 13 Nov 2020 15:13:42 +0100 Subject: [PATCH 1/5] fix: On some Linux, `cc` expects the input argument to come before other options. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For instance, the following will fail: ``` cc -I<…> -L<…> -Wl,l<…> -o test test.c ``` But the following will work: ``` cc test.c -I<…> -L<…> -Wl,l<…> -o test ``` This patch puts the input path first, before everything. --- src/run.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/run.rs b/src/run.rs index c76fbc3..2c22e42 100644 --- a/src/run.rs +++ b/src/run.rs @@ -32,6 +32,8 @@ pub fn run(language: Language, program: &str) -> Result> let host = target_lexicon::HOST.to_string(); let target = &host; + let msvc = target.contains("msvc"); + let (_, input_path) = program_file.keep()?; let mut output_temp = tempfile::Builder::new(); let output_temp = output_temp.prefix("inline-c-rs-"); @@ -63,17 +65,13 @@ pub fn run(language: Language, program: &str) -> Result> // arguments. let compiler = build.try_get_compiler()?; - let mut command = compiler.to_command(); + let mut command = Command::new(compiler.path()); + command.arg(input_path.clone()); // the input must come first + command.args(compiler.args()); command_add_compiler_flags(&mut command, &variables); + command_add_output_file(&mut command, &output_path, msvc, compiler.is_like_clang()); - { - let msvc = target.contains("msvc"); - let clang = compiler.is_like_clang(); - command_add_output_file(&mut command, &output_path, msvc, clang); - } - - command.arg(&input_path); command.envs(variables.clone()); let clang_output = command.output()?; From 2118ed6244a32cabbca13cc9e6d0f3eab36de113 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 13 Nov 2020 16:48:34 +0100 Subject: [PATCH 2/5] chore: Remove a warning on Windows. --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 581fe02..6ba2080 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,6 @@ mod tests { use super::predicates::*; use super::*; use crate as inline_c; - use std::env::{remove_var, set_var}; #[test] fn test_c_macro() { @@ -81,6 +80,8 @@ mod tests { #[cfg(not(target_os = "windows"))] #[test] fn test_c_macro_with_env_vars_from_env_vars() { + use std::env::{remove_var, set_var}; + // Define env vars through env vars. set_var("INLINE_C_RS_FOO", "bar baz qux"); set_var("INLINE_C_RS_HELLO", "World!"); From b80d9289eba9678a1ff24e95583ee491da4ba0cc Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 13 Nov 2020 16:48:53 +0100 Subject: [PATCH 3/5] fix: Try to debug on Windows. --- src/run.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run.rs b/src/run.rs index 2c22e42..efe7ddf 100644 --- a/src/run.rs +++ b/src/run.rs @@ -67,8 +67,8 @@ pub fn run(language: Language, program: &str) -> Result> let compiler = build.try_get_compiler()?; let mut command = Command::new(compiler.path()); - command.arg(input_path.clone()); // the input must come first command.args(compiler.args()); + command.arg(input_path.clone()); // the input must come first command_add_compiler_flags(&mut command, &variables); command_add_output_file(&mut command, &output_path, msvc, compiler.is_like_clang()); From 2aab93a40a5305c1f7dccfc6f9f8872bd4872e2f Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 13 Nov 2020 17:35:26 +0100 Subject: [PATCH 4/5] fix: Try debug on Windows. --- src/run.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/run.rs b/src/run.rs index efe7ddf..942948e 100644 --- a/src/run.rs +++ b/src/run.rs @@ -38,8 +38,9 @@ pub fn run(language: Language, program: &str) -> Result> let mut output_temp = tempfile::Builder::new(); let output_temp = output_temp.prefix("inline-c-rs-"); - #[cfg(target_os = "windows")] - output_temp.suffix(".exe"); + if msvc { + output_temp.suffix(".exe"); + } let (_, output_path) = output_temp.tempfile()?.keep()?; @@ -65,12 +66,19 @@ pub fn run(language: Language, program: &str) -> Result> // arguments. let compiler = build.try_get_compiler()?; - let mut command = Command::new(compiler.path()); - command.args(compiler.args()); - command.arg(input_path.clone()); // the input must come first - command_add_compiler_flags(&mut command, &variables); - command_add_output_file(&mut command, &output_path, msvc, compiler.is_like_clang()); + + if msvc { + command.args(compiler.args()); + command_add_compiler_flags(&mut command, &variables); + command_add_output_file(&mut command, &output_path, msvc, compiler.is_like_clang()); + command.arg(input_path.clone()); + } else { + command.arg(input_path.clone()); // the input must come first + command.args(compiler.args()); + command_add_compiler_flags(&mut command, &variables); + command_add_output_file(&mut command, &output_path, msvc, compiler.is_like_clang()); + } command.envs(variables.clone()); From 31d757e21cc1858ee88a302d42b9de8abc6f3511 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 16 Nov 2020 09:18:51 +0100 Subject: [PATCH 5/5] fix: Try to debug on Windows. --- src/run.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/run.rs b/src/run.rs index 942948e..24e8105 100644 --- a/src/run.rs +++ b/src/run.rs @@ -66,14 +66,18 @@ pub fn run(language: Language, program: &str) -> Result> // arguments. let compiler = build.try_get_compiler()?; - let mut command = Command::new(compiler.path()); + let mut command; if msvc { - command.args(compiler.args()); + command = compiler.to_command(); + command_add_compiler_flags(&mut command, &variables); command_add_output_file(&mut command, &output_path, msvc, compiler.is_like_clang()); command.arg(input_path.clone()); + command.envs(variables.clone()); } else { + command = Command::new(compiler.path()); + command.arg(input_path.clone()); // the input must come first command.args(compiler.args()); command_add_compiler_flags(&mut command, &variables);