From 5d2692262cdd28009c60af0cda0ebf56eb5ddea1 Mon Sep 17 00:00:00 2001 From: Vivian Lim Date: Wed, 18 Aug 2021 14:32:55 -0700 Subject: [PATCH] Split into two crates in one workspace: ferretro_core & ferretro_components --- .gitignore | 27 +++++++++++++-- Cargo.toml | 33 +++---------------- ferretro_components/Cargo.toml | 24 ++++++++++++++ .../examples}/multifunction_emulator.rs | 10 +++--- .../src/base}/mod.rs | 10 +++--- ferretro_components/src/lib.rs | 10 ++++++ .../src}/provided/ffmpeg.rs | 2 +- .../src}/provided/mod.rs | 0 .../src}/provided/sdl2.rs | 2 +- .../src}/provided/stdlib.rs | 2 +- ferretro_core/Cargo.toml | 22 +++++++++++++ build.rs => ferretro_core/build.rs | 0 .../examples}/ffmpeg_recorder.rs | 12 +++---- .../examples}/sdl2_emulator.rs | 12 +++---- {src => ferretro_core/src}/lib.rs | 2 -- .../src}/retro/c_ext/libretro.h | 0 .../src}/retro/c_ext/log_wrapper.c | 0 {src => ferretro_core/src}/retro/constants.rs | 0 {src => ferretro_core/src}/retro/ffi.rs | 0 {src => ferretro_core/src}/retro/loading.rs | 0 {src => ferretro_core/src}/retro/mod.rs | 0 .../src}/retro/wrapped_types.rs | 0 {src => ferretro_core/src}/retro/wrapper.rs | 0 23 files changed, 109 insertions(+), 59 deletions(-) create mode 100644 ferretro_components/Cargo.toml rename {examples => ferretro_components/examples}/multifunction_emulator.rs (89%) rename {src/components => ferretro_components/src/base}/mod.rs (98%) create mode 100644 ferretro_components/src/lib.rs rename {src/components => ferretro_components/src}/provided/ffmpeg.rs (99%) rename {src/components => ferretro_components/src}/provided/mod.rs (100%) rename {src/components => ferretro_components/src}/provided/sdl2.rs (99%) rename {src/components => ferretro_components/src}/provided/stdlib.rs (96%) create mode 100644 ferretro_core/Cargo.toml rename build.rs => ferretro_core/build.rs (100%) rename {examples => ferretro_core/examples}/ffmpeg_recorder.rs (98%) rename {examples => ferretro_core/examples}/sdl2_emulator.rs (97%) rename {src => ferretro_core/src}/lib.rs (78%) rename {src => ferretro_core/src}/retro/c_ext/libretro.h (100%) rename {src => ferretro_core/src}/retro/c_ext/log_wrapper.c (100%) rename {src => ferretro_core/src}/retro/constants.rs (100%) rename {src => ferretro_core/src}/retro/ffi.rs (100%) rename {src => ferretro_core/src}/retro/loading.rs (100%) rename {src => ferretro_core/src}/retro/mod.rs (100%) rename {src => ferretro_core/src}/retro/wrapped_types.rs (100%) rename {src => ferretro_core/src}/retro/wrapper.rs (100%) diff --git a/.gitignore b/.gitignore index 6473eaf..9262337 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,34 @@ +# build artifacts /target **/*.rs.bk -/.idea /Cargo.lock +# editors +/.idea +/.vscode + +# cores *.so *.dll *.dylib -*.mp4 -*.ogv + +# roms *.gb *.bin +*.sfc +*.z64 + +# save states +*.state* + +# media +*.mp4 +*.ogv +*.flv +*.flac + +# scratch data +/scratch + +# desktop.ini.mac .DS_Store \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 1e91e2e..7896c2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,28 +1,5 @@ -[package] -name = "ferretro" -version = "0.1.0" -authors = ["lifning ", "viv ", "iliana "] -edition = "2018" - -[build-dependencies] -cc = "^1" - -[dependencies] -libretro-sys = "0.1" -libloading = "0.5" -num_enum = "0.4" -ffmpeg-next = { version = "4.3.8", optional = true } -sdl2 = { version = "0.32", optional = true } -crossbeam-channel = { version = "0.4", optional = true } - -[dev-dependencies] -# example: sdl2_emulator -sdl2 = "0.32" -crossbeam-channel = "0.4" -structopt = "0.3" -# example: ffmpeg_recorder -ffmpeg-next = "4.3.8" - -[features] -ffmpeg_comp = ["ffmpeg-next"] -sdl2_comp = ["sdl2", "crossbeam-channel"] +[workspace] +members = [ + "ferretro_core", + "ferretro_components", +] \ No newline at end of file diff --git a/ferretro_components/Cargo.toml b/ferretro_components/Cargo.toml new file mode 100644 index 0000000..cdd7a02 --- /dev/null +++ b/ferretro_components/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "ferretro_components" +version = "0.1.0" +authors = ["lifning ", "viv ", "iliana "] +edition = "2018" + +[build-dependencies] +cc = "^1" + +[dependencies] +ferretro_core = { path = "../ferretro_core"} +libloading = "0.5" +num_enum = "0.4" +ffmpeg-next = { version = "4.3.8", optional = true } +sdl2 = { version = "0.32", optional = true } +crossbeam-channel = { version = "0.4", optional = true } + +[dev-dependencies] +crossbeam-channel = "0.4" +structopt = "0.3" + +[features] +ffmpeg_comp = ["ffmpeg-next"] +sdl2_comp = ["sdl2", "crossbeam-channel"] diff --git a/examples/multifunction_emulator.rs b/ferretro_components/examples/multifunction_emulator.rs similarity index 89% rename from examples/multifunction_emulator.rs rename to ferretro_components/examples/multifunction_emulator.rs index 3526331..811640e 100644 --- a/examples/multifunction_emulator.rs +++ b/ferretro_components/examples/multifunction_emulator.rs @@ -1,20 +1,20 @@ extern crate crossbeam_channel; -extern crate ferretro; +extern crate ferretro_components; extern crate ffmpeg_next as ffmpeg; extern crate sdl2; use std::path::PathBuf; use structopt::StructOpt; -use ferretro::prelude::*; +use ferretro_components::prelude::*; -use ferretro::components::provided::{ +use ferretro_components::provided::{ ffmpeg::FfmpegComponent, sdl2::Sdl2Component, stdlib::{PathBufComponent, StderrLogComponent}, }; -use ferretro::components::ControlFlow; -use ferretro::components::provided::stdlib::StderrSysInfoLogComponent; +use ferretro_components::base::ControlFlow; +use ferretro_components::provided::stdlib::StderrSysInfoLogComponent; #[derive(StructOpt)] struct Opt { diff --git a/src/components/mod.rs b/ferretro_components/src/base/mod.rs similarity index 98% rename from src/components/mod.rs rename to ferretro_components/src/base/mod.rs index 0eb51c2..9d9cef1 100644 --- a/src/components/mod.rs +++ b/ferretro_components/src/base/mod.rs @@ -1,7 +1,5 @@ -pub mod provided; - use crate::prelude::*; -use crate::retro::ffi::*; +use ferretro_core::retro::ffi::*; use std::os::raw::c_uint; use std::path::{PathBuf, Path}; use std::pin::Pin; @@ -48,7 +46,7 @@ impl RetroComponentBase { // TODO: constructor & wrapper that uses a statically linked libretro? pub fn new(core_path: impl AsRef) -> Pin> { let lib = libloading::Library::new(core_path.as_ref()).unwrap(); - let raw_retro = crate::retro::loading::LibretroApi::from_library(lib).unwrap(); + let raw_retro = ferretro_core::retro::loading::LibretroApi::from_library(lib).unwrap(); let retro = LibretroWrapper::from(raw_retro); let emu = RetroComponentBase { @@ -69,7 +67,7 @@ impl RetroComponentBase { }; let mut pin_emu = Box::pin(emu); - crate::retro::wrapper::set_handler(pin_emu.as_mut()); + ferretro_core::retro::wrapper::set_handler(pin_emu.as_mut()); pin_emu.retro.init(); pin_emu } @@ -495,6 +493,6 @@ impl RetroCallbacks for RetroComponentBase { impl Drop for RetroComponentBase { fn drop(&mut self) { - crate::retro::wrapper::unset_handler(); + ferretro_core::retro::wrapper::unset_handler(); } } diff --git a/ferretro_components/src/lib.rs b/ferretro_components/src/lib.rs new file mode 100644 index 0000000..457d51e --- /dev/null +++ b/ferretro_components/src/lib.rs @@ -0,0 +1,10 @@ +pub mod provided; +pub mod base; + +pub mod prelude { + pub use crate::base::{RetroComponent, RetroComponentBase}; + pub use ferretro_core::retro::constants::*; + pub use ferretro_core::retro::wrapped_types::*; + pub use ferretro_core::retro::wrapper::{RetroCallbacks, LibretroWrapper, LibretroWrapperAccess}; + pub use ferretro_core::retro::ffi::{PixelFormat, GameGeometry, SystemAvInfo, SystemInfo}; +} diff --git a/src/components/provided/ffmpeg.rs b/ferretro_components/src/provided/ffmpeg.rs similarity index 99% rename from src/components/provided/ffmpeg.rs rename to ferretro_components/src/provided/ffmpeg.rs index 3b3e8ea..c682168 100644 --- a/src/components/provided/ffmpeg.rs +++ b/ferretro_components/src/provided/ffmpeg.rs @@ -8,7 +8,7 @@ use crate::prelude::*; use ffmpeg::{ChannelLayout, Packet, filter, format, frame, media}; use ffmpeg::util::rational::Rational; -use crate::components::ControlFlow; +use crate::base::ControlFlow; enum EncoderToWriteFrom { Video, diff --git a/src/components/provided/mod.rs b/ferretro_components/src/provided/mod.rs similarity index 100% rename from src/components/provided/mod.rs rename to ferretro_components/src/provided/mod.rs diff --git a/src/components/provided/sdl2.rs b/ferretro_components/src/provided/sdl2.rs similarity index 99% rename from src/components/provided/sdl2.rs rename to ferretro_components/src/provided/sdl2.rs index 43ddb85..16b0a8a 100644 --- a/src/components/provided/sdl2.rs +++ b/ferretro_components/src/provided/sdl2.rs @@ -4,7 +4,7 @@ use std::path::Path; use std::time::{Duration, Instant}; use crate::prelude::*; -use crate::components::ControlFlow; +use crate::base::ControlFlow; use sdl2::audio::{AudioCallback, AudioFormat, AudioSpec, AudioSpecDesired, AudioDevice}; use sdl2::controller::{GameController, Button, Axis}; diff --git a/src/components/provided/stdlib.rs b/ferretro_components/src/provided/stdlib.rs similarity index 96% rename from src/components/provided/stdlib.rs rename to ferretro_components/src/provided/stdlib.rs index c269d7b..8cc1eed 100644 --- a/src/components/provided/stdlib.rs +++ b/ferretro_components/src/provided/stdlib.rs @@ -32,7 +32,7 @@ pub struct StderrLogComponent { impl RetroComponent for StderrLogComponent {} impl RetroCallbacks for StderrLogComponent { - fn log_print(&mut self, level: crate::retro::ffi::LogLevel, msg: &str) { + fn log_print(&mut self, level: ferretro_core::retro::ffi::LogLevel, msg: &str) { eprint!("{}[{:?}] {}", self.prefix, level, msg); } } diff --git a/ferretro_core/Cargo.toml b/ferretro_core/Cargo.toml new file mode 100644 index 0000000..f1bde34 --- /dev/null +++ b/ferretro_core/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "ferretro_core" +version = "0.1.0" +authors = ["lifning ", "viv ", "iliana "] +edition = "2018" + +[build-dependencies] +cc = "^1" + +[dependencies] +libretro-sys = "0.1" +libloading = "0.5" +num_enum = "0.4" +crossbeam-channel = { version = "0.4", optional = true } + +[dev-dependencies] +# example: sdl2_emulator +sdl2 = "0.32" +crossbeam-channel = "0.4" +structopt = "0.3" +# example: ffmpeg_recorder +ffmpeg-next = "4.3.8" diff --git a/build.rs b/ferretro_core/build.rs similarity index 100% rename from build.rs rename to ferretro_core/build.rs diff --git a/examples/ffmpeg_recorder.rs b/ferretro_core/examples/ffmpeg_recorder.rs similarity index 98% rename from examples/ffmpeg_recorder.rs rename to ferretro_core/examples/ffmpeg_recorder.rs index 04c7be3..af69d92 100644 --- a/examples/ffmpeg_recorder.rs +++ b/ferretro_core/examples/ffmpeg_recorder.rs @@ -1,4 +1,4 @@ -extern crate ferretro; +extern crate ferretro_core; extern crate ffmpeg_next as ffmpeg; use std::collections::VecDeque; @@ -8,11 +8,11 @@ use std::pin::Pin; use structopt::StructOpt; -use ferretro::retro; -use ferretro::retro::ffi::{PixelFormat, GameGeometry, SystemAvInfo, SystemInfo}; -use ferretro::retro::wrapper::{LibretroWrapper, RetroCallbacks}; +use ferretro_core::retro; +use ferretro_core::retro::ffi::{PixelFormat, GameGeometry, SystemAvInfo, SystemInfo}; +use ferretro_core::retro::wrapper::{LibretroWrapper, RetroCallbacks}; -use ferretro::retro::wrapped_types::{Variable2}; +use ferretro_core::retro::wrapped_types::{Variable2}; use ffmpeg::{ChannelLayout, Packet, codec, filter, format, frame, media}; use ffmpeg::util::rational::Rational; @@ -504,7 +504,7 @@ impl retro::wrapper::RetroCallbacks for MyEmulator { fn get_variable(&mut self, key: &str) -> Option { match key { "beetle_saturn_analog_stick_deadzone" => Some("15%".to_string()), - "parallel-n64-gfxplugin" => Some("angrylion".to_string()), + //"parallel-n64-gfxplugin" => Some("angrylion".to_string()), "parallel-n64-astick-deadzone" => Some("15%".to_string()), _ => None, } diff --git a/examples/sdl2_emulator.rs b/ferretro_core/examples/sdl2_emulator.rs similarity index 97% rename from examples/sdl2_emulator.rs rename to ferretro_core/examples/sdl2_emulator.rs index 57aa336..7d41f44 100644 --- a/examples/sdl2_emulator.rs +++ b/ferretro_core/examples/sdl2_emulator.rs @@ -1,12 +1,12 @@ extern crate crossbeam_channel; -extern crate ferretro; +extern crate ferretro_core; extern crate sdl2; -use ferretro::retro; -use ferretro::retro::ffi::{GameGeometry, SystemInfo, SystemAvInfo}; -use ferretro::retro::constants::{InputIndex, JoypadButton, AnalogAxis, DeviceType}; -use ferretro::retro::wrapped_types::{ControllerDescription2, InputDescriptor2, InputDeviceId, SubsystemInfo2, Variable2}; -use ferretro::retro::wrapper::LibretroWrapper; +use ferretro_core::retro; +use ferretro_core::retro::ffi::{GameGeometry, SystemInfo, SystemAvInfo}; +use ferretro_core::retro::constants::{InputIndex, JoypadButton, AnalogAxis, DeviceType}; +use ferretro_core::retro::wrapped_types::{ControllerDescription2, InputDescriptor2, InputDeviceId, SubsystemInfo2, Variable2}; +use ferretro_core::retro::wrapper::LibretroWrapper; use std::ffi::CStr; use std::io::Read; diff --git a/src/lib.rs b/ferretro_core/src/lib.rs similarity index 78% rename from src/lib.rs rename to ferretro_core/src/lib.rs index 04e228b..a4c6d02 100644 --- a/src/lib.rs +++ b/ferretro_core/src/lib.rs @@ -1,11 +1,9 @@ extern crate libloading; pub mod retro; -pub mod components; pub mod prelude { pub use crate::retro::constants::*; - pub use crate::components::{RetroComponent, RetroComponentBase}; pub use crate::retro::wrapped_types::*; pub use crate::retro::wrapper::{RetroCallbacks, LibretroWrapper, LibretroWrapperAccess}; pub use crate::retro::ffi::{PixelFormat, GameGeometry, SystemAvInfo, SystemInfo}; diff --git a/src/retro/c_ext/libretro.h b/ferretro_core/src/retro/c_ext/libretro.h similarity index 100% rename from src/retro/c_ext/libretro.h rename to ferretro_core/src/retro/c_ext/libretro.h diff --git a/src/retro/c_ext/log_wrapper.c b/ferretro_core/src/retro/c_ext/log_wrapper.c similarity index 100% rename from src/retro/c_ext/log_wrapper.c rename to ferretro_core/src/retro/c_ext/log_wrapper.c diff --git a/src/retro/constants.rs b/ferretro_core/src/retro/constants.rs similarity index 100% rename from src/retro/constants.rs rename to ferretro_core/src/retro/constants.rs diff --git a/src/retro/ffi.rs b/ferretro_core/src/retro/ffi.rs similarity index 100% rename from src/retro/ffi.rs rename to ferretro_core/src/retro/ffi.rs diff --git a/src/retro/loading.rs b/ferretro_core/src/retro/loading.rs similarity index 100% rename from src/retro/loading.rs rename to ferretro_core/src/retro/loading.rs diff --git a/src/retro/mod.rs b/ferretro_core/src/retro/mod.rs similarity index 100% rename from src/retro/mod.rs rename to ferretro_core/src/retro/mod.rs diff --git a/src/retro/wrapped_types.rs b/ferretro_core/src/retro/wrapped_types.rs similarity index 100% rename from src/retro/wrapped_types.rs rename to ferretro_core/src/retro/wrapped_types.rs diff --git a/src/retro/wrapper.rs b/ferretro_core/src/retro/wrapper.rs similarity index 100% rename from src/retro/wrapper.rs rename to ferretro_core/src/retro/wrapper.rs