Skip to content
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
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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!");
Expand Down
28 changes: 19 additions & 9 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ pub fn run(language: Language, program: &str) -> Result<Assert, Box<dyn Error>>
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-");

#[cfg(target_os = "windows")]
output_temp.suffix(".exe");
if msvc {
output_temp.suffix(".exe");
}

let (_, output_path) = output_temp.tempfile()?.keep()?;

Expand All @@ -63,17 +66,24 @@ pub fn run(language: Language, program: &str) -> Result<Assert, Box<dyn Error>>
// arguments.

let compiler = build.try_get_compiler()?;
let mut command = compiler.to_command();
let mut command;

command_add_compiler_flags(&mut command, &variables);
if msvc {
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());

{
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.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.arg(&input_path);
command.envs(variables.clone());

let clang_output = command.output()?;
Expand Down