From 7de966f624fb3f6a94cff0fb6ab4cb4719735f30 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Sat, 8 Jun 2024 15:21:07 +0200 Subject: [PATCH] web: Make serde (more-)optional in core --- core/Cargo.toml | 5 +++-- core/src/backend/navigator.rs | 10 +++++----- core/src/config.rs | 24 ++++++++++++++---------- core/src/context_menu.rs | 6 +++--- core/src/events.rs | 4 ++-- core/src/player.rs | 4 ++-- tests/framework/Cargo.toml | 2 +- web/Cargo.toml | 2 +- 8 files changed, 31 insertions(+), 26 deletions(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index f6542c4e834ec..29100a7202b12 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -39,7 +39,7 @@ chrono = { workspace = true, features = ["clock"] } web-time = "1.1.0" encoding_rs = "0.8.34" rand = { version = "0.8.5", features = ["std", "small_rng"], default-features = false } -serde = { workspace = true, features = ["derive"] } +serde = { workspace = true } serde_json = { version = "1.0", features = ["preserve_order"] } nellymoser-rs = { git = "https://github.com/ruffle-rs/nellymoser", rev = "754b1184037aa9952a907107284fb73897e26adc", optional = true } regress = "0.10" @@ -83,12 +83,13 @@ timeline_debug = [] mp3 = ["symphonia"] nellymoser = ["nellymoser-rs"] audio = ["dasp"] -known_stubs = ["linkme"] +known_stubs = ["linkme", "serde"] default_compatibility_rules = [] egui = ["dep:egui", "dep:egui_extras", "png"] jpegxr = ["dep:jpegxr", "lzma"] default_font = [] test_only_as3 = [] +serde = ["serde/derive"] [build-dependencies] build_playerglobal = { path = "build_playerglobal" } diff --git a/core/src/backend/navigator.rs b/core/src/backend/navigator.rs index 74fb5a794bfce..5dabc74928d72 100644 --- a/core/src/backend/navigator.rs +++ b/core/src/backend/navigator.rs @@ -5,7 +5,6 @@ use crate::socket::{ConnectionState, SocketAction, SocketHandle}; use crate::string::WStr; use async_channel::{Receiver, Sender}; use indexmap::IndexMap; -use serde::{Deserialize, Serialize}; use std::borrow::Cow; use std::fmt; use std::fmt::Display; @@ -57,18 +56,19 @@ pub enum SocketMode { /// The handling mode of links opening a new website. #[cfg_attr(feature = "clap", derive(clap::ValueEnum))] -#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum OpenURLMode { /// Allow all links to open a new website. - #[serde(rename = "allow")] + #[cfg_attr(feature = "serde", serde(rename = "allow"))] Allow, /// A confirmation dialog opens with every link trying to open a new website. - #[serde(rename = "confirm")] + #[cfg_attr(feature = "serde", serde(rename = "confirm"))] Confirm, /// Deny all links to open a new website. - #[serde(rename = "deny")] + #[cfg_attr(feature = "serde", serde(rename = "deny"))] Deny, } diff --git a/core/src/config.rs b/core/src/config.rs index 15fd0e7ae0a88..481bcfe372cb6 100644 --- a/core/src/config.rs +++ b/core/src/config.rs @@ -1,4 +1,3 @@ -use serde::{Deserialize, Serialize}; use std::str::FromStr; /// Controls whether the content is letterboxed or pillarboxed when the @@ -7,19 +6,23 @@ use std::str::FromStr; /// When letterboxed, black bars will be rendered around the exterior /// margins of the content. #[cfg_attr(feature = "clap", derive(clap::ValueEnum))] -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] -#[serde(rename = "letterbox")] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename = "letterbox") +)] pub enum Letterbox { /// The content will never be letterboxed. - #[serde(rename = "off")] + #[cfg_attr(feature = "serde", serde(rename = "off"))] Off, /// The content will only be letterboxed if the content is running fullscreen. - #[serde(rename = "fullscreen")] + #[cfg_attr(feature = "serde", serde(rename = "fullscreen"))] Fullscreen, /// The content will always be letterboxed. - #[serde(rename = "on")] + #[cfg_attr(feature = "serde", serde(rename = "on"))] On, } @@ -41,17 +44,18 @@ impl FromStr for Letterbox { /// The networking API access mode of the Ruffle player. /// This setting is only used on web. -#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum NetworkingAccessMode { /// All networking APIs are permitted in the SWF file. - #[serde(rename = "all")] + #[cfg_attr(feature = "serde", serde(rename = "all"))] All, /// The SWF file may not call browser navigation or browser interaction APIs. /// /// The APIs getURL(), navigateToURL(), fscommand() and ExternalInterface.call() /// are prevented in this mode. - #[serde(rename = "internal")] + #[cfg_attr(feature = "serde", serde(rename = "internal"))] Internal, /// The SWF file may not call browser navigation or browser interaction APIs @@ -65,6 +69,6 @@ pub enum NetworkingAccessMode { /// URLStream.load() and XMLSocket.connect() are prevented in this mode. /// /// This mode is not implemented yet. - #[serde(rename = "none")] + #[cfg_attr(feature = "serde", serde(rename = "none"))] None, } diff --git a/core/src/context_menu.rs b/core/src/context_menu.rs index 0ac4ee5ec02f5..bf1bfa6138c17 100644 --- a/core/src/context_menu.rs +++ b/core/src/context_menu.rs @@ -12,7 +12,6 @@ use crate::i18n::core_text; use fluent_templates::LanguageIdentifier; use gc_arena::Collect; use ruffle_render::quality::StageQuality; -use serde::Serialize; #[derive(Collect, Default)] #[collect(no_drop)] @@ -123,10 +122,11 @@ impl<'gc> ContextMenuState<'gc> { } } -#[derive(Clone, Serialize)] +#[derive(Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] pub struct ContextMenuItem { pub enabled: bool, - #[serde(rename = "separatorBefore")] + #[cfg_attr(feature = "serde", serde(rename = "separatorBefore"))] pub separator_before: bool, pub checked: bool, pub caption: String, diff --git a/core/src/events.rs b/core/src/events.rs index 4c5ac2daedbcb..0d619104444ae 100644 --- a/core/src/events.rs +++ b/core/src/events.rs @@ -1,5 +1,4 @@ use crate::display_object::InteractiveObject; -use serde::Deserialize; use swf::ClipEventFlag; #[derive(Debug, Clone, Copy)] @@ -341,7 +340,8 @@ impl<'gc> ClipEvent<'gc> { } /// Control inputs to a text field -#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub enum TextControlCode { MoveLeft, MoveLeftWord, diff --git a/core/src/player.rs b/core/src/player.rs index ba1117598731b..7126287957598 100644 --- a/core/src/player.rs +++ b/core/src/player.rs @@ -56,7 +56,6 @@ use ruffle_render::commands::CommandList; use ruffle_render::quality::StageQuality; use ruffle_render::transform::TransformStack; use ruffle_video::backend::VideoBackend; -use serde::Deserialize; use std::cell::RefCell; use std::collections::{HashMap, VecDeque}; use std::ops::DerefMut; @@ -2787,7 +2786,8 @@ fn run_mouse_pick<'gc>( } #[cfg_attr(feature = "clap", derive(clap::ValueEnum))] -#[derive(Default, Clone, Copy, Debug, Eq, PartialEq, Deserialize)] +#[derive(Default, Clone, Copy, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize))] pub enum PlayerRuntime { #[default] FlashPlayer, diff --git a/tests/framework/Cargo.toml b/tests/framework/Cargo.toml index 7b48703f4e294..0941d6b399e45 100644 --- a/tests/framework/Cargo.toml +++ b/tests/framework/Cargo.toml @@ -11,7 +11,7 @@ version.workspace = true workspace = true [dependencies] -ruffle_core = { path = "../../core", features = ["deterministic", "timeline_debug", "avm_debug", "audio", "mp3", "default_font"] } +ruffle_core = { path = "../../core", features = ["deterministic", "timeline_debug", "avm_debug", "audio", "mp3", "default_font", "serde"] } ruffle_render = { path = "../../render", features = ["serde"] } ruffle_input_format = { path = "../input-format" } ruffle_socket_format = { path = "../socket-format" } diff --git a/web/Cargo.toml b/web/Cargo.toml index c8de1fb97a14f..78f1da0b51887 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -62,7 +62,7 @@ futures = { workspace = true } [dependencies.ruffle_core] path = "../core" -features = ["audio", "mp3", "nellymoser", "default_compatibility_rules", "default_font"] +features = ["audio", "mp3", "nellymoser", "default_compatibility_rules", "default_font", "serde"] [dependencies.web-sys] version = "0.3.69"