Skip to content
Open
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
22 changes: 19 additions & 3 deletions src/exa/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,24 @@ use rand_distr::Alphanumeric;
use std::process::{Command, Stdio};
use std::thread;

#[cfg(windows)]
use std::os::windows::process::CommandExt;

use crate::Equation;

/// Windows flag to prevent console window from appearing
#[cfg(windows)]
const CREATE_NO_WINDOW: u32 = 0x08000000;

/// Creates a new Command with platform-specific settings to hide console windows on Windows
#[allow(unused_mut)]
fn new_command(program: &str) -> Command {
let mut cmd = Command::new(program);
#[cfg(windows)]
cmd.creation_flags(CREATE_NO_WINDOW);
cmd
}

/// Compiles model text into a dynamically loadable library.
///
/// This function creates a Rust project from a template, injects the model text,
Expand Down Expand Up @@ -170,7 +186,7 @@ fn create_template(temp_dir: PathBuf) -> Result<PathBuf, io::Error> {
);

if !template_dir.exists() {
let output = Command::new("cargo")
let output = new_command("cargo")
.arg("new")
.arg("template")
.arg("--lib")
Expand Down Expand Up @@ -250,7 +266,7 @@ fn inject_model<E: Equation>(
.join(", ")
);
fs::write(lib_rs_path, lib_rs_content)?;
Command::new("cargo")
new_command("cargo")
.arg("fmt")
.current_dir(&template_dir)
.output()
Expand All @@ -272,7 +288,7 @@ fn build_template(
template_path: PathBuf,
event_callback: Arc<dyn Fn(String, String) + Send + Sync + 'static>,
) -> Result<PathBuf, io::Error> {
let mut command = Command::new("cargo");
let mut command = new_command("cargo");
command
.arg("build")
.arg("--release")
Expand Down