From 451c4f0fde830740365956cde3b82ab5e3125aa6 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sun, 26 Nov 2023 13:15:31 +1100 Subject: [PATCH] separate binaries --- Cargo.lock | 68 ++++++++++++------- Cargo.toml | 5 +- cli/Cargo.toml | 13 ++++ gb-emu/src/bin/cli.rs => cli/src/main.rs | 17 ++--- {gb-emu => frontend-common}/Cargo.toml | 16 +---- {gb-emu => frontend-common}/src/audio.rs | 0 {gb-emu => frontend-common}/src/camera.rs | 0 {gb-emu => frontend-common}/src/debug.rs | 0 {gb-emu => frontend-common}/src/lib.rs | 24 ++++--- {gb-emu => frontend-common}/src/window.rs | 0 .../src/window/winit_manager.rs | 0 gui/Cargo.toml | 19 ++++++ .../src}/macos/cacao_window_manager.rs | 5 +- {gb-emu/src/bin => gui/src}/macos/mod.rs | 13 ++-- .../src/bin => gui/src}/macos/preferences.rs | 0 .../src}/macos/preferences/toolbar.rs | 0 .../src}/macos/preferences/views.rs | 2 +- .../src}/macos/preferences/views/widgets.rs | 0 gb-emu/src/bin/gui.rs => gui/src/main.rs | 0 19 files changed, 108 insertions(+), 74 deletions(-) create mode 100644 cli/Cargo.toml rename gb-emu/src/bin/cli.rs => cli/src/main.rs (90%) rename {gb-emu => frontend-common}/Cargo.toml (62%) rename {gb-emu => frontend-common}/src/audio.rs (100%) rename {gb-emu => frontend-common}/src/camera.rs (100%) rename {gb-emu => frontend-common}/src/debug.rs (100%) rename {gb-emu => frontend-common}/src/lib.rs (93%) rename {gb-emu => frontend-common}/src/window.rs (100%) rename {gb-emu => frontend-common}/src/window/winit_manager.rs (100%) create mode 100644 gui/Cargo.toml rename {gb-emu/src/bin => gui/src}/macos/cacao_window_manager.rs (98%) rename {gb-emu/src/bin => gui/src}/macos/mod.rs (93%) rename {gb-emu/src/bin => gui/src}/macos/preferences.rs (100%) rename {gb-emu/src/bin => gui/src}/macos/preferences/toolbar.rs (100%) rename {gb-emu/src/bin => gui/src}/macos/preferences/views.rs (99%) rename {gb-emu/src/bin => gui/src}/macos/preferences/views/widgets.rs (100%) rename gb-emu/src/bin/gui.rs => gui/src/main.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index e499139..c0b04e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -648,6 +648,16 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +[[package]] +name = "cli" +version = "0.1.0" +dependencies = [ + "clap", + "ctrlc", + "frontend-common", + "gb-emu-lib", +] + [[package]] name = "cmake" version = "0.1.50" @@ -1322,6 +1332,25 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "frontend-common" +version = "0.5.0" +dependencies = [ + "bytemuck", + "chrono", + "cpal", + "futures", + "gb-emu-lib", + "gilrs", + "image", + "nokhwa", + "raw-window-handle 0.5.2", + "send_wrapper", + "serde", + "winit", + "winit_input_helper", +] + [[package]] name = "futures" version = "0.3.29" @@ -1420,31 +1449,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "gb-emu" -version = "0.5.0" -dependencies = [ - "bytemuck", - "cacao", - "chrono", - "clap", - "cpal", - "ctrlc", - "futures", - "gb-emu-lib", - "gilrs", - "image", - "nokhwa", - "objc2 0.3.0-beta.3", - "raw-window-handle 0.5.2", - "send_wrapper", - "serde", - "twinc_emu_vst", - "uuid 1.6.1", - "winit", - "winit_input_helper", -] - [[package]] name = "gb-emu-lib" version = "0.5.0" @@ -1624,6 +1628,20 @@ dependencies = [ "bitflags 2.4.1", ] +[[package]] +name = "gui" +version = "0.1.0" +dependencies = [ + "cacao", + "cpal", + "frontend-common", + "gb-emu-lib", + "objc2 0.3.0-beta.3", + "raw-window-handle 0.5.2", + "twinc_emu_vst", + "uuid 1.6.1", +] + [[package]] name = "hashbrown" version = "0.12.3" diff --git a/Cargo.toml b/Cargo.toml index 335a3a4..1b6670a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,11 @@ [workspace] -members = ["lib", "gb-emu", "gb-vst", "gb-vst/xtask"] -default-members = ["gb-emu"] +members = ["lib", "frontend-common", "gb-vst", "gb-vst/xtask", "gui", "cli"] +default-members = ["cli"] resolver = "2" [workspace.dependencies] gb-emu-lib = { path = "./lib", features = ["config"] } +frontend-common = { path = "./frontend-common" } baseview = { git = "https://github.com/italicsjenga/baseview" } nih_plug = { git = "https://github.com/italicsjenga/nih-plug", branch = "raw-window-handle-0.5.0" } nih_plug_xtask = { git = "https://github.com/italicsjenga/nih-plug", branch = "raw-window-handle-0.5.0" } diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 0000000..7491283 --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "cli" +version = "0.1.0" +edition = "2021" + +[package.metadata.bundle] +identifier = "com.alexjanka.TWINC.cli" + +[dependencies] +frontend-common = { workspace = true } +gb-emu-lib = { workspace = true } +clap = { version = "4.4", features = ["derive"] } +ctrlc = "3.4" diff --git a/gb-emu/src/bin/cli.rs b/cli/src/main.rs similarity index 90% rename from gb-emu/src/bin/cli.rs rename to cli/src/main.rs index 8b79814..41b4959 100644 --- a/gb-emu/src/bin/cli.rs +++ b/cli/src/main.rs @@ -3,7 +3,7 @@ #[cfg(feature = "camera")] use camera::Webcam; use clap::{ArgGroup, Parser, Subcommand, ValueEnum}; -use gb_emu::{audio, debug::Debugger, window::winit_manager::WinitWindowManager}; +use frontend_common::{audio, debug::Debugger, window::winit_manager::WinitWindowManager}; use gb_emu_lib::{ config::ConfigManager, connect::{EmulatorCoreTrait, EmulatorMessage, SerialTarget, SramType, StdoutType}, @@ -15,11 +15,6 @@ use std::{ time::{Duration, Instant}, }; -#[cfg(all(feature = "vulkan", feature = "pixels"))] -compile_error!("select only one rendering backend!"); -#[cfg(all(not(feature = "vulkan"), not(feature = "pixels")))] -compile_error!("select one rendering backend!"); - #[derive(Subcommand, Debug, Clone, Copy)] enum Commands { PrintConfig { @@ -104,7 +99,7 @@ struct Args { record: bool, } -impl From for gb_emu::RunOptions { +impl From for frontend_common::RunOptions { fn from(value: Args) -> Self { Self { rom: value @@ -143,7 +138,7 @@ fn main() { ) .ok(), ConfigType::Standalone => config_manager - .load_custom_config::() + .load_custom_config::() .and_then(|v| ConfigManager::get_custom_config_string(v).ok()), } } else { @@ -153,7 +148,7 @@ fn main() { ) .ok(), ConfigType::Standalone => ConfigManager::get_custom_config_string( - gb_emu::StandaloneConfig::default(), + frontend_common::StandaloneConfig::default(), ) .ok(), } @@ -175,10 +170,10 @@ fn main() { .unwrap(); } let (record, mute, debug) = (args.record, args.mute, args.debug); - let prepared = gb_emu::prepare(args.into(), receiver); + let prepared = frontend_common::prepare(args.into(), receiver); let (output, stream) = audio::create_output(mute); let mut window_manager = WinitWindowManager::new(sender, stream, record); - let mut core = gb_emu::run(prepared, &mut window_manager, output); + let mut core = frontend_common::run(prepared, &mut window_manager, output); if debug { let mut debugger = Debugger::new(Box::new(core)); let mut since = Instant::now(); diff --git a/gb-emu/Cargo.toml b/frontend-common/Cargo.toml similarity index 62% rename from gb-emu/Cargo.toml rename to frontend-common/Cargo.toml index ce5d7ec..7b9ae65 100644 --- a/gb-emu/Cargo.toml +++ b/frontend-common/Cargo.toml @@ -1,15 +1,11 @@ [package] -name = "gb-emu" +name = "frontend-common" version = "0.5.0" edition = "2021" -description = "TWINC Game Boy (CGB/DMG) emulator" +description = "Frontend common library for TWINC Game Boy (CGB/DMG) emulator" [package.metadata.bundle] identifier = "com.alexjanka.TWINC" -[package.metadata.bundle.bin.cli] -identifier = "com.alexjanka.TWINC.cli" -[package.metadata.bundle.bin.gui] -identifier = "com.alexjanka.TWINC.gui" [features] default = ["vulkan-static"] @@ -25,11 +21,9 @@ force-crossplatform-ui = [] [dependencies] gb-emu-lib = { workspace = true } -clap = { version = "4.4", features = ["derive"] } gilrs = "0.10" cpal = "0.15" futures = "0.3" -ctrlc = "3.4" nokhwa = { version = "0.10", features = [ "input-avfoundation", ], optional = true } @@ -41,9 +35,3 @@ serde = { version = "1.0", features = ["derive"] } image = { version = "0.24", default-features = false, features = ["png"] } bytemuck = "1.14" chrono = "0.4" -twinc_emu_vst = { path = "../gb-vst", default-features = false } -uuid = { version = "1.6", features = ["v4", "fast-rng"] } - -[target.'cfg(any(target_os = "macos"))'.dependencies] -cacao = { git = "https://github.com/italicsjenga/cacao" } -objc = { version = "=0.3.0-beta.3", package = "objc2" } diff --git a/gb-emu/src/audio.rs b/frontend-common/src/audio.rs similarity index 100% rename from gb-emu/src/audio.rs rename to frontend-common/src/audio.rs diff --git a/gb-emu/src/camera.rs b/frontend-common/src/camera.rs similarity index 100% rename from gb-emu/src/camera.rs rename to frontend-common/src/camera.rs diff --git a/gb-emu/src/debug.rs b/frontend-common/src/debug.rs similarity index 100% rename from gb-emu/src/debug.rs rename to frontend-common/src/debug.rs diff --git a/gb-emu/src/lib.rs b/frontend-common/src/lib.rs similarity index 93% rename from gb-emu/src/lib.rs rename to frontend-common/src/lib.rs index f04e592..a7b70a0 100644 --- a/gb-emu/src/lib.rs +++ b/frontend-common/src/lib.rs @@ -133,12 +133,13 @@ pub fn prepare( let will_be_cgb = rom.rom_type == CgbRomType::CgbOnly || config.prefer_cgb; - let shader_path = if will_be_cgb { - config.vulkan_config.cgb_shader_path.as_ref() - } else { - config.vulkan_config.dmg_shader_path.as_ref() - } - .map(|v| config_manager.dir().join(v)); + let shader_path = + if will_be_cgb { + config.vulkan_config.cgb_shader_path.as_ref() + } else { + config.vulkan_config.dmg_shader_path.as_ref() + } + .map(|v| config_manager.dir().join(v)); let resizable = shader_path.is_some() && if will_be_cgb { @@ -180,11 +181,12 @@ where { let configs = access_config(); - let window = window_manager.add_main( - prepared.scale_override, - prepared.shader_path, - prepared.resizable, - ); + let window = + window_manager.add_main( + prepared.scale_override, + prepared.shader_path, + prepared.resizable, + ); let tile_window = if prepared.tile_window { Some(window_manager.add(configs.standalone_config.scale_factor, None, false)) diff --git a/gb-emu/src/window.rs b/frontend-common/src/window.rs similarity index 100% rename from gb-emu/src/window.rs rename to frontend-common/src/window.rs diff --git a/gb-emu/src/window/winit_manager.rs b/frontend-common/src/window/winit_manager.rs similarity index 100% rename from gb-emu/src/window/winit_manager.rs rename to frontend-common/src/window/winit_manager.rs diff --git a/gui/Cargo.toml b/gui/Cargo.toml new file mode 100644 index 0000000..96a08f2 --- /dev/null +++ b/gui/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "gui" +version = "0.1.0" +edition = "2021" + +[package.metadata.bundle] +identifier = "com.alexjanka.TWINC.gui" + +[dependencies] +frontend-common = { workspace = true } +gb-emu-lib = { workspace = true } +twinc_emu_vst = { path = "../gb-vst", default-features = false } + +[target.'cfg(any(target_os = "macos"))'.dependencies] +cacao = { git = "https://github.com/italicsjenga/cacao" } +objc = { version = "=0.3.0-beta.3", package = "objc2" } +uuid = { version = "1.6", features = ["v4", "fast-rng"] } +raw-window-handle = { version = "0.5" } +cpal = "0.15" diff --git a/gb-emu/src/bin/macos/cacao_window_manager.rs b/gui/src/macos/cacao_window_manager.rs similarity index 98% rename from gb-emu/src/bin/macos/cacao_window_manager.rs rename to gui/src/macos/cacao_window_manager.rs index 482691c..62d2d20 100644 --- a/gb-emu/src/bin/macos/cacao_window_manager.rs +++ b/gui/src/macos/cacao_window_manager.rs @@ -13,7 +13,7 @@ use cacao::{ core_foundation::base::TCFTypeRef, }; use cpal::Stream; -use gb_emu::window::{RendererChannel, WindowManager}; +use frontend_common::window::{RendererChannel, WindowManager}; use gb_emu_lib::{ connect::{EmulatorMessage, RendererMessage, ResolutionData}, renderer::{RendererBackend, RendererBackendManager, WindowOptions}, @@ -279,12 +279,9 @@ impl WindowDelegate for CacaoWindow { const NAME: &'static str = "EmulatorWindow"; fn did_load(&mut self, window: Window) { - #[cfg(feature = "vulkan")] let options = WindowOptions { shader_path: self.shader_path.clone(), }; - #[cfg(feature = "pixels")] - let options = WindowOptions {}; self.backend = Some(RendererBackend::new( self.resolutions, diff --git a/gb-emu/src/bin/macos/mod.rs b/gui/src/macos/mod.rs similarity index 93% rename from gb-emu/src/bin/macos/mod.rs rename to gui/src/macos/mod.rs index d9cea9f..818bf5f 100644 --- a/gb-emu/src/bin/macos/mod.rs +++ b/gui/src/macos/mod.rs @@ -7,7 +7,7 @@ use cacao::appkit::window::{Window, WindowConfig, WindowStyle, WindowToolbarStyl use cacao::appkit::{App, AppDelegate}; use cacao::filesystem::FileSelectPanel; use cacao::notification_center::Dispatcher; -use gb_emu::audio; +use frontend_common::audio; use gb_emu_lib::connect::{EmulatorCoreTrait, EmulatorMessage}; use raw_window_handle::{AppKitDisplayHandle, RawDisplayHandle}; use uuid::Uuid; @@ -73,9 +73,9 @@ impl Default for TwincUiApp { }, PreferencesUi::new(), )), - current_game: RwLock::new(CacaoWindowManager::new(RawDisplayHandle::AppKit( - AppKitDisplayHandle::empty(), - ))), + current_game: RwLock::new( + CacaoWindowManager::new(RawDisplayHandle::AppKit(AppKitDisplayHandle::empty())) + ), } } } @@ -99,11 +99,12 @@ impl Dispatcher for TwincUiApp { AppMessage::Core(CoreMessage::OpenRom(path)) => { let (sender, receiver) = channel::(); sender.send(EmulatorMessage::Start).unwrap(); - let prepared = gb_emu::prepare(gb_emu::RunOptions::new(path), receiver); + let prepared = + frontend_common::prepare(frontend_common::RunOptions::new(path), receiver); let (output, stream) = audio::create_output(false); let mut window_manager = self.current_game.write().unwrap(); window_manager.update_handles(sender, stream); - let mut core = gb_emu::run(prepared, &mut *window_manager, output); + let mut core = frontend_common::run(prepared, &mut *window_manager, output); let handle = std::thread::Builder::new() .name(String::from("EmuCore")) .spawn(move || loop { diff --git a/gb-emu/src/bin/macos/preferences.rs b/gui/src/macos/preferences.rs similarity index 100% rename from gb-emu/src/bin/macos/preferences.rs rename to gui/src/macos/preferences.rs diff --git a/gb-emu/src/bin/macos/preferences/toolbar.rs b/gui/src/macos/preferences/toolbar.rs similarity index 100% rename from gb-emu/src/bin/macos/preferences/toolbar.rs rename to gui/src/macos/preferences/toolbar.rs diff --git a/gb-emu/src/bin/macos/preferences/views.rs b/gui/src/macos/preferences/views.rs similarity index 99% rename from gb-emu/src/bin/macos/preferences/views.rs rename to gui/src/macos/preferences/views.rs index 0164c01..88f5798 100644 --- a/gb-emu/src/bin/macos/preferences/views.rs +++ b/gui/src/macos/preferences/views.rs @@ -4,7 +4,7 @@ use cacao::{ layout::Layout, view::{View, ViewDelegate}, }; -use gb_emu::StandaloneConfig; +use frontend_common::StandaloneConfig; use gb_emu_lib::config::{Config, ConfigManager, ResolutionOverride}; use crate::macos::dispatch; diff --git a/gb-emu/src/bin/macos/preferences/views/widgets.rs b/gui/src/macos/preferences/views/widgets.rs similarity index 100% rename from gb-emu/src/bin/macos/preferences/views/widgets.rs rename to gui/src/macos/preferences/views/widgets.rs diff --git a/gb-emu/src/bin/gui.rs b/gui/src/main.rs similarity index 100% rename from gb-emu/src/bin/gui.rs rename to gui/src/main.rs