diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-21 11:08:50 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-21 11:08:50 +0000 |
| commit | 7b94b9003daa1126ce78df37481fc52774c2f0b4 (patch) | |
| tree | c5e491c2a33d031da2f3400143ec74dab437e291 /bundle/src-tauri/src/main.rs | |
| parent | 5a254e2ab4741bc88c373ae1673c2ad9a7e6a588 (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'bundle/src-tauri/src/main.rs')
| -rw-r--r-- | bundle/src-tauri/src/main.rs | 50 |
1 files changed, 47 insertions, 3 deletions
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<String, String> { 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<OutputEvent>, + 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::<Runner>().stop()); + } + }); } |
