From 7b94b9003daa1126ce78df37481fc52774c2f0b4 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Wed, 21 Oct 2026 11:08:50 +0000 Subject: feat(bundle): run the bundled compiler with input and streaming output Save before running, close prefilled stdin at EOF, and stream output bytes through Tauri channels. Stop and reap the child before exit or another run. Disable embedded stdout buffering and exercise the runner with real programs. Co-Authored-By: Claude Opus 5.5 --- bundle/src-tauri/src/main.rs | 50 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'bundle/src-tauri/src/main.rs') diff --git a/bundle/src-tauri/src/main.rs b/bundle/src-tauri/src/main.rs index 34b1b70..96f040c 100644 --- a/bundle/src-tauri/src/main.rs +++ b/bundle/src-tauri/src/main.rs @@ -1,5 +1,9 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +mod runner; +use runner::{OutputEvent, Runner}; +use tauri::{ipc::Channel, Manager, State}; + #[tauri::command] fn read_file(path: String) -> Result { std::fs::read_to_string(path).map_err(|error| error.to_string()) @@ -10,10 +14,50 @@ fn write_file(path: String, text: String) -> Result<(), String> { std::fs::write(path, text).map_err(|error| error.to_string()) } +#[tauri::command] +async fn run_file( + path: String, + input: String, + output: Channel, + runner: State<'_, Runner>, +) -> Result<(), String> { + let executable = std::env::current_exe() + .map_err(|error| error.to_string())? + .with_file_name(if cfg!(windows) { "cpsc.exe" } else { "cpsc" }); + let result = runner + .run(executable, path.into(), input, |stream, bytes| { + let _ = output.send(OutputEvent::Data { + stream: stream.into(), + bytes, + }); + }) + .await?; + output + .send(OutputEvent::Finished { + code: result.code, + stopped: result.stopped, + }) + .map_err(|error| error.to_string()) +} + +#[tauri::command] +async fn stop_run(runner: State<'_, Runner>) -> Result<(), String> { + runner.stop().await; + Ok(()) +} + fn main() { tauri::Builder::default() .plugin(tauri_plugin_dialog::init()) - .invoke_handler(tauri::generate_handler![read_file, write_file]) - .run(tauri::generate_context!()) - .expect("Could not start CPSC Bundle"); + .manage(Runner::default()) + .invoke_handler(tauri::generate_handler![ + read_file, write_file, run_file, stop_run + ]) + .build(tauri::generate_context!()) + .expect("Could not start CPSC Bundle") + .run(|app, event| { + if matches!(event, tauri::RunEvent::ExitRequested { .. }) { + tauri::async_runtime::block_on(app.state::().stop()); + } + }); } -- cgit v1.3.1-4-g156e