From 014aa3639223e0656834d7d469faad40291dd2aa Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Fri, 19 Sep 2025 14:43:47 +1200 Subject: Allow building Bedrock programs as standalone executables This commit adds a run_program() function to the root of the library. Any Bedrock program can be compiled as a standalone native executable by creating a thin Rust program that calls only that function, passing in the bytecode of the program and a configuration object. --- src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index f260042..20e4e4e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,3 +29,25 @@ pub const DEFAULT_SCREEN_SCALE: NonZeroU32 = unsafe { NonZeroU32::new_unchecked( pub type ScreenPosition = geometry::Point; pub type ScreenDimensions = geometry::Dimensions; + + +pub fn run_program(bytecode: &[u8], config: EmulatorConfig) { + let mut args = switchboard::Switchboard::from_env(); + args.named("verbose").short('v'); + if args.get("verbose").as_bool() { + log::set_log_level(log::LogLevel::Info); + } + + match Phosphor::new() { + Ok(phosphor) => { + info!("Starting graphical emulator"); + let mut emulator = GraphicalEmulator::new(config, false); + emulator.load_program(&bytecode); + emulator.run(phosphor, true); + } + Err(err) => { + eprintln!("EventLoopError: {err:?}"); + fatal!("Could not start graphical event loop"); + } + } +} -- cgit v1.2.3-70-g09d2