diff --git a/ferretro_base/Cargo.toml b/ferretro_base/Cargo.toml index d513ec8..ec16a4f 100644 --- a/ferretro_base/Cargo.toml +++ b/ferretro_base/Cargo.toml @@ -11,4 +11,4 @@ cc = "^1" libretro-sys = "0.1" libloading = "0.5" num_enum = "0.4" -once_cell = "1.8" +once_cell = "1" diff --git a/ferretro_components/Cargo.toml b/ferretro_components/Cargo.toml index 8e4e1f8..22b46ec 100644 --- a/ferretro_components/Cargo.toml +++ b/ferretro_components/Cargo.toml @@ -15,6 +15,7 @@ ffmpeg-next = { version = "4.3.8", optional = true } sdl2 = { version = "0.32", optional = true, features = ["gfx"] } gl = { version = "0.14", optional = true } crossbeam-channel = { version = "0.4", optional = true } +tempfile = "3" [dev-dependencies] crossbeam-channel = "0.4" diff --git a/ferretro_components/src/base/mod.rs b/ferretro_components/src/base/mod.rs index eaa06f3..22b950b 100644 --- a/ferretro_components/src/base/mod.rs +++ b/ferretro_components/src/base/mod.rs @@ -4,6 +4,7 @@ use crate::prelude::*; use ferretro_base::retro::ffi::*; +use ferretro_base::prelude::{LibretroWrapperAccess, RetroHandlerId}; use core::any::{Any, TypeId}; use core::pin::Pin; @@ -13,7 +14,6 @@ use std::path::{PathBuf, Path}; use std::io::Read; use std::collections::HashMap; use std::ffi::c_void; -use ferretro_base::prelude::{LibretroWrapperAccess, RetroHandlerId}; pub struct RetroComponentBase { retro: LibretroWrapper, @@ -37,6 +37,7 @@ pub struct RetroComponentBase { cached_geometry: Option, handler_id: Option, + _temp_dir: tempfile::TempDir, } // TODO: replace with std::ops::ControlFlow when it becomes stable @@ -61,13 +62,18 @@ pub trait RetroComponent: RetroCallbacks + Any { 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(); + // allow multiple copies of same lib, possibly? + let temp_dir = tempfile::tempdir().unwrap(); + let libretro_path = temp_dir.path().join(core_path.as_ref().file_name().unwrap()); + std::fs::copy(core_path.as_ref(), &libretro_path).unwrap(); + + let lib = libloading::Library::new(&libretro_path).unwrap(); let raw_retro = ferretro_base::retro::loading::LibretroApi::from_library(lib).unwrap(); let retro = LibretroWrapper::from(raw_retro); let emu = RetroComponentBase { retro, - libretro_path: core_path.as_ref().to_path_buf(), + libretro_path, components: Default::default(), component_ptrs: Default::default(), cached_rom_path: None, @@ -82,6 +88,7 @@ impl RetroComponentBase { cached_memory_map: None, cached_geometry: None, handler_id: None, + _temp_dir: temp_dir, }; let mut pin_emu = Box::pin(emu);